How do you use scripting to manipulate registry?
Hi!
Some days ago my company decided to change some parameters on their ExchangeServers so that all outlook clients has to be changed. I decided to use vbs / wsh to automate these changes.
At first I took a snapshot of the old registry. Than I changed the values and I took another Snapshot. After that I compared both.
A lot of registry keys were added and only two keys has changed. I tried to change the outlook setting using another value in both changed registry keys and it worked.
So I decided to compare the registry changes again while using outlook changing its settings. I found out that there were a second time many changes (including both which I change manually with regedit before).
I tried again and again and everytime I got other values which were changed ( including both "important" keys ).
How would you handle this problem?
My second problem is that my script only runs on some machines. On other machines it stops without finding the registrykey it should change. By looking manually I found the registry keys......... HELP!
Here is my script:
Const HKEY_CURRENT_USER = &h80000001
Const HKEY_USERS = &h80000003
Const machinename = "."
Set stdregprov = GetObject("winmgmts:\\" & machinename & "\root\Default:StdRegProv")
'get current User SID
GetCurrentUser()
Sub GetCurrentUser()
user = ""
Set WSHNetwork = Wscript.CreateObject("Wscript.Network")
username = WSHNetwork.UserName
Set wmi = GetObject("winmgmts:root/CIMV2")
wql = "Select SID from Win32_UserAccount Where Name='" & username &"'"
Set result = wmi.ExecQuery(wql)
For each instance in result
user = instance.SID
Next
If user <> "" then
GetOutlookProfiles(user)
Else
MsgBox "User couldn't be found."
Wscript.Quit
End If
End Sub
'getting mail-profiles
Function GetOutlookProfiles(user)
wurzel = HKEY_USERS
key = user & "\Software\Microsoft\windows NT\CurrentVersion\windows Messaging Subsystem\Profiles"
status = stdregprov.EnumKey(wurzel, key, subkeys)
If status = 0 then
For each subkey in subkeys
Call ChOutlook(user, subkey)
Next
Else
Wscript.Quit
End If
End Function
'Changing Outlooksettings
Function ChOutlook(user, profile)
wurzel = HKEY_USERS
key = user & "\Software\Microsoft\windows NT\CurrentVersion\windows Messaging Subsystem\Profiles\" & profile &"\0a0d020000000000c000000000000046"
eintrag = "000b0274"
status = stdregprov.GetBinaryValue(wurzel, key, eintrag, wert)
If status=0 then
werti = Hex(wert(x))
Else
Exit Function
End If
If werti = 0 then
Exit Function
Else
nwert = Array(00,00)
status = stdregprov.SetBinaryValue(wurzel, key, eintrag, nwert)
If status <> 0 Then
MsgBox "Value could not be changed."
Else
MsgBox"Outlook repaired."
End If
End If
End Function
Thanks in advanced
Ruben
|