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

Need help editing VBS to include reg key/value lookup ..

Status
Not open for further replies.

trytofixalot

Technical User
Jun 28, 2010
8
GB
I have a vbs that initiates a wsus download and installs necessary patches, which works well ..
I need to code an exemption process to prevent the script from running on machines that have a specific reg value (hklm\software\companyname)in the registry. Can anyone give me any help on this pls.. ?
Heres the vbs -

' Exit Codes:
' 0 = scripting failure
' 1 = error obtaining or installing updates
' 2 = installation successful, no further updates to install
' 3 = reboot needed; rerun script after reboot
'
' Note that exit code 0 has to indicate failure because that is what
' is returned if a scripting error is raised.
'

Set updateSession = CreateObject("Microsoft.Update.Session")

Set updateSearcher = updateSession.CreateUpdateSearcher()
Set updateDownloader = updateSession.CreateUpdateDownloader()
Set updateInstaller = updateSession.CreateUpdateInstaller()

Do

WScript.Echo
WScript.Echo "Searching for approved updates ..."
WScript.Echo

Set updateSearch = updateSearcher.Search("IsInstalled=0")

If updateSearch.ResultCode <> 2 Then

WScript.Echo "Search failed with result code", updateSearch.ResultCode
WScript.Quit 1

End If

If updateSearch.Updates.Count = 0 Then

WScript.Echo "There are no updates to install."
WScript.Quit 2

End If

Set updateList = updateSearch.Updates

For I = 0 to updateSearch.Updates.Count - 1

Set update = updateList.Item(I)

WScript.Echo "Update found:", update.Title

Next

WScript.Echo

updateDownloader.Updates = updateList
updateDownloader.Priority = 3

Set downloadResult = updateDownloader.Download()

If downloadResult.ResultCode <> 2 Then

WScript.Echo "Download failed with result code", downloadResult.ResultCode
WScript.Echo

WScript.Quit 1

End If

WScript.Echo "Download complete. Installing updates ..."
WScript.Echo

updateInstaller.Updates = updateList

Set installationResult = updateInstaller.Install()

If installationResult.ResultCode <> 2 Then

WScript.Echo "Installation failed with result code", installationResult.ResultCode

For I = 0 to updateList.Count - 1

Set updateInstallationResult = installationResult.GetUpdateResult(I)
WScript.Echo "Result for " & updateList.Item(I).Title & " is " & installationResult.GetUpdateResult(I).ResultCode

Next

WScript.Quit 1

End If

If installationResult.RebootRequired Then

WScript.Echo "The system must be rebooted to complete installation."

WScript.Quit 3

End If

WScript.Echo "Installation complete."

Loop

 
Perhaps this will be of use: faq329-5864
 

Typically:
Code:
CONST HKLM = &H80000002

strComputer = "."
set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
objReg.GetStringValue HKLM, "software", "companyname", strValue

if (strValue = "foobar") then
    'don't update
else
    'update
end if

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top