New
#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.