Run as Admin

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Dominic_Fichera
Pro Scripter
Posts: 82
Joined: Mon Mar 24, 2014 12:15 pm

Run as Admin

Post by Dominic_Fichera » Wed Apr 01, 2015 3:43 am

Hey all,

I have written a script that will in turn write a .bat file to execute some commands that can't be completed within Macro Scheduler code. For this to be completed though, the .bat needs to be run as admin.

Code: Select all

Writeln>%TEMP_DIR%msfix.bat,ICACLS "C:\Program Files\MJT Net Ltd" /GRANT USERS:(CI)(OI)F
Writeln>%TEMP_DIR%msfix.bat,TASKKILL /F /IM msched.exe
Writeln>%TEMP_DIR%msfix.bat,pause
ExecuteFile>%TEMP_DIR%msfix.bat
The obvious way to make this work is to compile the macro and run the .exe as admin, but what I am wanting to know is if there is anyway to make a prompt appear similar to UAC that will let the .bat run as admin.

Hope this all makes sense! :)

Thanks in advance,

Dominic Fichera

Alternatively, are there any native MS commands which will grant folder permissions without having to run the whole macro/.exe as admin? Trying to streamline :)

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Run as Admin

Post by JRL » Wed Apr 01, 2015 2:29 pm

Not sure. What happens if instead of using executefile> to run the batch file you run from a DOS command line and use Runas. Something like:

RunProgram>cmd /c runas /user:mymachine\administrator %TEMP_DIR%msfix.bat

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Run as Admin

Post by Marcus Tettmar » Thu Apr 02, 2015 3:05 pm

To run the .bat file as admin you can do one of:

1. Start Macro Scheduler as admin in the first place. Then anything it runs will run as admin

Or

2. Do this:

Code: Select all

Let>RP_ADMIN=1
Run>%TEMP_DIR%msfix.bat
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts