20 August 2012

Report UAC Status to SMS or SCCM

This VB script will report the UAC status to SMS or SCCM. It queries the registry entry that shows if UAC is enabled/disabled and then edits the UAC.mif file with the status. It then initiates a hardware inventory to report the MIF file back to the SMS/SCCM.

You can download this script from here.
 '*******************************************************************************  
 '      Author: Mick Pletcher  
 '        Date: 20 August 2012  
 '    Modified:   
 '  
 '     Program: UACStatus.vbs
 '     Version:   
 ' Description: This will query the status of the UAC and report to SMS/SCCM  
 '                 1) Define the relative installation path  
 '                 2) Determine if x86 or x64  
 '                 3) Check UAC Status  
 '                 4) Generate MIF with UAC status  
 '                 5) Copy MIF to noidmifs  
 '                 6) Initiate SMS Hardware Inventory  
 '                 7) Cleanup Global Variables  
 '*******************************************************************************  
 Option Explicit

 REM Define Constants  
 CONST TempFolder  = "c:\temp\"  
 CONST LogFolderName = "UAC"  

 REM Define Global Variables  
 DIM Architecture : Set Architecture = Nothing  
 DIM RelativePath : Set RelativePath = Nothing  
 DIM UACStatus    : Set UACStatus    = Nothing  

 REM Define the relative installation path  
 DefineRelativePath()  
 REM Determine if x86 or x64  
 DetermineArchitecture()  
 REM Check UAC Status  
 CheckUACStatus()  
 REM Generate MIF with UAC status  
 GenerateMIF()  
 REM Copy MIF to noidmifs  
 CopyMIF()  
 REM Initiate SMS Hardware Inventory  
 InitiateSMSHardwareInventory()  
 REM Cleanup Global Variables  
 GlobalVariableCleanup()  

 '*******************************************************************************  
 '*******************************************************************************  

 Sub DefineRelativePath()  

      REM Get File Name with full relative path  
      RelativePath = WScript.ScriptFullName  
      REM Remove file name, leaving relative path only  
      RelativePath = Left(RelativePath, InStrRev(RelativePath, "\"))  

 End Sub  
 '*******************************************************************************  
 Sub DetermineArchitecture()  

      REM Define Local Objects  
      DIM WshShell : Set WshShell = CreateObject("WScript.Shell")  

      REM Define Local Variables  
      DIM OsType : OsType = WshShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE")  

      If OsType = "x86" then  
           Architecture = "x86"  
      ElseIf OsType = "AMD64" then  
           Architecture = "x64"  
      End If  

 End Sub  

 '*******************************************************************************  

 Sub CheckUACStatus()  

      REM Define Local Constants  
      CONST HKEY_CURRENT_USER  = &H80000001  
      CONST HKEY_LOCAL_MACHINE = &H80000002  

      REM Define Local Variables  
      DIM strComputer  : strComputer  = "."  
      DIM StdOut       : Set StdOut   = WScript.StdOut  
      DIM oReg         : Set oReg     = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_  
                                        strComputer & "\root\default:StdRegProv")  
      DIM strKeyPath   : strKeyPath   = "SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"  
      DIM strValueName : strValueName = "EnableLUA"  
      DIM dwValue      : Set dwValue  = Nothing  

      REM Get UAC value  
      oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue  
      If dwValue = 1 then  
           UACStatus = "Enabled"  
      Else  
           UACStatus = "Disabled"  
      End If  

      REM Local Variable Cleanup  
      Set dwValue      = Nothing  
      Set oReg         = Nothing  
      Set StdOut       = Nothing  
      Set strComputer  = Nothing  
      Set strKeyPath   = Nothing  
      Set strValueName = Nothing  

 End Sub  
 '*******************************************************************************  

 Sub GenerateMIF()  

      REM Define Local Constants  
      CONST ForReading = 1   
      CONST ForWriting = 2   

      REM Define Local Objects  
      DIM File          : File              = RelativePath & "UAC.mif"  
      DIM strOld        : strOld            = Chr(9) & Chr(9) & Chr(9) & "Value =" & Chr(32) & Chr(34) & Chr(34)  
      DIM strNew        : strNew            = Chr(9) & Chr(9) & Chr(9) & "Value =" & Chr(32) & UACStatus  
      DIM objFSO        : Set objFSO        = CreateObject("Scripting.FileSystemObject")   
      DIM objFile       : Set objFile       = objFSO.getFile(File)   
      DIM objTextStream : Set objTextStream = objFile.OpenAsTextStream(ForReading)   
      DIM strInclude    : strInclude        = objTextStream.ReadAll   

      objTextStream.Close  
      Set objTextStream = Nothing  
      If InStr(strInclude,strOld) > 0 Then   
           strInclude = Replace(strInclude,strOld,strNew)   
           Set objTextStream = objFile.OpenAsTextStream(ForWriting)   
           objTextStream.Write strInclude   
           objTextSTream.Close   
           Set objTextStream = Nothing   
      End If   

      REM Cleanup Local Variables  
      Set File          = Nothing  
      Set objFile       = Nothing   
      Set objFSO        = Nothing  
      Set objTextStream = Nothing  
      Set strInclude    = Nothing  
      Set strNew        = Nothing  
      Set strOld        = Nothing  

 End Sub  

 '*******************************************************************************  

 Sub CopyMIF()  

      REM Define Local Objects  
      DIM FSO : Set FSO = CreateObject("Scripting.FileSystemObject")  

      If FSO.FileExists(RelativePath & "UAC.mif") then  
           If Architecture = "x86" then  
                FSO.CopyFile RelativePath & "UAC.mif", "C:\Windows\System32\CCM\Inventory\noidmifs\", True  
           ElseIF Architecture = "x64" then  
                FSO.CopyFile RelativePath & "UAC.mif", "C:\Windows\SysWOW64\CCM\Inventory\noidmifs\", True  
           End If  
      End If  

      REM Cleanup Local Memory  
      Set FSO = Nothing  

 End Sub  

 '*******************************************************************************  

 Sub InitiateSMSHardwareInventory()  

      On Error Resume Next  
      DIM oCPAppletMgr   : Set oCPAppletMgr   = CreateObject("CPApplet.CPAppletMgr")  
      DIM oClientAction  : Set oClientAction  = Nothing  
      DIM oClientActions : Set oClientActions = oCPAppletMgr.GetClientActions()  

      For Each oClientAction In oClientActions  
           If oClientAction.Name = "Hardware Inventory Collection Cycle" Then  
                oClientAction.PerformAction  
           End If  
      Next  

 End Sub  
 '*******************************************************************************  

 Sub GlobalVariableCleanup()  

      Set Architecture = Nothing  
      Set RelativePath = Nothing  
      Set UACStatus    = Nothing  

 End Sub  

Here is the download of the MIF file that will need to be placed in the same directory which the VB script is executed from. The two name fields can be changed to any name you desire. I used the name of the firm I work for.
 Start Component   
      Name = "GSP"       
      Start group   
           Name = "GSP"   
           ID = 1   
           Class = "UAC"   
           Start Attribute   
                Name = "Status"   
                ID = 1   
                Type = String(10)   
                Value = Enabled   
           End Attribute   
      End group   
 End Component  

2 comments: