Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...If there has ever been a justification needed for access to the net during working hours, just referring to this site should suffice. Fantastic!..."

Geography

Where in the world do Tek-Tips members come from?

Vbscript to remove unique registry key

K7mm (Programmer)
8 Aug 12 11:55
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
K7mm (Programmer)
9 Aug 12 9:46
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.
PHV (MIS)
9 Aug 12 10:02
K7mm (Programmer)
9 Aug 12 18:58
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

K7mm (Programmer)
18 Aug 12 10:25
I have tried different ways still not working, any ideas?
guitarzan (Programmer)
20 Aug 12 11:54
Your DeleteKey syntax is not correct. Should be something like:
objRegistry.DeleteKey HKEY_CURRENT_USER, strKeyPath & "\" & objSubkey

See here for some info.
http://technet.microsoft.com/en-us/magazine/2006.0...
K7mm (Programmer)
20 Aug 12 21:06
Thanks for the link...it was helpful.


I tried your syntax example.

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


No Dice sadeyes
guitarzan (Programmer)
20 Aug 12 23:13
Define "no dice". Did you get an error? If so, what was it?
K7mm (Programmer)
20 Aug 12 23:22
no error, the key remains.
K7mm (Programmer)
22 Aug 12 1:55

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.

guitarzan (Programmer)
22 Aug 12 9:53
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
K7mm (Programmer)
23 Aug 12 19:13
Sorry, "On Error Resume Next" is in my script. If I take it out it still does not work.
guitarzan (Programmer)
23 Aug 12 21:38
Yes, but it should give an error
K7mm (Programmer)
24 Aug 12 0:32
the error code

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


Hope this helps
guitarzan (Programmer)
24 Aug 12 9:05
It might, when you show your code and indicate which line is line 11 smile
K7mm (Programmer)
24 Aug 12 15:18
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
guitarzan (Programmer)
24 Aug 12 15:51
Now we are getting somewhere.

1) Const HKEY_CURRENT_USER = &H80000002 is wrong... should be

CODE

HKEY_CURRENT_USER = &H80000001 
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
K7mm (Programmer)
24 Aug 12 17:53
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
guitarzan (Programmer)
25 Aug 12 0:07
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.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close