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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

scipt to change registry settings in 5 areas

Status
Not open for further replies.

slickyboi

Programmer
Oct 16, 2003
29
0
0
US
Hi all,

I'm not very good with vbs, and I found a script that will work for me.. It checks to see if a registry setting is set if not it writes in the values needed. But I need to do this in different areas within the registry. Is there an easier way to write this in one script instead of having 5 separate vbs files.. Basically I need this script to change the default IE setting in 5 different places within the registry...

Sub AWASetIE_HKCU_Start()
' Test and set IE to standard
Set WshShell = Wscript.CreateObject("Wscript.Shell")
If Not WshShell.RegRead("HKCU\Software\Microsoft\Internet Explorer\Main\Start Page")=" then
WSHShell.RegWrite "HKCU\Software\Microsoft\Internet Explorer\Main\Start Page","End If
End Sub
Call AWASetIE_HKCU_Start()


Sub AWASetIE_HKU_Start()
Set WshShell = Wscript.CreateObject("Wscript.Shell")
If Not Wshshell.RegRead("HKU\.DEFAULT\Software\Microsoft\Internet Explorer\Main\Start Page")=" then
WSHShell.RegWrite "HKU\.DEFAULT\Software\Microsoft\Internet Explorer\Main\Start Page","End If
End Sub
Call AWASetIE_HKU_Start()


Sub AWASetIE_HKU_Default()
Set WshShell = Wscript.CreateObject("Wscript.Shell")
If Not Wshshell.RegRead("HKU\.DEFAULT\Software\Microsoft\Internet Explorer\Main\Default_Page_URL")=" then
WSHShell.RegWrite "HKU\.DEFAULT\Software\Microsoft\Internet Explorer\Main\Default_Page_URL","End If
End Sub
Call AWASetIE_HKU_Default()


Sub AWASetIE_HKLM_Start()
Set WshShell = Wscript.CreateObject("Wscript.Shell")
If Not Wshshell.RegRead("HKLM\Software\Microsoft\Internet Explorer\Main\Start Page")=" then
WSHShell.RegWrite "HKLM\Software\Microsoft\Internet Explorer\Main\Start Page","End If
End Sub
Call AWASetIE_HKLM_Start()


Sub AWASetIE_HKLM_Default()
Set WshShell = Wscript.CreateObject("Wscript.Shell")
If Not Wshshell.RegRead("HKLM\Software\Microsoft\Internet Explorer\Main\Default_Page_URL")=" then
WSHShell.RegWrite "HKLM\Software\Microsoft\Internet Explorer\Main\Default_Page_URL","End If
End Sub
Call AWASetIE_HKLM_Default()
 
Hello slickyboi,

You can store the setting full path valuename/value pair in a dictionary and make a sub processing the check & write. But, array is more easy to visualize (everytime I use dictionary, I need to consult documentation to remind me some detail). Also, since your value for each valuename entry is the same, you can do simply just set up an array of valuename and a string variable for the value. Here is a remodelling of your code (off-hand).
Code:
dim sValue, aName, iret
sValue=&quot;[URL unfurl="true"]http://my.portal.com/communities/community.asp?Communit...;&quot;[/URL]  '<<<make it right here
aName=array( _
    &quot;HKCU\Software\Microsoft\Internet Explorer\Main\Start Page&quot;), _
    &quot;HKLM\Software\Microsoft\Internet Explorer\Main\Start Page&quot;, _
    &quot;HKU\.DEFAULT\Software\Microsoft\Internet Explorer\Main\Default_Page_URL&quot;, _
    &quot;HKLM\Software\Microsoft\Internet Explorer\Main\Start Page&quot;, _
    &quot;HKLM\Software\Microsoft\Internet Explorer\Main\Default_Page_URL&quot;)

for each sName in aName
     iret=postsetting(sName, sValue)
     if iret<>0 then
        wscript.echo &quot;Valuename&quot; & sName & &quot; not found. Posting failed.&quot;
     end if
next

function postsetting(sX, sY)
    dim wsh
    set wsh=createobject(&quot;wscript.shell&quot;)
    on error resume next
    if not wsh.regread(sX)=sY then
        wsh.regwrite sX, sY
    end if
    set wsh=nothing
    postsetting=err.number
    err.clear
    on error goto 0
end function
regards - tsuji
 
Hi tsuji,

Thanks for helping me out. I went ahead and created a vbs for it and I received an error Microsoft VBScript Compilation error.I think I must be missing something
 
slickyboi,

I look again my posting. My mistake in cut & paste lines from your original script. It is the first element of the array aName where a parenthesis (&quot;)&quot;) should not be there. My bad. So replace the setting of aName, like this:
Code:
aName=array( _
    &quot;HKCU\Software\Microsoft\Internet Explorer\Main\Start Page&quot;, _
    &quot;HKLM\Software\Microsoft\Internet Explorer\Main\Start Page&quot;, _
    &quot;HKU\.DEFAULT\Software\Microsoft\Internet Explorer\Main\Default_Page_URL&quot;, _
    &quot;HKLM\Software\Microsoft\Internet Explorer\Main\Start Page&quot;, _
    &quot;HKLM\Software\Microsoft\Internet Explorer\Main\Default_Page_URL&quot;)
regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top