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

List of Softwares installed using VBScript

Status
Not open for further replies.

jambai

Programmer
Mar 21, 2007
58
US
When I use the below function to get the list of installed software in a computer, I am getting the product name as "?[" or some other junk character when the DisplayName is empty in the registery

Code:
Private Function GetAddRemove(sComp) As String

  Dim cnt, oReg, sBaseKey, iRC, aSubKeys, iPN, ix
  Dim sCompName As String
  
  Const HKEY_LOCAL_MACHINE = &H80000002  'HKEY_LOCAL_MACHINE
  Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
              sComp & "/root/default:StdRegProv")
  sBaseKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
iRC = oReg.EnumKey(HKEY_LOCAL_MACHINE, sBaseKey, aSubKeys)
  Dim sKey, sValue, sTmp, sVersion, sDateValue, sYr, sMth, sDay, sPublisher, psValue
  
    Dim db As Database
    Dim rs As DAO.Recordset
    
    Set db = CurrentDb
    Set rs = db.OpenRecordset("SWI")
    
    Dim strDeviceID, strProductName As String
  For Each sKey In aSubKeys
  On Error Resume Next
      [COLOR=red]iRC = oReg.GetStringValue(HKEY_LOCAL_MACHINE, sBaseKey & sKey, "DisplayName", sValue)[/color]
    iPN = oReg.GetStringValue(HKEY_LOCAL_MACHINE, sBaseKey & sKey, "Publisher", sPublisher)
    If iRC <> 0 Then
      oReg.GetStringValue HKEY_LOCAL_MACHINE, sBaseKey & sKey, "QuietDisplayName", sValue
    End If
	''Code to insert the values into DB   
    cnt = cnt + 1
    End If
  Next
End Function

Any help is appreciated.

Thanks
Jambai
 
Your code compares a string to an integer, crap is expected, especially with OERN. Also, set iRC to an empty string before using it.

Code:
  For Each sKey In aSubKeys
  [s]On Error Resume Next[/s]
    [red]iRC = ""[/red]
    iRC = oReg.GetStringValue(HKEY_LOCAL_MACHINE, sBaseKey & sKey, "DisplayName", sValue)
    iPN = oReg.GetStringValue(HKEY_LOCAL_MACHINE, sBaseKey & sKey, "Publisher", sPublisher)
    If [red]len(iRC)[/red] <> 0 Then
      oReg.GetStringValue HKEY_LOCAL_MACHINE, sBaseKey & sKey, "QuietDisplayName", sValue
    End If
    ''Code to insert the values into DB   
    cnt = cnt + 1
    End If
  Next

-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
 
Oops, Nevermind. I misread your code. Clear sValue before using it.

sValue = ""
iRC = oReg.GetStringValue(HKEY_LOCAL_MACHINE, sBaseKey & sKey, "DisplayName", sValue)

-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
 

Thanks for your suggestion.

But I am clearing the values (svalue,sPublisher, etc.,) after inserting into database.

When I run this code today I am getting the display name as "?b?[&o". Yesterday it was like "?["
 
It's looks like classic memory garbage. With OERN on, oReg.GetStringValue will return what is currently in memory at the if DisplayName is not found. Clear them regardless of whether or not they were added to the DB.

-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