How to run cmd.exe elevated in batch script

manik14

New member
Local time
3:28 AM
Messages
1
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 :mad:. 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

Computer type
PC/Desktop
OS
Windows 7 x64
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

Computer type
Laptop
Computer Manufacturer/Model Number
HP Elitebook 8540p
OS
Windows 7 Pro 32
CPU
Intel(R) Core(TM) i5 CPU M 540 @ 2.53GHz
Motherboard
Hewlett-Packard 1521
Memory
4,00 GB (Usable 2,98)
Graphics Card(s)
NVIDIA NVS 5100M
Sound Card
NVIDIA High Definition Audio
Screen Resolution
1600x900
Hard Drives
INTEL SSDSA2CW120G3
Antivirus
F-Secure Internet Security
Browser
IE, Firefox, Opera
Other Info
Sandboxie,
SRP (Software Restriction Policy),
EMET (Enhanced Mitigation Experience Toolkit),
WFC (Windows Firewall Control by BiniSoft),
Malwarebytes Premium
Back
Top