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!

Insert Values into array

Status
Not open for further replies.

Yaik

Programmer
Oct 1, 2010
36
US
I've been trying to, instead of the values been written one after another, to put them all in an array, so I can later call them when needed.

I've been trying to do so, but it has been just a mess with nothing working.

Here is my working VBScript that makes a Software Inventory on the programs you have installed on your computer and then writes it down to a text file.

How can I put them into an array.

Like have an array for sAppName and another one for sAppVer

Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.CreateTextFile(".\SoftInv02.txt")

Const HKCR = &H80000000
Const HKCU = &H80000001
Const HKLM = &H80000002

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


sUninstallPath= "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"

oReg.EnumKey HKLM, sUninstallPath, aSubkeys

	On Error Resume Next
	For Each sSubkey In aSubkeys
	
	   oReg.GetStringValue HKLM, sUninstallPath &"\" &_
	      sSubkey, "DisplayName", sAppName
	
	   oReg.GetStringValue HKLM, sUninstallPath &"\" &_
	      sSubkey, "DisplayVersion", sAppVer

	
	   objFile.Write(sAppName)

	   objFile.WriteLine(sAppVer)

	     

	Next
 
Something like this ?
Code:
Dim aAppName(), aAppVer(), i, j, tmp, objFSO, objFile, oReg, aSubkeys, sSubkey, sUninstallPath
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(".\SoftInv02.txt")
Const HKLM = &H80000002
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
   ".\root\default:StdRegProv")
sUninstallPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
oReg.EnumKey HKLM, sUninstallPath, aSubkeys
i = 0
For Each sSubkey In aSubkeys
  oReg.GetStringValue HKLM, sUninstallPath & "\" & _
     sSubkey, "DisplayName", tmp
  If Not IsNull(tmp) Then
    ReDim Preserve aAppName(i)
    ReDim Preserve aAppVer(i)
    aAppName(i) = tmp
    oReg.GetStringValue HKLM, sUninstallPath & "\" & _
       sSubkey, "DisplayVersion", aAppVer(i)
    i = i + 1
  End If
Next
For j = 0 To i - 1
  objFile.WriteLine aAppName(j) & ", " & aAppVer(j)
Next

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
You are amazing, thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top