Answered by:
how to run a program as adminitrator via the command line
-
Hello All,
I would like to know if there is a way to run a java program, requiring administrator priviledges, via the Windows command line.
Normally you would right click and then select 'run as administrator' - but i would like to set this as a property on the command line, so that you dont have to right click every time. Is this possible?
Question
Answers
-
Create a new txtfile, pase this content:
@echo Set objShell = CreateObject("Shell.Application") > %temp%\sudo.tmp.vbs @echo args = Right("%*", (Len("%*") - Len("%1"))) >> %temp%\sudo.tmp.vbs @echo objShell.ShellExecute "%1", args, "", "runas" >> %temp%\sudo.tmp.vbs @cscript %temp%\sudo.tmp.vbsand save it as SUDO.cmd.Now copy the cmd to your system32 folder.
When you now want to run a programm with admin rights type this:
sudo cmd /k javaw.exe JAVA file
Now accept the UAC prompt.
Hope this helps.
André
"A programmer is just a tool which converts caffeine into code" CLIP- Stellvertreter http://www.winvistaside.de/- Proposed as answer by Andre.Ziegler Tuesday, August 17, 2010 12:52 PM
- Marked as answer by Leo HuangMicrosoft contingent staff, Moderator Wednesday, August 25, 2010 1:14 AM
-
Hi harriet, there is a DOS command you can use to run as administrator in command line:
runas /profile /user:administrator “Driver:\folder\program”
For example, the administrator account is “AAA” and you want to run BBB.exe of C:\programs, you should do these following steps:
1 Press Win key & R
2 Input “CMD” in open box and click “OK”
3 Input: runas /profile /user:AAA “C:\programs\BBB.exe” and press “Enter”
4 Input the password of administrator AAA
5 Press “Enter”
Hope it works.
- Marked as answer by Leo HuangMicrosoft contingent staff, Moderator Wednesday, August 25, 2010 1:14 AM
All replies
-
Create a new txtfile, pase this content:
@echo Set objShell = CreateObject("Shell.Application") > %temp%\sudo.tmp.vbs @echo args = Right("%*", (Len("%*") - Len("%1"))) >> %temp%\sudo.tmp.vbs @echo objShell.ShellExecute "%1", args, "", "runas" >> %temp%\sudo.tmp.vbs @cscript %temp%\sudo.tmp.vbsand save it as SUDO.cmd.Now copy the cmd to your system32 folder.
When you now want to run a programm with admin rights type this:
sudo cmd /k javaw.exe JAVA file
Now accept the UAC prompt.
Hope this helps.
André
"A programmer is just a tool which converts caffeine into code" CLIP- Stellvertreter http://www.winvistaside.de/- Proposed as answer by Andre.Ziegler Tuesday, August 17, 2010 12:52 PM
- Marked as answer by Leo HuangMicrosoft contingent staff, Moderator Wednesday, August 25, 2010 1:14 AM
-
Hi harriet, there is a DOS command you can use to run as administrator in command line:
runas /profile /user:administrator “Driver:\folder\program”
For example, the administrator account is “AAA” and you want to run BBB.exe of C:\programs, you should do these following steps:
1 Press Win key & R
2 Input “CMD” in open box and click “OK”
3 Input: runas /profile /user:AAA “C:\programs\BBB.exe” and press “Enter”
4 Input the password of administrator AAA
5 Press “Enter”
Hope it works.
- Marked as answer by Leo HuangMicrosoft contingent staff, Moderator Wednesday, August 25, 2010 1:14 AM
-
-
-
-
Andre, any documentation on this?
It worked for me.
is there a way to include cmd /k in the "...... %1" because it returned an error when i tried that saying cannot find......
If you can link to documentation that would be nice.
Thanks.
<textarea style="height:80px;width:444px;border:1px solid grey;padding:2px;"></textarea><select><option value="af">Afrikaans</option><option value="sq">Albanian</option><option value="ar">Arabic</option><option value="hy">Armenian</option><option value="az">Azerbaijani</option><option value="eu">Basque</option><option value="be">Belarusian</option><option value="bg">Bulgarian</option><option value="ca">Catalan</option><option value="zh-CN">Chinese (Simplified)</option><option value="zh-TW">Chinese (Traditional)</option><option value="hr">Croatian</option><option value="cs">Czech</option><option value="da">Danish</option><option selected="selected" value="auto">Detect language</option><option value="nl">Dutch</option><option value="en">English</option><option value="et">Estonian</option><option value="tl">Filipino</option><option value="fi">Finnish</option><option value="fr">French</option><option value="gl">Galician</option><option value="ka">Georgian</option><option value="de">German</option><option value="el">Greek</option><option value="ht">Haitian Creole</option><option value="iw">Hebrew</option><option value="hi">Hindi</option><option value="hu">Hungarian</option><option value="is">Icelandic</option><option value="id">Indonesian</option><option value="ga">Irish</option><option value="it">Italian</option><option value="ja">Japanese</option><option value="ko">Korean</option><option value="la">Latin</option><option value="lv">Latvian</option><option value="lt">Lithuanian</option><option value="mk">Macedonian</option><option value="ms">Malay</option><option value="mt">Maltese</option><option value="no">Norwegian</option><option value="fa">Persian</option><option value="pl">Polish</option><option value="pt">Portuguese</option><option value="ro">Romanian</option><option value="ru">Russian</option><option value="sr">Serbian</option><option value="sk">Slovak</option><option value="sl">Slovenian</option><option value="es">Spanish</option><option value="sw">Swahili</option><option value="sv">Swedish</option><option value="th">Thai</option><option value="tr">Turkish</option><option value="uk">Ukrainian</option><option value="ur">Urdu</option><option value="vi">Vietnamese</option><option value="cy">Welsh</option><option value="yi">Yiddish</option></select>⇄<select><option value="af">Afrikaans</option><option value="sq">Albanian</option><option value="ar">Arabic</option><option value="hy">Armenian</option><option value="az">Azerbaijani</option><option value="eu">Basque</option><option value="be">Belarusian</option><option value="bg">Bulgarian</option><option value="ca">Catalan</option><option value="zh-CN">Chinese (Simplified)</option><option value="zh-TW">Chinese (Traditional)</option><option value="hr">Croatian</option><option value="cs">Czech</option><option value="da">Danish</option><option value="nl">Dutch</option><option selected="selected" value="en">English</option><option value="et">Estonian</option><option value="tl">Filipino</option><option value="fi">Finnish</option><option value="fr">French</option><option value="gl">Galician</option><option value="ka">Georgian</option><option value="de">German</option><option value="el">Greek</option><option value="ht">Haitian Creole</option><option value="iw">Hebrew</option><option value="hi">Hindi</option><option value="hu">Hungarian</option><option value="is">Icelandic</option><option value="id">Indonesian</option><option value="ga">Irish</option><option value="it">Italian</option><option value="ja">Japanese</option><option value="ko">Korean</option><option value="la">Latin</option><option value="lv">Latvian</option><option value="lt">Lithuanian</option><option value="mk">Macedonian</option><option value="ms">Malay</option><option value="mt">Maltese</option><option value="no">Norwegian</option><option value="fa">Persian</option><option value="pl">Polish</option><option value="pt">Portuguese</option><option value="ro">Romanian</option><option value="ru">Russian</option><option value="sr">Serbian</option><option value="sk">Slovak</option><option value="sl">Slovenian</option><option value="es">Spanish</option><option value="sw">Swahili</option><option value="sv">Swedish</option><option value="th">Thai</option><option value="tr">Turkish</option><option value="uk">Ukrainian</option><option value="ur">Urdu</option><option value="vi">Vietnamese</option><option value="cy">Welsh</option><option value="yi">Yiddish</option></select>Detect language » English
-
I can't find the link to the German forum/blog any longer.
Use this tool instead:
http://nircmd.nirsoft.net/elevate.html
nircmd elevate notepad.exe C:\Windows\System32\Drivers\etc\HOSTS
"A programmer is just a tool which converts caffeine into code"
- Proposed as answer by C Dublya Tuesday, October 10, 2017 8:57 PM
-
-
I don't like manually adding files to any folder under Windows unless absolutely necessary. Instead I added this (and other small utilities/scripts) to C:\Toolbox\ and added that to my %PATH% system environment variable. Is there a downside to this that made you choose System32 instead?
-
-
-
If you actually need elevated privileges this will not work. It should therefore not have been marked as the accepted answer, especially not by the person writing the answer.Hi harriet, there is a DOS command you can use to run as administrator in command line:
runas /profile /user:administrator “Driver:\folder\program”
-
I had this working only problem is that the new CMD window stays open until launched app is terminated, therefore my batch does not continue.
http://nircmd.nirsoft.net/elevate.html <-- this however rules!
I'm here to learn.
- Edited by Michael Blackkatt Sunday, April 09, 2017 1:47 PM