 |
| VBScript For questions and discussions related to VBScript. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

September 24th, 2003, 06:06 AM
|
|
Registered User
|
|
Join Date: Sep 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

March 11th, 2005, 01:20 PM
|
|
Registered User
|
|
Join Date: Mar 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i was wondering if this script can be used to modify the key that will prompt the user to enter his password when he opens outlook. can you help?
Quote:
quote:Originally posted by Ruben
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
|
|

March 11th, 2005, 01:45 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Ruben,
Dude, I can tell you are a tech because I couldn't understand what you want to do, what you had done, and what your problem is by your post.
You can modify Registry entries using RegWrite().
'=====
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.RegWrite "HKLM\Software\ODBC\ODBC.INI\SQLDSN\Descriptio n", "SQL"
'======
The default is REG_SZ. I forget where you add this in the line, either last or before the value, with "" and a comma.
MM23, if you don't know where to find this registry key, run a registry watcher and then make the change manually, and see where changes are made in the registry. Then plug that value into the script.
For both of you I strongly recommend Microsoft Windows 2000 Scripting Guide, the BEST administrative scripting book ever. Sorry Wrox.
HTH
mmcdonal
|

September 13th, 2006, 09:36 AM
|
|
Registered User
|
|
Join Date: Sep 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Ruben!
I´m having a similar problem. I´m trying to set the Outlook/Mail settings for each new User via a small Script. My problem are the keys under ...\Windows Messaging Subsystem\Profiles\<user>
Some of these Keys under each Profile seem to be fixed, some are Changing from mashine to mashine. I can´t find any information how these keys of the Messaging Subsystem are created.
If you find any information about this, drop me a line ;)
|
|
 |