Run one bat from another bat using elevated privileges.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sourbread
Posts: 23
Joined: 26 Apr 2012 09:10

Run one bat from another bat using elevated privileges.

#1 Post by sourbread » 10 May 2013 13:02

This might be simple, but I just can't seem to find anything specifically on how to run the command the way I need it.

Here is my dilemma..

Call it:
Script A
Script B

Script A runs without administrative privileges.. I need Script A to automatically kickoff Script B using admin privileges.

This is what I have so far, and I'm not sure exactly where I'm missing it.

Code: Select all

@echo off &cls
SET localname=%COMPUTERNAME%
RUNAS /USER:%localname%\Administrator "cmd \"Desktop\ScriptB.bat\""
pause


The \"Desktop...\"" seems a bit off but I was referencing one forum where they were doing a similar task with Notepad and it worked, so I tried using the same syntax using cmd.

Running this, it will just kick off a command prompt using elevated privileges, it won't load the bat file.

I've also tried removing the cmd portion and just using the .bat path without quotes, but that doesn't work either..

Just tried this as well, but it's still not working

Code: Select all

@echo off &cls
SET localname=%COMPUTERNAME%
RUNAS /USER:%localname%\Administrator "cmd /c ScriptB.bat"
pause

sourbread
Posts: 23
Joined: 26 Apr 2012 09:10

Re: Run one bat from another bat using elevated privileges.

#2 Post by sourbread » 10 May 2013 13:28

Got it :)

Code: Select all

@echo off &cls
SET localname=%COMPUTERNAME%
RUNAS /profile /USER:nscorp\g07bc "CMD /c \"C:\Users\g07bc\Desktop\New Folder\ScriptB.bat""
pause

Post Reply