Solved

Clearing a variable in a VBS script.

Posted on 2008-06-11
2
1,613 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Unlike scripting languages such as C# where a semi-colon is used to indicate the end of a command, Microsoft's VBScript language relies on line breaks to determine when a command begins and ends. As you can imagine, this quickly results in messy cod…
Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

813 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now