onsdag 27. juni 2012

Elevate in the middle of a batch-file

Have you ever run into an issue where you need to elevate during a script. Sometimes it's more convenient to allow users to run the scripts themselves, and if they are local admins they can do some serious changes also with a script. If you place your script on a mapped network drive, and they right-click that batch-file and select run as administrator, the administrative profile would not have any mapped drives, and trying to run the script will fail miserably.

Here is the solution:
http://technet.microsoft.com/en-us/magazine/2007.06.utilityspotlight.aspx?pr=blog

Examples:
elevate net stop spooler
elevate REG ADD HKLM\Software\Blabla /v Enabled /t REG_SZ /d 1