Solved

Clearing a variable in a VBS script.

Posted on 2008-06-11
2
1,612 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
Comment Utility
Try inserting before line 13
Set SNSet = nothing

What is the error message you are getting?
0
 

Author Closing Comment

by:TechniMemphis
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Welcome to part one of a multi-part tutorial series, VBScript for Windows System Administrators.  The goal of this series is to teach non-programmers how to write useful VBS code to automate their environment, and perform tasks faster, and in a more…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

728 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

10 Experts available now in Live!

Get 1:1 Help Now