I'm trying to write a batch file that creates a new directory in %programfiles%
. It needs to be run as admin. I've tried:
runas /user:admin-pc\admin "mkdir C:\Program Files\MyDir"
runas /user:admin-pc\admin "mkdir \"C:\Program Files\MyDir\""
runas /user:admin-pc\admin "cmd /c mkdir \"C:\Program Files\MyDir\""
runas /user:admin-pc\admin "cmd /c mkdir %programfiles%\MyDir"
runas /user:admin-pc\admin "cmd /c mkdir \"C:/Program Files/MyDir\""
runas /user:admin-pc\admin "cmd /c mkdir C:\Program^ Files\MyDir"
What's the right way to do this?
The question turned out to be IExpress specific.
You cam make your IExpress installer and use ResHacker to replace it's manifest with the one in my answer. http://angusj.com/resourcehacker It's Resource type 24.
This answer is console programs specific - see Run batch script as admin during Maven build for a more generic way.
To elevate in Windows the recommended way is by embedding a manifest. Which can't be done for text based programs. It's easy to put vbscript into VB.NET, add a manifest, and compile it.
Current scripting approaches mimic a right click and then Run As Administrator. This only works if file associations are Windows' defaults, eg the user can stop this approach from working by customising their system.
To use
EG
The files. Place each file on the desktop. The must be ANSI. Change this line from
/k
to/c
as you preferShell("cmd /k " & Command())
RunAsAdminConsole.vb
RunAsAdmin.Manifest
And the batch file RunAsAdminConsole.bat to compile above
A file called RunAsAdminConsole.exe will appear on the desktop.