Home » Questions » Computers [ Ask a new question ]

How to run program from command line with elevated rights

How to run program from command line with elevated rights

Is there a way to run a program or command with elevated rights when I am already in a non-elevated command line?

Asked by: Guest | Views: 102
Total answers/comments: 5
Guest [Entry]

"It looks like this utility - Hidden Start - will do what you wish if you use the /uac switch. Here's an example command line:

hstart /UAC ""notepad.exe""

This will pop up the UAC dialog rather than ask for a password like runas does."
Guest [Entry]

"Building on Rustam's answer, you can:

Create a su.bat batch file somewhere in your default %PATH%, with the following content:

@echo off
set cmd=%*
if not defined cmd set cmd=%ComSpec%
powershell iex """"""start -v runas $Env:cmd""""""

Add this function to your PowerShell $profile : function su {start -verb runas @args}

Now you can issue su <command> [parameters] in either shell !"
Guest [Entry]

RunAdmin is a small utility (150Kb) that lets you run a program from command line with elevated rights (it will show the UAC). And opposite to Hidden Start is freeare.
Guest [Entry]

"There is another way to run a process with UAC elevation that works without third-party tools and without having to set the execution policies for PowerShell.

This approach uses the Microsoft HTML Application Host (mshta) to run a VBScript snippet in the form of a single command:

mshta vbscript:Execute(""Set UAC = CreateObject(""""Shell.Application""""):
UAC.ShellExecute """"SomeProcess.exe"""", """"SomeArguments"""", """""""", """"runas"""", 1:close"")"
Guest [Entry]

"You can set __COMPAT_LAYER=RunAsAdmin.
Then the commands will run in a separate elevated cmd.

Example .bat:

rem Run next command elevated to Admin.
set __COMPAT_LAYER=RunAsAdmin
reg add ""HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Group Policy\{35378EAC-683F-11D2-A89A-00C04FBBCFA2}"" /t REG_DWORD /v ""NoBackgroundPolicy"" /d ""1""
rem Disable elevation
rem continue non elevated
reg add ""HKEY_CURRENT_USER\SOFTWARE\Policies\Microsoft\Internet Explorer\Main"" /t REG_SZ /v ""Start Page"" /d ""www.google.com"" /f

All Compatibility Mode options are listed in the MS Application Compatibility Toolkit."