Solved

vbscript registry append

Posted on 2009-04-08
4
1,422 Views
Last Modified: 2012-05-06
I created a script to append to a registry key, this work fine, except, I want to put this as a GPO start up script and it will re-write the entry every time it's run.  How can I adjust the script to tell if it already exist to not write?  Keep in mind that there could be any number of entries in this reg key?

Help is appreciated!
Option Explicit
On Error Resume Next
Dim WSHShell, rtnValue, newValue
Set WSHShell = WScript.CreateObject("WScript.Shell")
rtnValue = WSHShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyOverride")
If Right(Trim(rtnValue),1)=";" Then newValue = "*.test.com" Else newValue = "*.test.com"
WSHShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyOverride", rtnValue & _
newValue, "REG_SZ"
Set WSHShell = Nothing

Open in new window

0
Comment
Question by:rtmcmullen
  • 2
  • 2
4 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 24106913
I think you're saying that it would endlessly append *.test.com and you don't want that.

By the way, I'm not a fan of "On Error" statements unless you're actually performing error trapping routines.  I'd suggest removing that or you could mask a problem...


Const NewProxy = "*.test.com"
Dim WSHShell : Set WSHShell = WScript.CreateObject("WScript.Shell")
rtnValue = WSHShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyOverride")
 
If Instr(rtnValue,NewProxy) > 0 Then 
  'value already present.  Do not update rtnValue
Else 'Add value
  If Right(Trim(rtnValue), 1) <> ";" Then rtnValue = rtnValue & ";" 'ensure trailing semicolon
  rtnValue = rtnValue & NewProxy & ";"
  WSHShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyOverride",rtnValue, "REG_SZ"
End If
 
Set WSHShell = Nothing

Open in new window

0
 

Author Closing Comment

by:rtmcmullen
ID: 31568324
Absolutely Perfect!
0
 

Author Comment

by:rtmcmullen
ID: 24106970
Perfect!  Many thanks sirbounty!
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 24106975
Glad I could help - thanx for the grade! :^)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question