How do I get system serial number using VB script for list of servers.

Posted on 2006-05-25
Medium Priority
Last Modified: 2008-02-01
I am looking for a quick way to collect serial numbers from Windows 2000 and greater servers using an external host file.

I have a text file that has server names in it. I want to either run a VBS command that will read the text host file, query the server then output to another file the servers name, serial number, model number, then go to the next one until the end of the file.

Also, if it doesn't find the server then put in the words "not online" instead of a serial number.

I have this script that will retrieve the serial number one at a time, but would like something I described above?

On Error Resume Next
Dim System
if Wscript.Arguments.Count >0 then
end if
ComputerName = InputBox("Enter the name of the computer you wish to query")
winmgmt1 = "winmgmts:{impersonationLevel=impersonate}!//"& ComputerName &""
Set SNSet = GetObject( winmgmt1 ).InstancesOf ("Win32_BIOS")
for each SN in SNSet
MsgBox "The serial number for the specified computer is: " & SN.SerialNumber
Question by:mystikal1000
1 Comment
LVL 23

Accepted Solution

basicinstinct earned 2000 total points
ID: 16765634
Code below - change COMPUTER_NAMES_FILE to the file that contains all the computer names.  You didn't specify, so I have assumed a file containing one computername per line, like this:


Change RESULTS_FILE to the location where you want the results output.  The results file will be overwritten each time the script runs.

const FSO_READ_MODE = 1
const FSO_WRITE_MODE = 2
const COMPUTER_NAMES_FILE = "C:\servers.txt"
const RESULTS_FILE = "C:\results.txt" 'warning - will be overwritten each time script runs

Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")

Set fso = Nothing

function CheckSerial(ComputerName)
      Dim System
      Dim retVal
      if Wscript.Arguments.Count > 0 then
      end if
      winmgmt1 = "winmgmts:{impersonationLevel=impersonate}!//"& ComputerName &""
      Set SNSet = GetObject( winmgmt1 ).InstancesOf ("Win32_BIOS")
      for each SN in SNSet
            retVal = retVal & "The serial number for " & ComputerName & " is: " & SN.SerialNumber
      CheckSerial = retVal
end function

function ReadFile(sFilePath)
      If fso.FileExists(sFilePath) then
            'The file exists, so open it and output its contents
            dim file: set file = fso.OpenTextFile(sFilePath, FSO_READ_MODE)
            dim sLine
            dim sResults: sResults = ""
            Do While file.AtEndOfStream = False
                sLine = file.ReadLine
                sResults = sResults & CheckSerial(sLine) & vbcrlf
            Set file = Nothing
            WriteResults sResults
            'The file did not exist
            msgbox sFilePath & " was not found."
      End If
end function

sub WriteResults(sResults)
      dim file: set file = fso.OpenTextFile(RESULTS_FILE, FSO_WRITE_MODE, true)
      Set file = Nothing
end sub

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month15 days, 20 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question