Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

VBScript FAQ

Scripting for the Enterprise

Making scripts UAC aware by markdmac
Posted: 15 Feb 13

Detecting if UAC is Enabled or Not Set
MarkDMac's Enterprise Scripts

While working on a project for a customer that had a mix of Windows XP and Windows 7 computers, I encountered some trouble with getting a script to run on the test machine that had UAC enabled. Initially I just added code to always launch the script elevated, but then reports came in that the code would not execute on the Windows XP systems. I had to add in some code to detect the Windows version. That was all well and fine for the needs of the workstations, but then it dawned on me that Windows Server 2008 can also have UAC enabled, so after a little research I found where UAC is set in the registry and altered my template to no longer detect OS but detect UAC presence. I figured others would benefit from this template as well, so I am sharing it.


'Allow errors in case the registry key does not exist (Windows XP)
On Error Resume Next
'Now check if UAC is set.  1=Enabled, 0=Disabled. Missing is same as disabled
UACPath = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA"
Dim WshShell
Set WshShell = CreateObject("wscript.Shell")
UACValue = WshShell.RegRead(UACPath)
If UACValue = 1 Then
    'Run Elevated
		If WScript.Arguments.length =0 Then
		  Set objShell = CreateObject("Shell.Application")
		  'Relaunch the script elevated.  
                  'We pass a bogus arg (UAC) to determine if relaunched elevated.
		  objShell.ShellExecute "wscript.exe", Chr(34) & _
		  WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
		End If
End If

Function Body()
	'Put your script code in here!
End Function 

Back to VBScript FAQ Index
Back to VBScript Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close