Solved

Clearing a variable in a VBS script.

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

724 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