none
how to run a program as adminitrator via the command line

    Question

  • 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?

    Tuesday, August 17, 2010 12:41 PM

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.vbs
    and 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/
    Tuesday, August 17, 2010 12:52 PM
  • 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.

    Thursday, August 19, 2010 5:08 AM
    Moderator

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.vbs
    and 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/
    Tuesday, August 17, 2010 12:52 PM
  • 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.

    Thursday, August 19, 2010 5:08 AM
    Moderator
  • with my solution you can run any tool you want with admin rights, without creating a shortcut for every tool

    "A programmer is just a tool which converts caffeine into code" CLIP- Stellvertreter http://www.winvistaside.de/
    Thursday, August 19, 2010 2:50 PM
  • it's not my script, I read it on a german blog several years ago. I'll try the updated version. Thanks for posting the link.
    "A programmer is just a tool which converts caffeine into code" CLIP- Stellvertreter http://www.winvistaside.de/
    Thursday, August 19, 2010 3:10 PM
  • Andre.Ziegler,  your command also apply to x64 applications?
    Saturday, September 29, 2012 9:17 PM
  • 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

    Monday, August 12, 2013 12:22 PM
  • 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"

    Tuesday, August 13, 2013 7:30 PM
  • This is the reason I nerd out on my computer for like 16 hours of the day. Cool encrypted solutions by great people who just want to help...worked like a charm!!!!

    Sunday, October 13, 2013 12:15 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?
    • Proposed as answer by nchamps Thursday, March 03, 2016 9:42 AM
    • Unproposed as answer by nchamps Thursday, March 03, 2016 9:42 AM
    Friday, September 19, 2014 4:20 AM
  • Hi.

    From command line in windows> digit ...cmd>over the cmd.exe>right mouse button>run as administrator....ready.

    Saturday, January 17, 2015 3:07 PM
  • While this will run as the user named "administrator" this will NOT run with an administrative run-space token as per the UAC environment. (As occurs when you right click and choose "run as administrator"
    Tuesday, November 01, 2016 3:49 PM
  • Hi harriet, there is a DOS command you can use to run as administrator in command line:

    runas /profile /user:administrator “Driver:\folder\program”

    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.
    Friday, November 04, 2016 4:23 AM
  • 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.


    Sunday, April 09, 2017 1:45 PM