Its easy to run a batch script under the local Administrator account in Windows 7/Vista as there is an entry for that in the context menu. The option appears when you right click any batch file. VBScripts however are a different matter. After relying on CMD.exe with admin privileges as a workaround one time too many I decided to see if there was a better way! I found a nice registry import on another site that would add a context menu item for launching VBScripts as local admin. I tried it and it worked beautifully, I was able to right-click any .VBS file on my computer and a "Run as Administrator" option appeared and worked every time. Just for grins though I thought I'd try to create my own implementation using REG ADD with Batch. Here is the result:
@ECHO OFF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
TITLE Enable 'Run as Administrator' on VBScripts in Context Menu for Windows 7
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
ECHO Enable 'Run as Administrator' on VBScripts in Context Menu for Windows 7:
ECHO.
:: Add value for UAC shield icon:
REG ADD "HKCR\VBSFile\Shell\runas" /v HasLUAShield /t REG_SZ /d "" /f
:: Add value to create context menu item:
REG ADD "HKCR\VBSFile\Shell\runas\Command" /ve /t REG_EXPAND_SZ /d "\"%%SystemRoot%%\System32\WScript.exe\" \"%%1\" %%*" /f
:: Uncomment "PAUSE" to view script results:
ECHO.
PAUSE
Hope someone finds it useful.
No comments:
Post a Comment