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

Why is this NOT working?? 1

Status
Not open for further replies.

BKearan

IS-IT--Management
Sep 27, 2007
45
US
Got a script that goes out to a list of targets and pulls the uninstall registry info... it gets the Uninstall and it's subkeys and returns those fine... BUT, I need to pull DisplayName, DisplayVersion and UninstallString from each subkey.
From everything I've googled and read, the following SHOULD work: (minus all the irrelevant stuff)

Code:
Function RegistryPull(strPCName)
WScript.Echo "Funtion RegistryPull has been called"

Dim objWMIService, Err, objProcess, strShell, objProgram, searchkey
Dim strRem1, subkey, oReg, arrSubKeys, strKeyPath, strValue1, strValue2, strValue3


	On Error Resume Next
	strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
	strValue1 = "DisplayName"
	strValue2 = "DisplayVersion"
	strValue3 = "UninstallString"
	
	Set oReg = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & strPCName & "\root\default:StdRegProv")
	oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
	For Each subkey In arrSubKeys
	On Error Resume Next
	searchkey = strKeyPath & "\" & subkey
	LogFile.Writeline strPCName & "," & searchkey
      oReg.GetStringValue HKEY_LOCAL_MACHINE, searchkey, strValue1, strDisplayName
      oReg.GetStringValue HKEY_LOCAL_MACHINE, searchkey, strValue2, strDisplayVersion
      oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE, searchkey, strValue3, strUninstall
	LogFile.Writeline strDisplayName & "," & strDisplayVersion & "," & strUninstall
	Next

Set objWMIService = Nothing

End Function  'RegistryPull(strPCName)

BUT, it doesn't get the VALUES... HELP!!
 
Add the following code after or before your DIM statements.

Code:
Const HKEY_LOCAL_MACHINE = &H80000002

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
yeah, that is up in the main body of the script... added it to the Function also... but, still not getting the DisplayName or UninstallString. It DOES get the subkeys just fine like it is.
Does it need to re-initialize something? Clear something? Its frustrating because everything seems to SAY it should work... but it does not.
 
If you remove "On Error Resume Next" do you get any errors?

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
.. Doah!
strDisplayName, strDisplayVersion and strUninstall were not defined in the Dim.....

working now... thanks for pointing out the obvious. Glad it was not a poisonous snake.

Now to put in a test... :

Code:
Dim objWMIService, Err, objProcess, strShell, objProgram, searchkey, strDisplayName, strDisplayVersion, strUninstall
Dim strRem1, subkey, oReg, arrSubKeys, strKeyPath, NValueName, VValueName, UValueName, intTest
Const HKEY_LOCAL_MACHINE = &H80000002

	strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" 'The path in the Registry needed to search
	NValueName = "DisplayName"
	VValueName = "DisplayVersion"
	UValueName = "UninstallString"
	
	Set oReg = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & strPCName & "\root\default:StdRegProv")
	oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
	For Each subkey In arrSubKeys
	searchkey = strKeyPath & "\" & subkey
	  oReg.GetStringValue HKEY_LOCAL_MACHINE, searchkey, NValueName, strDisplayName
      oReg.GetStringValue HKEY_LOCAL_MACHINE, searchkey, VValueName, strDisplayVersion
      oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE, searchkey, UValueName, strUninstall
intTest=InStr(strDisplayName,"VPN")
       	If intTest <> 0 and intTest <> "" Then
    	LogFile.Writeline "," & strDisplayName & "," & strDisplayVersion & "," & strUninstall
    	End If
	Next
 
Code:
option explicit
rules OK...

;)

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top