Solved

using list in vbs

Posted on 2014-10-31
7
209 Views
Last Modified: 2014-10-31
I got the following script from a different question on EE, which shows the version of internet explorer on the computer you run the script on. If I change strComputer = "." to strComputer = "remotecomputername" it works great to show the version on a remote pc as well.

Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Internet Explorer"
strValueName = "Version"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
Wscript.Echo "Installed IE Version: " & strValue & VBCRLF & "IE Version: " & Left(strValue,1)

it works great, but now I would like to use a list of computers and have the script run on each computer name in the list, then output the results to a file, so that is would have something like,

computer1 = ie8
computer2 = ie10

I have been googleing this but I think I'm too new to scripting, and haven't been able to figure it out. So would this be hard to do, meaning it isn't just adding a few more lines to the script.
0
Comment
Question by:JeffBeall
7 Comments
 
LVL 33

Assisted Solution

by:ste5an
ste5an earned 20 total points
ID: 40416331
Please define "list".
0
 
LVL 1

Author Comment

by:JeffBeall
ID: 40416352
well, I have a list of computers I need to know the version of IE that is installed on them. I could make it a text document, an excel document, or whatever would work. I just thought it would be something like

computer1
computer2
computer3

and so on.
0
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 240 total points
ID: 40416389
Try this...
Const HKEY_LOCAL_MACHINE = &H80000002

Dim objFSO : Set objFSO = CreateObject

("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("c:\PCs.txt")
Set objOut = objFSO.CreateTextFile("C:\PC_IEVer.txt")

Do while not objFile.AtEndOfStream
  strComputer = objFile.ReadLine
  Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
  strKeyPath = "SOFTWARE\Microsoft\Internet Explorer"
  strValueName = "Version"
  oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
  objOut.WriteLine "Installed IE Version on " & strComputer & ": " & strValue & VBCRLF & "IE Version: " & Left(strValue,1)
Loop

objFile.Close
objOut.Close

Open in new window

0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 1

Author Comment

by:JeffBeall
ID: 40416473
thank you sirbounty, however, two things about this.
1st, our policies at work don't allow me to create files directly on C, so I changed
Set objFile = objFSO.OpenTextFile("c:\pcs\PCs.txt")
to
Set objFile = objFSO.OpenTextFile("c:\pcs\pcs\PCs.txt")
and created a folder call pcs on the root of C. So if that is okay, then the other thing is, when I run the script it errors with

Script: C:\users\d01jbeaje02\Desktop\IEVersion2.vbs
Line:     5
Char:    1
Error:    Expected Statement
Code:    800A0400
Source:  Microsoft VBScript compilation error

any ideas why this is happening?
0
 
LVL 33

Accepted Solution

by:
it_saige earned 240 total points
ID: 40416481
Somehow in sirbounty's copy/paste flurry, the scripting object parameters got separated from the declaration.

With your changes and a combining line 3 and line 5
Const HKEY_LOCAL_MACHINE = &H80000002

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile("c:\pcs\PCs.txt")
Set objOut = objFSO.CreateTextFile("C:\pcs\PC_IEVer.txt")

Do while not objFile.AtEndOfStream
  strComputer = objFile.ReadLine
  Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
  strKeyPath = "SOFTWARE\Microsoft\Internet Explorer"
  strValueName = "Version"
  oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
  objOut.WriteLine "Installed IE Version on " & strComputer & ": " & strValue & VBCRLF & "IE Version: " & Left(strValue,1)
Loop

objFile.Close
objOut.Close

Open in new window


-saige-
0
 
LVL 1

Author Closing Comment

by:JeffBeall
ID: 40416514
Wow! you guys are good! I wish I knew how to script. It's hard to be new and see how far I have to go.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 40416791
Thanks saige for the pickup.
JeffBeall, it will come - stay with it, we all start from the same place. ;^)
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Macro Excel - Multiple If conditions 2 72
Example unit tests with AngularJS 3 45
Run a .bat file wich is inside a .vbs file 8 38
Batch file or script with password 22 44
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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 …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

770 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