Windows7 elevated command prompt priviledges throug a script RRS feed

  • Question

  • this was simple in windows xp.
    I have a script that installs Citrix web client.
    Problem I need to copy over the shortcut to users\public\public desktop through this script
    How can you program the copy to run in the Elevated command prompt mode to do this?
    Wednesday, February 10, 2010 9:55 PM


All replies

  • Hi Heflin,

    You should be able to get around this by using the runas command:

    runas /user:administrator /savecred c:\batchfile.bat

    you can also use the run as to place the admin's username and password in plain text, but that less desirable. In the above example, the batchfile.bat would contain all of your copy and install commands for the citrix client.

    Give it a shot, hope it helps,

    Kevin Costain - @calwell @calwell on Twitter Calwell's Blog Google Profile
    Thursday, February 11, 2010 6:17 AM
  • Greetings,
    I agree with Calwell’s reply. It seems that you want to run the copy action as an administrator using the script itself.

    You can refer the following URLs, hope it would be helpful.
    Utility Spotlight - Script Elevation PowerToys for Windows Vista
    How Can I Run a Script Under Alternate Credentials?
    Since this issue is more related to scripting, I recommend you open a thread to Official Scripting Guys Forum in Technet so those coders can help you fix the issue in a timely manner.
    Official Scripting Guys Forum http://social.technet.microsoft.com/Forums/en/ITCG/threads
    Script Center:  http://technet.microsoft.com/en-us/scriptcenter/default.aspx

    Thursday, February 11, 2010 9:29 AM
  • Hi,

    I'm on Win7 Home Premium and I want to write a batch script to start a service ("net start <svcname>").

    I have tried
    runas /user:administrator "net start <svcname>"
    but it doesn't work: It asks me for the password, I enter it, and then I get the error "unknown user name or bad password."

    I'm given to understand that, in Windows 7, there is no "administrator" account, so I tried it using my username, but that clearly doesn't run in "elevated" status, which is what I need.

    One of the answers here shows links to solutions for Vista, but I'm on Windows 7 and it looks like those Vista solutions don't work for Win7.

    Is there a way to start a service in Win7 Home Premium from a batch file (which requires running "elevated")? It's fine if I have to enter a password, or if the UAC confirmation window pops up. I would strongly prefer not to enable the administrator account (because I don't want to open myself up to other issues).

    -- mdeck
    Friday, September 16, 2011 8:57 PM
  • p.s. I want to start a service (elevated), then run a program (un-elevated), then stop the service (elevate). If I could figure out a way to start the program un-elevated in a batch, I could run the whole batch file as administrator, but so far I can't get "runas" to start the application as underprivileged me.
    Friday, September 16, 2011 9:35 PM
  • As I have not found any simple script so far, here's my two cents (derived from one of the URLs below):

    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



    Thursday, April 24, 2014 12:06 PM
  • Hi Nika,

    thanks for your script - it works, if I add the line


    before the line "DEL elevatedapp.vbs"

    so the script is also called after creation :-)

    kind regards,


    Wednesday, July 16, 2014 10:00 AM
  • Thanks very much for your answer Nika, but how would I use this to install Java instead?

    Wednesday, December 16, 2015 10:08 PM