Solved

Clearing a variable in a VBS script.

Posted on 2008-06-11
2
1,614 Views
Last Modified: 2012-08-14
I plagiarized er, researched this script and it works extremely well except for a problem of reporting the wrong serial number (duplicate)

It creates a CSV text file with two items.

computername,serialnumber

However if a computer isn't going to give me a serial number for any reason it shows the serial number of the previous computer. (it isn't clearing the variable, basically because I don't know how to do that)

Sample output.
computer1,serial1
computer2,serial1
computer3,serial1
computer4,serial4

I've played around with moving the clear variable around, but only succeeded in changing where the error message comes up.

Should I instead persue using a different variable to keep track of the last one and clear it if it's the same?

Hoping I'm just not doing it right,

Chad Helton

On Error Resume Next
set WshShell = WScript.CreateObject("WScript.Shell")
 
'file output
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("C:\Documents and Settings\user\Desktop\serial.txt", True)
 
 
Computers = Array("comp1","comp2","comp3","comp4")
For Each Computer in Computers
winmgmt1 = "winmgmts:{impersonationLevel=impersonate}!//"& Computer &""
'WScript.Echo winmgmt1
Set SNSet = GetObject( winmgmt1 ).InstancesOf ("Win32_BIOS")
for each SN in SNSet
REM	MsgBox "The serial number for the specified computer is: " & Computer & SN.SerialNumber
 
REM a.Writeline (Computer)&","& (SN.SerialNumber)
MsgBox "The serial number for the specified computer is: " & Computer & SN.SerialNumber
 
REM THIS IS WHERE I'VE BEEN PLAYING WITH CLEARING VARIABLES 
SN.SerialNumber = ""
MsgBox "TEST COMPUTER SN" & Computer & SN.SerialNumber
Next
Next

Open in new window

0
Comment
Question by:TechniMemphis
2 Comments
 
LVL 6

Accepted Solution

by:
ysfx earned 250 total points
ID: 21763827
Try inserting before line 13
Set SNSet = nothing

What is the error message you are getting?
0
 

Author Closing Comment

by:TechniMemphis
ID: 31466306
I inserted your line where you asked and it simply skipped over the non-responding computer (I put in a known turned off computername and a computer I'm not an admin on for controls)

Okay, I can't duplicate my original error, but your script worked like a charm. (read: busy with other stuff and can't get back to it)

Take the points and my thanks and run while I scratch my head to figure out what I did earlier?

Thanks!!

Chad

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB Script: create txt file with DateStamp and IP Adress 6 27
Restart service script 5 14
a slight change to the code written by Brad Yundt 2 34
CREATE DATABASE 3 30
Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

820 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