WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

UAC

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Cmd Prompt Run As Administrator

 Keywords: Cmd Cmd.exe COMSPEC Prompt Run As RunAs Administrator requested operation requires elevation
 

Question:

I want to run a command from a DOS Prompt in Windows 7 from within WinBatch:
RunHideWait( Environment("COMSPEC"), '/c %Commands% >"%CommandRes%"')
This works fine for normal commands but some like NETSH reports "The requested operation requires elevation (Run as administrator)."

How do you launch a DOS Prompt with Run as administrator from WinBatch? Thanks

Answer:

Try ShellExecute with "RunAs" verb to launch your application as an Administrator
; You must be logged into a admin account for this to work
ShellExecute(Environment("COMSPEC"), '/k Echo Test', '', @NORMAL, 'RunAs')
Exit

Article ID:   W18310
Filename:   Cmd Prompt Run As Administrator.txt
File Created: 2014:05:07:10:16:14
Last Updated: 2014:05:07:10:16:14