I\'m writing a client/server checking program but it needs to run as Administrator.
I want this to run silently on my network and users, and I don\'t want the \"Run
its possible using syntax:
RUNAS [/profile] [/env] [/netonly] /user:user Program
Key :
/profile Option to load the user's profile (registry)
/env Use current environment instead of user's.
/netonly Use the credentials specified only for remote connections.
/user Username in form USER@DOMAIN or DOMAIN\USER
(USER@DOMAIN is not compatible with /netonly)
Program The command to execute
example :
runas /env /user:domain\Administrator <program.exe/command you want to execute>
Create a shortcut and set the shortcut to always run as administrator.
How-To Geek forum Make a batch file to run cmd as administrator solution:
Make a batch file in an editor and nameit.bat then create a shortcut to it. Nameit.bat - shortcut. then right click on Nameit.bat - shortcut ->Properties->Shortcut tab -> Advanced and click Run as administrator. Execute it from the shortcut.
My solution, if you dont need to have .bat file, is to convert the batch file to .exe file then you will be able to set up run as admin.
As I have not found any simple script so far, here's my two cents:
set ELEVATE_APP=Full command line without parameters for the app to run
set ELEVATE_PARMS=The actual parameters for the app
echo Set objShell = CreateObject("Shell.Application") >elevatedapp.vbs
echo Set objWshShell = WScript.CreateObject("WScript.Shell") >>elevatedapp.vbs
echo Set objWshProcessEnv = objWshShell.Environment("PROCESS") >>elevatedapp.vbs
echo objShell.ShellExecute "%ELEVATE_APP%", "%ELEVATE_PARMS%", "", "runas" >>elevatedapp.vbs
DEL elevatedapp.vbs
Don't waste your time, use this one line command to run command line as administrator:
echo createobject("shell.application").shellexecute "cmd.exe",,,"runas",1 > runas.vbs & start /wait runas.vbs & del /f runas.vbs
if you want to start any application with administrator privilege you will just write the hole path for this application like this notepad++ in my program files for example :
echo createobject("shell.application").shellexecute "%programfiles%\Notepad++\notepad++.exe",,,"runas",1 > runas.vbs & start /wait runas.vbs
Following is a work-around:
Running the shortcut will execute your batch script as administrator.