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!

reading the registry

Status
Not open for further replies.

WilliamUT

IS-IT--Management
Oct 8, 2002
182
US
Im trying to read the key :

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
this key contains all the installed apps on the computer (in the add/remove programs)...the problem im having is how do i read this whole key into an array?

Thanks!
 
Dim WshShell, retArray, i
Set WshShell = WScript.CreateObject("WScript.Shell")
retArray = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\")
for i = 0 to ubound(retArray)-1
' // do what you want with retArray(i)
next
Water is not bad as long as it stays out human body ;-)
 
What doesn't work ? do you have an error message ? Water is not bad as long as it stays out human body ;-)
 
Dim WshShell, i
Dim retArray

Set WshShell = WScript.CreateObject("WScript.Shell")

retArray = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\")

for i = 0 to ubound(retArray)-1
msgbox retArray(i)
next



error i get is this :

Line : 6
Char : 1
Error: Unable to open the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\UninstallCode : 80070002
Source: WshShell.Regread


This key does exist I have checked it...
 
You can use WMI to access this

This code is located on Technet scripting:


Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile("c:\scripts\software.tsv", True)
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product")
objTextFile.WriteLine "Caption" & vbtab & _
"Description" & vbtab & "Identifying Number" & vbtab & _
"Install Date" & vbtab & "Install Location" & vbtab & _
"Install State" & vbtab & "Name" & vbtab & _
"Package Cache" & vbtab & "SKU Number" & vbtab & "Vendor" & vbtab _
& "Version"
For Each objSoftware in colSoftware
objTextFile.WriteLine objSoftware.Caption & vbtab & _
objSoftware.Description & vbtab & _
objSoftware.IdentifyingNumber & vbtab & _
objSoftware.InstallDate2 & vbtab & _
objSoftware.InstallLocation & vbtab & _
objSoftware.InstallState & vbtab & _
objSoftware.Name & vbtab & _
objSoftware.PackageCache & vbtab & _
objSoftware.SKUNumber & vbtab & _
objSoftware.Vendor & vbtab & _
objSoftware.Version
Next
objTextFile.Close Regards
Steve Friday
 
Only problem with that code steve is that it leaves some applications that were not installed with the windows installer...so it really doesn't solve my problem. Thats why I am trying to resort to the registry
 
try this and see if it gives you what you want

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."


Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

For Each subkey In arrSubKeys
msgbox subkey
Next Regards
Steve Friday
 
here is an amalgamation of them both

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product")

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

For Each subkey In arrSubKeys
If NOT Left(subkey,1) ="{" Then
msgbox subkey
End If
Next

For Each objSoftware in colSoftware
msgbox objSoftware.Caption & vbcrlf & _
objSoftware.Description & vbcrlf & _
objSoftware.IdentifyingNumber & vbcrlf & _
objSoftware.InstallLocation & vbcrlf & _
objSoftware.InstallState & vbcrlf & _
objSoftware.Name & vbcrlf & _
objSoftware.PackageCache & vbcrlf & _
objSoftware.SKUNumber & vbcrlf & _
objSoftware.Vendor & vbcrlf & _
objSoftware.Version
Next Regards
Steve Friday
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top