Hi Experts,
Have the VBscript below - It should read a list of PC names from a text file - scan each PC for list of software installed and then write to an access db.
Unfortunately I am having problems with the For-Next syntax - it is only scanning the first PC and not going onto the next...
Much appreciate any help!
Here is the script... The database is called Database.mdb and the table is called Software
The text file with the PC List is called AD_PCS_Test.txt and all files are located in D:\Data...
'*** Script Start ***
Option Explicit
' Declare the constants for the database connection
Const adOpenStatic = 3
Const adLockOptimistic = 3
' Declare the variables
Dim sComputer,strComputer,WSHS
hell, ofso, Sys
Dim oNet,oSoftware,objWMIServi
ce,objComp
uter
Dim cnSoftInv, rsData,aComputers, oComputer, oService
Dim colSoftware,sComputerName,
oFile
Dim INPUT_FILE_NAME, Inputfolder, inputfile
Dim colComputers, colRunningServices, colComputer, colItems, colServices
Inputfolder = "D:\Data\"
inputfile = "AD_PCS_Test.txt"
INPUT_FILE_NAME = inputfolder & inputfile
Const FOR_READING = 1
Set ofso = CreateObject("Scripting.Fi
leSystemOb
ject")
Set WSHShell = WScript.CreateObject("WScr
ipt.Shell"
)
Set oFile = ofso.OpenTextFile(INPUT_FI
LE_NAME, FOR_READING)
Set oNet = CreateObject("WScript.Netw
ork")
Set cnSoftInv = CreateObject("ADODB.Connec
tion")
Set rsData = CreateObject("ADODB.Record
set")
cnSoftInv.ConnectionString
= "Provider=Microsoft.Jet.OL
EDB.4.0;" _
& "User ID=Admin;Data Source=D:\Data\Database.md
b"
cnSoftInv.Open
sComputerName = oFile.ReadAll
oFile.Close
aComputers = Split(sComputerName, vbCrLf)
For Each sComputerName In aComputers
Call ServStat
Next
rsData.Close
Set rsData = Nothing
cnSoftInv.Close
Set cnSoftInv = Nothing
'WScript.Quit
'****** Declare Subs ******
Sub ServStat
On Error Resume Next
rsData.Open "software", cnSoftInv, adOpenStatic, adLockOptimistic
strComputer = sComputerName
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper
sonate}!\\
" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery("S
ELECT * FROM Win32_Product")
For Each oSoftware in colSoftware
rsData.AddNew
rsData.Fields("ComputerNam
e").Value = oNet.ComputerName
rsData.Fields("Caption").V
alue = oSoftware.Caption
rsData.Fields("Description
").Value = oSoftware.Description
rsData.Fields("IdNum").Val
ue = oSoftware.IdentifyingNumbe
r
rsData.Fields("InstallLoca
tion").Val
ue = oSoftware.InstallLocation
rsData.Fields("InstallStat
e").Value = oSoftware.InstallState
rsData.Fields("InstallDate
").Value = oSoftware.InstallDate
rsData.Fields("Name").Valu
e = oSoftware.Name
rsData.Fields("PackageCach
e").Value = oSoftware.PackageCache
rsData.Fields("SKUNumber")
.Value = oSoftware.SKUNumber
rsData.Fields("Vendor").Va
lue = oSoftware.Vendor
rsData.Fields("Version").V
alue = oSoftware.Version
rsData.Update
Next
End Sub
'*** End of Script ***
Start Free Trial