Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Clearing a variable in a VBS script.

Posted on 2008-06-11
2
Medium Priority
?
1,619 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
ysfx earned 1000 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

636 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