It is currently April 24th, 2024, 10:56 pm

Run CMD.EXE as Administrator from Rainmeter

Get help with creating, editing & fixing problems with skins
learninginsight
Posts: 6
Joined: April 16th, 2014, 12:38 am

Run CMD.EXE as Administrator from Rainmeter

Post by learninginsight »

So, I can run CMD.exe from Rainmeter ... but I would like to run it as Administrator.

LeftMouseUpAction=["%windir%\system32\cmd.exe"] opens a window and let's me enter commands, but I want to run the program as Administrator.

I tried googling for a quick solution, but just found info on ShellExecute and Runas which didn't help me much.

Any help or pointers in the right direction would be appreciated.

Thanks!
You do not have the required permissions to view the files attached to this post.
User avatar
moshi
Posts: 1740
Joined: November 13th, 2012, 9:53 pm

Re: Run CMD.EXE as Administrator from Rainmeter

Post by moshi »

not really a Rainmeter, but rather a "how do i use Windows question" :)

create a shortcut as described here: http://www.sevenforums.com/tutorials/3718-elevated-command-prompt-shortcut.html

Code: Select all

LeftMouseUpAction=["path\to the\name of your new shortcut.lnk"]
learninginsight
Posts: 6
Joined: April 16th, 2014, 12:38 am

Re: Run CMD.EXE as Administrator from Rainmeter

Post by learninginsight »

Thanks for the pointer. It was helpful.

I use Rainmeter to avoid creating shortcuts on my desktop and run everything directly. Thought I could do the same thing in this situation ... which is why I was asking for help.

As I mentioned previously, my google efforts came up short, because I obviously didn't know what to google for ... your link did provide a work around.

However, even when I create a shortcut and designate it as "run as admin", and then use Rainmeter to reference that shortcut, CMD.exe is still not run as admin. When I click on the shortcut in Windows, it works as expected. When I reference the shortcut in Rainmeter, it executes CMD.exe but not as Admin.

As a workaround, I created a copy of the CMD.EXE file locally and designated it as "run as admin" and then referenced that in Rainmeter. It works, but is kludgy and problematic for other reasons, but I can live with it for now.

I realize that this is a Windows issue, but I am still kinda wondering is it possible to run CMD as Admin through Rainmeter without my kludgy solution?

Just wondering ...
You do not have the required permissions to view the files attached to this post.
tk_
Posts: 11
Joined: March 30th, 2015, 1:50 am

Re: Run CMD.EXE as Administrator from Rainmeter

Post by tk_ »

(Yes, I realize this topic is nearly a year old, but...)

I am wanting to do specifically what the OP was wanting to do. That is, discover if there is a native way in Rainmeter to open a command prompt with elevated privileges (i.e. as admin). Creating a link as shown above isn't really what I'm looking for, and I don't want to use a kluge solution either.

It seems like no one answered the OP in this respect, so I'm poking again to see if this is possible.

Thanks in advance,
tk_
User avatar
fonpaolo
Moderator
Posts: 1387
Joined: April 11th, 2013, 8:08 pm
Location: Italy

Re: Run CMD.EXE as Administrator from Rainmeter

Post by fonpaolo »

The only other suggestion that comes to my mind is to right click on the CMD.exe file, and set "Run as Administrator" in the Properties, without making a copy.

...but remember that, then it will always run "as Administrator".
tk_
Posts: 11
Joined: March 30th, 2015, 1:50 am

Re: Run CMD.EXE as Administrator from Rainmeter

Post by tk_ »

fonpaolo wrote:The only other suggestion that comes to my mind is to right click on the CMD.exe file, and set "Run as Administrator" in the Properties, without making a copy.

...but remember that, then it will always run "as Administrator".
Thank you for the reply.
Right, and that's not doing it with Rainmeter.

So, anyone else? Is there no way to do this within Rainmeter?

Thanks
tk_
jn_meter
Posts: 136
Joined: December 27th, 2016, 12:04 pm

Re: Run CMD.EXE as Administrator from Rainmeter

Post by jn_meter »

I too would like a way of running a program - any program, not just cmd.exe - elevated from within Rainmeter. I feel Rainmeter should have this function built-in.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2604
Joined: March 23rd, 2015, 5:26 pm

Re: Run CMD.EXE as Administrator from Rainmeter

Post by SilverAzide »

jn_meter wrote: November 16th, 2020, 4:39 pm I too would like a way of running a program - any program, not just cmd.exe - elevated from within Rainmeter. I feel Rainmeter should have this function built-in.
Not possible. The Windows operating system itself controls elevation, so the only way to launch a program from Rainmeter in an elevated mode is to run Rainmeter itself elevated. Windows doesn't want you to run stuff elevated, that's why it nags you with a prompt. It is possible to write a PowerShell script that will self-elevate (after the usual prompting that you can't avoid).
Gadgets Wiki GitHub More Gadgets...
jn_meter
Posts: 136
Joined: December 27th, 2016, 12:04 pm

Re: Run CMD.EXE as Administrator from Rainmeter

Post by jn_meter »

Thanks. Perhaps I was not clear, though: I am not trying to skip the elevation prompt; rather, when I use (unelevated) Rainmeter to run a program that need elevation, I do not see an elevation prompt. Rather, nothing at all happens. I suppose I'll have to implement one of the workarounds documented on this page.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2604
Joined: March 23rd, 2015, 5:26 pm

Re: Run CMD.EXE as Administrator from Rainmeter

Post by SilverAzide »

Probably the elevation prompt is getting lost if the CMD or PowerShell window is hidden. Perhaps the following will help. Save the following as a .ps1 script and run it using PowerShell and see if it works:

Code: Select all

# test if current process is elevated; if not, relaunch
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
  # Relaunch as an elevated process:
  Start-Process powershell.exe "-File",('"{0}"' -f $MyInvocation.MyCommand.Path) -Verb RunAs
  exit
}
<your command goes here>
P.S.: Obviously, this will not work if you want to retrieve the results of the command, since this launches a secondary process that Rainmeter won't know about. If you just want to run something, though, it should work... (I didn't try it.)
Gadgets Wiki GitHub More Gadgets...