Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vbscript to remove unique registry key

Status
Not open for further replies.

K7mm

Programmer
Aug 8, 2012
11
US
I am running an update for an organizations email service with 1000+ users.

As part of this update I need to blow away their old email settings in outlook, there are some residual settings in the registry that I need to remove also. Normally I would make a simple .reg file and remove the registry keys in question. The problem I run into is one of the keys that need to be removed are unique to each user (ie: their email address). What makes this more complicated is that many of the users email addresses are different from their domain username. I would like to make a script to do this but I don't see where to start. Any help would be greatly appreciated.


Example:

HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\Autodiscover subkey bsmith8@email.com
 
Hello,

I have look at this before and it does not apply in this case. Those commands only let you read, delete and modify specific registry keys. The registry keys I need to remove are unique and change from user to user and from workstation to workstation.

Unfortunately there does not seem to be a wildcard way to delete registry keys, if there was I could simply make a script to delete *@email.com.

On the other hand I think I have the basic sodo code

I can read all the subkeys under HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\Autodiscover
then search for *@email.com with in the subkeys and what ever value comes from the read results....example rjohnson2@email.com
send command to delete rjohnson2@email.com
exit.

This should work but I am not sure how to code this.
 
Use the EnumKey method and the InStr function.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hello,

I am not the best at vbs but this is what I can up with. It does not work. Any help would be greatly appreciated.


Const HKEY_CURRENT_USER = &H80000002

strComputer = "."

Set objRegistry=GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")

strKeyPath = "Software\Microsoft\Office\12.0\Outlook\Autodiscover"
objRegistry.EnumKey HKEY_CURRENT_USER, strKeyPath, arrSubkeys

For Each objSubkey In arrSubkeys

Result = InStr(objSubkey, "@email.com")
if Result <> 0 then
objRegistry.DeleteKey HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\Autodiscover & objSubkey, strKeyPath
else

End If
Next

 
I have tried different ways still not working, any ideas?
 
Thanks for the link...it was helpful.


I tried your syntax example.

I also tried
DeleteSubkeys HKEY_CURRENT_USER, strKeyPath & "\" & objSubky


No Dice [sadeyes]
 
This is an example of what I want to delete if I did not make myself clear. I want to delete the subkey and everything in it and leave everything else. This sub key will change from one user to another.

Z9lFc.jpg
 
I hadn't noticed, but script in the link I sent includes the line "On Error Resume Next", which suppresses all run-time errors. Remove this line and try your script, and see if an error comes up
 
Sorry, "On Error Resume Next" is in my script. If I take it out it still does not work.
 
the error code

Line: 11
Char: 1
Error: Object not a collection
Code: 800A01C3
Source: Microsoft VBScript runtime error


Hope this helps
 
It might, when you show your code and indicate which line is line 11 :)
 
The code is the same listed above

I think line 11 is "For Each objSubkey In arrSubkeys"

___________________________________________________________________________
Const HKEY_CURRENT_USER = &H80000002

strComputer = "."

Set objRegistry=GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")

strKeyPath = "Software\Microsoft\Office\12.0\Outlook\Autodiscover"
objRegistry.EnumKey HKEY_CURRENT_USER, strKeyPath, arrSubkeys

For Each objSubkey In arrSubkeys

Result = InStr(objSubkey, "@email.com")
if Result <> 0 then
objRegistry.DeleteKey HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\Autodiscover & objSubkey, strKeyPath
else

End If
Next
 
Now we are getting somewhere.

1) Const HKEY_CURRENT_USER = &H80000002 is wrong... should be
Code:
[b]HKEY_CURRENT_USER = &H8000000[highlight #FCE94F]1[/highlight][/b]
If you fix that and still get the same exact error, it's probably because the key "HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\Autodiscover" does not exist.

2) You never fixed the DeleteKey syntax
 
Ok, I made the changes and get a different error

Line: 15
Char: 1
Error: Type mismatch 'DeleteSubkeys'
Code: 800A000D
Source: Microsoft VBScript runtime error
 
K7mm:
"DeleteSubkeys" is not in the code sample you provided. If you are not going to post the ACTUAL code that you use, then no one here will be able to help you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top