Friday, February 15, 2008

Vista "Run As Administrator"

Another question came up a few weeks ago on how to automate the MS Vista "Run as Administrator" option for any given EXE. Instead of manually checking this box under the "Compatibility" tab, this small snippet can be used in a larger script to automate that. If anyone knows of an .NET method or other Vista API on how to do this programmatically please let me know.
   1:  Const HKEY_CURRENT_USER = &H80000001
   2:  strComputer = "."
   3:  Set objReg=GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
   4:   
   5:  strKeyPath = "Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"
   6:  strValueName = "C:\Program Files\SAPIEN\PrimalScript 2007 Professional\PrimalScript.exe"
   7:  strValue = "RUNASADMIN"
   8:  objReg.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue

No comments: