Running .bat files as administrator on win 7 and win 2k8 machines
I have .bat which will be copied onto Win 7 and Win 2k8 machines remotely. The batch file contains scripts to stop and restart Windows services, like, net stop "Adobe Acrobat Update Service". Now when I run this batch file, I get "System error 5 has occurred. Access is denied." I understand that I need to run this batch file as administrator (here by administrator I mean, Windows default administrator.). Does anyone have a solution for this? P.S: 1) "run as" command inside the .bat file won't work, since you need to run the .bat file itself as administrator (here by administrator I mean, Windows default administrator.). 2) I can create another batch file (say b.bat) containing the "run as" command and invoking the the original batch file (say a.bat), which has the command net stop "Adobe Acrobat Update Service". But still, this won't solve the issue, since you can run as, the user, who has administrator privileges and not run as administrator (here by administrator I mean, Windows default administrator.) itself.
October 3rd, 2011 5:40am

Suhas, Can you explain me why you want to do this? Maby there are there some beter ways to achive your goal. The reason why this doesn't work is UAC who strips the administrator tokens from your user account. So it is not nesseary to use the default windows administrator account. Just a user with administrative priviliges will do you only need to run this command elevated. There are several ways to run this command elevated: Just right click on the batch file and choose the option run as administator. Quite simple but a no go if you wanna have a fully automated solution Use PsExec.exe from the pstools suite (avaible here) If you use the command like this: PSEXEC -u domain\user -p password -h net stop spooler PSEXEC -u domain\user -p password -h net start spooler Or from a remote machine (pcX = remote management machine, pcY = machine where you want to restart the service.) Execute this command on machine pcX: PSEXEC \\pcY -u domain\user -p password -h net stop spooler PSEXEC \\pcY -u domain\user -p password -h net start spooler Create a sheduled task with the "highest privlilges" that executes your batch file. etc ... Kind Regards DFTIM me - TWiTTer: @DFTER
Free Windows Admin Tool Kit Click here and download it now
October 4th, 2011 4:54pm

Suhas, Can you explain me why you want to do this? Maby there are there some beter ways to achive your goal. The reason why this doesn't work is UAC who strips the administrator tokens from your user account. So it is not nesseary to use the default windows administrator account. Just a user with administrative priviliges will do you only need to run this command elevated. There are several ways to run this command elevated: Just right click on the batch file and choose the option run as administator. Quite simple but a no go if you wanna have a fully automated solution Use PsExec.exe from the pstools suite (avaible here) If you use the command like this: PSEXEC -u domain\user -p password -h net stop spooler PSEXEC -u domain\user -p password -h net start spooler Or from a remote machine (pcX = remote management machine, pcY = machine where you want to restart the service.) Execute this command on machine pcX: PSEXEC \\pcY -u domain\user -p password -h net stop spooler PSEXEC \\pcY -u domain\user -p password -h net start spooler Create a sheduled task with the "highest privlilges" that executes your batch file. etc ... Kind Regards DFTIM me - TWiTTer: @DFTER
October 5th, 2011 9:46am

I found that registry projects are hard but they do get the job done. bat files cannot invoke a higher privilege, it must be configured to do do from the first called bat file Windows MVP 2010-11, XP, Vista, 7. Expanding into Windows Server 2008 R2, SQL Server, SharePoint etc. My page on Video Card Problems is now my most popular landing page. My Page on SSD is now #2. See my gaming site for game reviews etc. Developer | Windows IT | Chess | Economics | Hardcore Games | Vegan Advocate | PC Reviews
Free Windows Admin Tool Kit Click here and download it now
October 5th, 2011 2:21pm

I Found the solution: http://www.youtube.com/watch?v=OGHQzg69vsg
March 20th, 2012 5:10am

if you rename BAT files to CMD you can use more functionality Windows MVP 2010-11, XP, Vista, 7. Expanding into Windows Server 2008 R2, SQL Server, SharePoint, Cloud, Virtualization etc. etc. Hardcore Games, Legendary is the only Way to Play Developer | Windows IT | Chess | Economics | Vegan Advocate | PC Reviews
Free Windows Admin Tool Kit Click here and download it now
March 20th, 2012 7:41pm

Use the free tool (ELEVATE) to run it as administrator http://www.winability.com/elevate/
March 30th, 2012 8:46am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics