Solved

vbscript registry append

Posted on 2009-04-08
4
1,423 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

724 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