Solved

using list in vbs

Posted on 2014-10-31
7
212 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
[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
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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Handling case and special names in javascript 3 26
Subtraction v Hex2Dec in vbscript 6 30
MS ACCESS 2010 Clear Form Button 4 63
using vb script 5 52
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
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…

697 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