Advertisement

01.05.2006 at 09:16AM PST, ID: 21685367
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.2

Need help with a VB Script using WMI scanning text file list of PCs and writing to Access Database

Asked by thegordo in Visual Basic Programming, VB Script

Tags: , , , ,

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,WSHShell, ofso, Sys
Dim oNet,oSoftware,objWMIService,objComputer
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.FileSystemObject")
Set WSHShell = WScript.CreateObject("WScript.Shell")      
Set oFile = ofso.OpenTextFile(INPUT_FILE_NAME, FOR_READING)
Set oNet = CreateObject("WScript.Network")
Set cnSoftInv = CreateObject("ADODB.Connection")
Set rsData = CreateObject("ADODB.Recordset")

cnSoftInv.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "User ID=Admin;Data Source=D:\Data\Database.mdb"

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=impersonate}!\\" & strComputer & "\root\cimv2")
          
      Set colSoftware = objWMIService.ExecQuery("SELECT * FROM Win32_Product")            
                        
      For Each oSoftware in colSoftware
      
      rsData.AddNew
      
       rsData.Fields("ComputerName").Value = oNet.ComputerName
       rsData.Fields("Caption").Value = oSoftware.Caption
        rsData.Fields("Description").Value = oSoftware.Description
        rsData.Fields("IdNum").Value = oSoftware.IdentifyingNumber
        rsData.Fields("InstallLocation").Value = oSoftware.InstallLocation
        rsData.Fields("InstallState").Value = oSoftware.InstallState
        rsData.Fields("InstallDate").Value = oSoftware.InstallDate
        rsData.Fields("Name").Value = oSoftware.Name
        rsData.Fields("PackageCache").Value = oSoftware.PackageCache
        rsData.Fields("SKUNumber").Value = oSoftware.SKUNumber
        rsData.Fields("Vendor").Value = oSoftware.Vendor
        rsData.Fields("Version").Value = oSoftware.Version        
        
        rsData.Update

Next
      
End Sub

'*** End of Script ***Start Free Trial
[+][-]01.05.2006 at 09:57AM PST, ID: 15620803

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.05.2006 at 10:07AM PST, ID: 15620929

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.05.2006 at 12:12PM PST, ID: 15622377

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.05.2006 at 12:55PM PST, ID: 15622804

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.06.2006 at 02:26AM PST, ID: 15627405

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.06.2006 at 08:45AM PST, ID: 15630458

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Visual Basic Programming, VB Script
Tags: win32_product, wmi, connect, installlocation, list
Sign Up Now!
Solution Provided By: JesterToo
Participating Experts: 4
Solution Grade: A
 
 
[+][-]01.06.2006 at 01:40PM PST, ID: 15633622

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.09.2006 at 02:47AM PST, ID: 15647509

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.09.2006 at 10:12AM PST, ID: 15652235

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32