Private Overloads Sub UpdateRegistry(ByVal strPath As String, ByVal Value As String)
Dim WSHShell As Object
Dim imp As New CRunAs_Impersonator
Try
WSHShell = CreateObject("WScript.Shell")
If GlobalSettings(5) = "True" Then
imp.ImpersonateStart(GlobalSettings(4), GlobalSettings(2), GlobalSettings(3)) 'creates new context using token for user
'everything between ImpersonateStart and ImpersonateStop will be run as the impersonated user
WSHShell.regwrite(strPath, Value, "REG_EXPAND_SZ")
imp.ImpersonateStop()
Else
WSHShell.regwrite(strPath, Value, "REG_EXPAND_SZ")
End If
Catch ex As Exception 'make sure impersonation is stopped whether code succeeds or not
LogMYErrors(ex, Err.Number, False)
If GlobalSettings(5) = "True" Then imp.ImpersonateStop()
Finally
WSHShell = Nothing
GC.Collect()
End Try
End Sub
|