Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Check to see if a registry key exists, it is driving me mad!

$
0
0

Script Language - vbScript.

I am currently developing a script to check our servers have specific SNMP configuration settings, if they do not then the script will make the neccessary changes automatically.  The intention is to deploy this targetting our servers OU via a Start Up Script GPO.  During testing I am running into a problem with one of the checks which surrounds checking to see if a registry key exists, the boolean return value of the check registry key exists function is true and I cannot figure out how that is the case when the registry key concerned does not exist initally??

Below is the code snippet concerned, if anybody can tell me where I have gone wrong that would be of a great assistance!

(Main Code)

 If CheckCommunityTrapConfig = False Then
  If ReadRegistryValue(HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Services\SNMP\Parameters\TrapConfiguration\B0ndStr33t", "NULL", REG_KEY) = False Then
   sNewValue = "SYSTEM\CurrentControlSet\Services\SNMP\Parameters\TrapConfiguration\B0ndStr33t"
   If SetRegistryValue(HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Services\SNMP\Parameters\TrapConfiguration\B0ndStr33t", "NULL", REG_KEY) = True Then
    sNewValue = "10.212.10.115"
    If SetRegistryValue(HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Services\SNMP\Parameters\TrapConfiguration\B0ndStr33t", "1", REG_SZ) = False Then
     WriteToLogFile "017 (SNMP Orion Monitoring Server #10) : Error!  The attempt to create the trap server registry value for the community BB0ndStr33t failed!"   
     QuitScript
    End If
    If CheckCommunityTrapConfig = False Then
     WriteToLogFile "018 (SNMP Orion Monitoring Server #10) : Error!  The attempt to create the trap server community and destination trap server failed!"      
     QuitScript
    Else
     iServiceRestartRequired = 1
    End If
   Else
    WriteToLogFile "019 (SNMP Orion Monitoring Server #10) : Error!  The attempt to create the registry value for the community BB0ndStr33t failed!"   
    QuitScript
   End If
  Else
   If EnumerateRegistryValues(HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Services\SNMP\Parameters\TrapConfiguration\B0ndStr33t") = False Then
    sNewValue = "SYSTEM\CurrentControlSet\Services\SNMP\Parameters\TrapConfiguration\B0ndStr33t"
    If SetRegistryValue(HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Services\SNMP\Parameters\TrapConfiguration\B0ndStr33t", "NULL", REG_KEY) = True Then
     sNewValue = "10.212.10.115"
     If SetRegistryValue(HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Services\SNMP\Parameters\TrapConfiguration", "B0ndStr33t", REG_SZ) = False Then
      WriteToLogFile "020 (SNMP Orion Monitoring Server #10) : Error!  The attempt to create the trap server registry value for the community BB0ndStr33t failed!"   
      QuitScript
     End If
     If CheckCommunityTrapConfig = False Then
      WriteToLogFile "021 (SNMP Orion Monitoring Server #10) : Error!  The attempt to create the trap server community and destination trap server failed!"      
      QuitScript
     Else
      iServiceRestartRequired = 1
     End If
    Else
     WriteToLogFile "022 (SNMP Orion Monitoring Server #10) : Error! The attempt to create the community B0ndStr33t failed!"
     QuitScript
    End If
   Else
    sNewValue = "10.212.10.115"
    iArrayElementFound = -1
    On Error Resume Next
    For i = 0 To UBound(arrRegistryResult)
     If arrRegistryResult(i) = sNewValue Then
      iArrayElementFound = i
     End If
    Next
    On Error Goto 0
    If Err.Number = 9 Then
     WriteToLogFile "023 (SNMP Orion Monitoring Server #10) :  Error! The attempt to find a matching trap destionation server in the results array failed as no data was present in the array!"
     QuitScript
    End If
    If iArrayElementFound = -1 Then
     If SetRegistryValue(HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Services\SNMP\Parameters\TrapConfiguration\B0ndStr33t", UBound(arrRegistryResult) + 2, REG_SZ) = False Then
      WriteToLogFile "024 (SNMP Orion Monitoring Server #10) : Error!  The attempt to create the registry key " & UBound(arrRegistryResult) + 2 & " with the value of 10.212.10.115 failed!"
      QuitScript
     Else
      iServiceRestartRequired = 1
     End If
    Else
     If ChecCommunityTrapConfig = False Then
      WriteToLogFile "025 (SNMP Orion Monitoring Server #10) : Error!  The attempt to create the permitted trap server failed!"
      QuitScript
     Else
      iServiceRestartRequired = 1
     End If
    End If   
   End If
  End If
 End If

'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Function CheckCommunityTrapConfig()
 ' #10 Check that the correct community name and trap destination for the Orion monitoring server has been configured correctly
 If ReadRegistryValue(HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Services\SNMP\Parameters\TrapConfiguration\B0ndStr33t", "NULL", REG_KEY) = False Then
  WriteToLogFile "065 (SNMP Orion Monitoring Community #10) : Warning!  The SNMP Orion Monitoring Community has not been configured."
  CheckCommunityTrapConfig = False
 Else
  If EnumerateRegistryValues(HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Services\SNMP\Parameters\TrapConfiguration\B0ndStr33t") = False Then
   WriteToLogFile "066 (SNMP Orion Monitoring Community #10) : Error!  The first #10 check performed was successful, the second check performed failed for some reason?"
   CheckCommunityTrapConfig = False
  Else
   iArrayElementFound = -1
   On Error Resume Next
   For i = 0 To UBound(arrRegistryResult)
    If ReadRegistryValue(HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Services\SNMP\Parameters\TrapConfiguration\B0ndStr33t", arrRegistryResult(i), REG_SZ) = True And sRegistryResult = "10.212.10.115" Then
     iArrayElementFound = arrRegistryResult(i)
    End If
   Next
   If Err.Number = 9 Then
    WriteToLogFile "130 (SNMP Security Configr #13) : Warning! The attempt to the permitted managers array failed as no data was present in the array!"
    QuitScript
   End If
   On Error Goto 0
   If iArrayElementFound > -1 Then
    WriteToLogFile "067 (SNMP Orion Monitoring Server #10) : Passed.  The SNMP Orion Monitoring Community has been configured correctly with the Orion Monitoring server IP address."
    CheckCommunityTrapConfig = True
   Else
    WriteToLogFile "068 (SNMP Orion Monitoring Server #10) : Warnng!  The SNMP Orion Monitoring Server has not been configured for the Orion Monitoring Community."
    CheckCommunityTrapConfig = False
   End If
  End If
 End If
 
 Exit Function
End Function

'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Function EnumerateRegistryValues(sRegistryHive, sRegistryKey)
' This function reads the registry value passed and returns the contents of the value to a public
' variable that can be accessed within any part of the script.  If any values are found then the
' function returns a True boolean value or if no values are found a False boolean value is returned
' by the function
 
 ' Private Variables
 Dim objRegistry
  
 ' Open the WMI registry object
 Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & CURRENT_COMPUTER & "\root\default:StdRegProv")

 Erase arrRegistryResult
 objRegistry.EnumValues sRegistryHive, sRegistryKey, arrRegistryResult
 
 On Error Resume Next
 If UBound(arrRegistryResult) => 0 Then
  EnumerateRegistryValues = True
 Else
  EnumerateRegistryValues = False
 End If
 ' Capture the out of bounds error that occurs when attempting to get the upper bounds for an empty array
 If Err.Number = 9 Then
  EnumerateRegistryValues = False
 End If
 On Error Goto 0
 
 ' Clean up and exit function
 Set objRegistry = Nothing
 Exit Function
End Function
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Function ReadRegistryValue(sRegistryHive, sRegistryKey, sRegistryValue, sValueType)
' This function reads the registry value passed and returns the contents of the value to a public
' variable that can be accessed within any part of the script.  If the value is found then the
' function returns a True boolean value or if it is not found a False boolean value is returned
' by the function
 
 ' Private Variables
 Dim objRegistry
 
 ' Open the WMI registry object
 Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & CURRENT_COMPUTER & "\root\default:StdRegProv")

 ' Determine the registry type being read and use appropiate object access command based on the registry
 ' value type.
 On Error Resume Next
 Select Case sValueType
  Case REG_KEY
   sRegistryResult = ""
   If sRegistryHive = HKEY_LOCAL_MACHINE Then sRegistryHive = "HKLM"
   If sRegistryHive = HKEY_CURRENT_USER Then sRegistryHive = "HKCU"
   If sRegistryHive = HKEY_CLASSES_ROOT Then sRegistryHive = "HKCR"
   If sRegistryHive = HKEY_CURRENT_CONFIG Then sRegistryHive = "HKCC"
   If sRegistryHive = HKEY_USERS Then sRegistryHive = "HKU"
   WriteToLogFile "086 (ReadRegistryValue) : Checking for registry key " & sRegistryHive & "\" & sRegistryKey & "."
   objShell.RegRead sRegistryHive & "\" & sRegistryKey
'   objRegistry.GetStringValue sRegistryHive, sRegistryKey, "(Default)", sRegistryResult
  Case REG_BINARY
   WriteToLogFile "087 (ReadRegistryValue) : Checking for registry binary value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & "."
   If UBound(arrRegistryResult) > 0 Then Erase arrRegistryResult   
   objRegistry.GetBinaryValue sRegistryHive, sRegistryKey, sRegistryValue, arrRegistryResult
  Case REG_EXPAND_SZ
   WriteToLogFile "088 (ReadRegistryValue) : Checking for registry expanded text value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & "."
   sRegistryResult = ""
   objRegistry.GetExpandedStringValue sRegistryHive, sRegistryKey, sRegistryValue, sRegistryResult
  Case REG_MULTI_SZ
   WriteToLogFile "089 (ReadRegistryValue) : Checking for registry multi string text value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & "."
   If UBound(arrRegistryResult) > 0 Then Erase arrRegistryResult   
   objRegistry.GetMultiStringValue sRegistryHive, sRegistryKey, sRegistryValue, arrRegistryResult
  Case REG_SZ
   WriteToLogFile "090 (ReadRegistryValue) : Checking for registry string value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & "."
   sRegistryResult = ""
   objRegistry.GetStringValue sRegistryHive, sRegistryKey, sRegistryValue, sRegistryResult
  Case REG_DWORD
   WriteToLogFile "091 (ReadRegistryValue) : Checking for registry dword value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & "."
   sRegistryResult = ""
   objRegistry.GetDWORDValue sRegistryHive, sRegistryKey, sRegistryValue, sRegistryResult
  Case Else
   WriteToLogFile "092 (ReadRegistryValue) : Error! The value for the variable sValueType was not matched in the Select Case statement."
   ReadRegistryValue = False
   QuitScript
 End Select
 
 ' Determine if the reading of the registry value went OK by checking for an error.
 If Err.Number <> 0 Then
  WriteToLogFile "093 (ReadRegistryValue) : Error! The attempt to read the registry value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & " failed with the error " & Err.Number & "(" & Err.Description& ")."
  ReadRegistryValue = False
  QuitScript
 Else
  WriteToLogFile "094 (ReadRegistryValue) : The attempt to read the registry value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & " did not return an error (Success)."
  ReadRegistryValue = True
 End If
 On Error Goto 0

 ' Determine the registry type being read and then perform validation check to ensure the public variable has been
 ' populated, if no population has occurred then the value does not exist therefore return boolean value False
 ' This only applies to multi-value registry objects such as the Binary and MultiSz objects as you could well have
 ' a standard registry text object that has a null length value but does actually exist
 Select Case sValueType  
  Case REG_BINARY
   On Error Resume Next
   If Ubound(arrRegistryResult) < 0 Then
    WriteToLogFile "095 (ReadRegistryValue) : Warning! The attempt to read the registry value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & " failed as nothing was returned."
    ReadRegistryValue = False
   Else
    WriteToLogFile "096 (ReadRegistryValue) : The registry value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & " contains " & UBound(arrRegistryResult) & " array fields."
    ReadRegistryValue = True
   End If
   ' Capture the out of bounds error that occurs when attempting to get the upper bounds for an empty array
   If Err.Number = 9 Then
    WriteToLogFile "097 (ReadRegistryValue) : Warning! The attempt to read the registry value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & " failed as nothing was returned."
    ReadRegistryValue = False
   End If
   On Error Goto 0
  Case REG_MULTI_SZ
   On Error Resume Next
   If Ubound(arrRegistryResult) < 0 Then
    WriteToLogFile "098 (ReadRegistryValue) : Warning! The attempt to read the registry value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & " failed as nothing was returned."
    ReadRegistryValue = False
   Else
    WriteToLogFile "099 (ReadRegistryValue) : The registry value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & " contains " & UBound(arrRegistryResult) & " array fields."
    ReadRegistryValue = True
   End If
   ' Capture the out of bounds error that occurs when attempting to get the upper bounds for an empty array
   If Err.Number = 9 Then
    WriteToLogFile "100 (ReadRegistryValue) : Warning! The attempt to read the registry value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & " failed as nothing was returned."
    ReadRegistryValue = False
   End If
   On Error Goto 0
  Case Else
   WriteToLogFile "101 (ReadRegistryValue) : Secondary confirmation of registry value skipped as value may be empty due to registry type of " & sValueType & " used."
 End Select
 
 ' Clean up and exit function
 Set objRegistry = Nothing
 Exit Function
End Function
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Function WriteToLogFile(sLogFileEntry)
' Write the text passed in the sLogFileEntry function parameter to the log file object
 
 objLogFile.WriteLine("[" & Date() & " - " & Time() & "]  :  " & sLogFileEntry)
 Exit Function
End Function
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Function QuitScript()
' Close the public script objects and log file
 
 WriteToLogFile "SNMPAutoConfig.VBS script finished."

 objLogFile.Close

 Set objLogFile = Nothing
 Set objFSO = Nothing
 Set objShell = Nothing
 Set objWMI = Nothing
 
 WScript.Quit
 Exit Function
End Function
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Function SetRegistryValue(sRegistryHive, sRegistryKey, sRegistryValue, sValueType)
' This function sets the registry value contained in sRegistryResult or arrRegistryResult (dependant on the registry type being set). 
' If the value is configured correctly then the function returns a True boolean value or if the configuration fails a False boolean value
' is returned by the function
 
 ' Private Variables
 Dim objRegistry, sCurrentValueInRegistry, sNewValueInRegistry, i
 
 ' Open the WMI registry object
 Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & CURRENT_COMPUTER & "\root\default:StdRegProv")

 ' Determine the registry type being read and use appropiate object access command based on the registry
 ' value type.
 On Error Resume Next
 Select Case sValueType
  Case REG_KEY
   objRegistry.CreateKey sRegistryHive, sNewValue
  Case REG_BINARY
   objRegistry.SetBinaryValue sRegistryHive, sRegistryKey, sRegistryValue, arrNewValues
  Case REG_EXPAND_SZ
   objRegistry.SetExpandedStringValue sRegistryHive, sRegistryKey, sRegistryValue, sNewValue
  Case REG_MULTI_SZ
   objRegistry.SetMultiStringValue sRegistryHive, sRegistryKey, sRegistryValue, arrNewValues
  Case REG_SZ
   objRegistry.SetStringValue sRegistryHive, sRegistryKey, sRegistryValue, sNewValue
  Case REG_DWORD
   objRegistry.SetDWORDValue sRegistryHive, sRegistryKey, sRegistryValue, sNewValue
  Case Else
   WriteToLogFile "104 (SetRegistryValue) : Error! The value for the variable sValueType was not matched in the Select Case statement."
   SetRegistryValue = False
   QuitScript
 End Select
 
 ' Determine if the setting of the registry value went OK by checking for an error.
 If Err.Number <> 0 Then
  WriteToLogFile "105 (SetRegistryValue) : Error! The attempt to set the registry value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & " failed with the error " & Err.Number & "(" & Err.Description& ")."
  SetRegistryValue = False
  QuitScript
 Else
  WriteToLogFile "106 (SetRegistryValue) : The attempt to set the registry value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & " did not return an error (Success)."
  SetRegistryValue = True
 End If
 
 On Error Goto 0

 ' Determine the registry type being read and then perform validation check to ensure the new registry value
 ' has been set
 
 Select Case sValueType
  Case REG_KEY
   If ReadRegistryValue(sRegistryHive, sRegistryKey & "\" & sNewValue, "NULL", REG_KEY) = True Then
    WriteToLogFile "107 (SetRegistryValue) : The new registry key " & sRegistryHive & "\" & sRegistryKey & "\" & sNewValue & " was succesfully created."
    SetRegistryValue = True
   Else
    WriteToLogFile "108 (SetRegistryValue) : Error! The new registry key " & sRegistryHive & "\" & sRegistryKey & "\" & sNewValue & " was not created."
    SetRegistryValue = False
   End If
  Case REG_BINARY
   If ReadRegistryValue(sRegistryHive, sRegistryKey, sRegistryValue, REG_BINARY) = False Then
    WriteToLogFile "109 (SetRegistryValue) : Error! The new registry binary value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & " was not created."
    SetRegistryValue = False
   Else
    sCurrentValueInRegistry = ""
    For i = 0 To UBound(arrRegistryResult) - 1
     sCurrentValueInRegistry = sCurrentValueInRegistry & arrRegistryResult(i)
    Next
    sNewValueInRegistry = ""
    For i = 0 To UBound(arrNewValues) - 1
     sNewValueInRegistry = sNewValueInRegistry & arrNewValues(i)
    Next
    If sCurrentValueInRegistry = sNewValueInRegistry Then
     WriteToLogFile "110 (SetRegistryValue) : The new registry binary value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & " was succesfully created."
     SetRegistryValue = True
    Else
     WriteToLogFile "111 (SetRegistryValue) : The new registry binary value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & " exists but does not match the new expected value of " & sNewValueInRegistry& ", current value is " & sCurrentValueInRegistry & "."
     SetRegistryValue = False
    End If
   End If
  Case REG_EXPAND_SZ
   If ReadRegistryValue(sRegistryHive, sRegistryKey, sRegistryValue, REG_EXPAND_SZ) = False Then
    WriteToLogFile "112 (SetRegistryValue) : Error! The new registry expanded text value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & " was not created."
    SetRegistryValue = False
   Else
    If sNewValue = sRegistryResult Then
     WriteToLogFile "113 (SetRegistryValue) : The new registry expanded text value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & " was succesfully created."
     SetRegistryValue = True
    Else
     WriteToLogFile "114 (SetRegistryValue) : The new registry expanded text value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & " exists but does not match the new expected value of " & sNewValue & ", current value is " & sRegistryResult & "."
     SetRegistryValue = False
    End If
   End If
  Case REG_MULTI_SZ
   If ReadRegistryValue(sRegistryHive, sRegistryKey, sRegistryValue, REG_MULTI_SZ) = False Then
    WriteToLogFile "115 (SetRegistryValue) : Error! The new registry multi text value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & " was not created."
    SetRegistryValue = False
   Else
    sCurrentValueInRegistry = ""
    For i = 0 To UBound(arrRegistryResult) - 1
     sCurrentValueInRegistry = sCurrentValueInRegistry & arrRegistryResult(i)
    Next
    sNewValueInRegistry = ""
    For i = 0 To UBound(arrNewValues) - 1
     sNewValueInRegistry = sNewValueInRegistry & arrNewValues(i)
    Next
    If sCurrentValueInRegistry = sNewValueInRegistry Then
     WriteToLogFile "116 (SetRegistryValue) : The new registry multi text value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & " was succesfully created."
     SetRegistryValue = True
    Else
     WriteToLogFile "117 (SetRegistryValue) : The new registry multi text value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & " exists but does not match the new expected value of " & sNewValue& ", current value is " & sCurrentValueInRegistry & "."
     SetRegistryValue = False
    End If
   End If
  Case REG_SZ
   If ReadRegistryValue(sRegistryHive, sRegistryKey, sRegistryValue, REG_SZ) = False Then
    WriteToLogFile "118 (SetRegistryValue) : Error! The new registry text value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & " was not created."
    SetRegistryValue = False
   Else
    If sNewValue = sRegistryResult Then
     WriteToLogFile "119 (SetRegistryValue) : The new registry text value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & " was succesfully created."
     SetRegistryValue = True
    Else
     WriteToLogFile "120 (SetRegistryValue) : The new registry text value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & " exists but does not match the new expected value of " & sNewValue& ", current value is " & sRegistryResult & "."
     SetRegistryValue = False
    End If
   End If
  Case REG_DWORD
   If ReadRegistryValue(sRegistryHive, sRegistryKey, sRegistryValue, REG_DWORD) = False Then
    WriteToLogFile "121 (SetRegistryValue) : Error! The new registry dword value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & " was not created."
    SetRegistryValue = False
   Else
    If CLng(sNewValue) = CLng(sRegistryResult) Then
     WriteToLogFile "122 (SetRegistryValue) : The new registry dword value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & " was succesfully created."
     SetRegistryValue = True
    Else
     WriteToLogFile "123 (SetRegistryValue) : The new registry dword value " & sRegistryHive & "\" & sRegistryKey & "\" & sRegistryValue & " exists but does not match the new expected value of " & sNewValue& ", current value is " & sRegistryResult & "."
     SetRegistryValue = False
    End If
   End If
  Case Else
   WriteToLogFile "124 (SetRegistryValue) : Error! The value for the variable sValueType was not matched in the second Select Case statement."
   SetRegistryValue = False
   QuitScript
 End Select
 
 ' Clean up and exit function
 Set objRegistry = Nothing
 Exit Function
End Function
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

 


spar1grep

Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>