How to run cmd.exe elevated in batch script


  1. Posts : 1
    Windows 7 x64
       #1

    How to run cmd.exe elevated in batch script


    Hi All,

    I am writing a dos batch file for windows7 and it has many commands which need elevated access to run. For elevation I am using elevate.exe. I am doing like below -

    set Elevation=elevate -wait cmd.exe /c
    %Elevation% "cd /d %CD% && xcopy /E /Y ...."
    %Elevation% "cd /d %CD% && command 2 .."
    %Elevation% "cd /d %CD% && command 3 .."
    %Elevation% "cd /d %CD% && command 4 .."
    .....

    My script calls elevate for cmd and then "cd /d %CD% for each command as elevate changes the working path to /system32 I am forced to change the directory every time I run elevate. It also prompts user for "UAC" dialog for each elevate command, so for ten such command UAC prompts will come 10 times . Commands I am using are mix of DOS command(like xcopy, diskpart etc) and some other 3rd party executable. So there is two problem for which I need some help-

    1. How to call elevate for cmd.exe once and run rest of the command in same elevated console.
    2. How to change working directory once instead with every command. I think solution to first one will take care of this also.

    Any help is most welcome.
      My Computer


  2. Posts : 1,049
    Windows 7 Pro 32
       #2

    Hi and welcome to SevenForums,

    For batch files I run manually I set the shortcut for it to run as administrator and I get ONE UAC prompt.

    I've never heard of elevate.exe
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 08:34.
Find Us