Solved

using list in vbs

Posted on 2014-10-31
7
201 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 32

Assisted Solution

by:Stefan Hoffmann
Stefan Hoffmann earned 20 total points
Comment Utility
Please define "list".
0
 
LVL 1

Author Comment

by:JeffBeall
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

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

Accepted Solution

by:
it_saige earned 240 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks saige for the pickup.
JeffBeall, it will come - stay with it, we all start from the same place. ;^)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 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

11 Experts available now in Live!

Get 1:1 Help Now