Solved

Need to Run VBScript to Read list of servers from a text file

Posted on 2011-03-04
4
680 Views
Last Modified: 2012-05-11
I need to execute the following VBscript on a list of servers that are listed on a text file. Please advise.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colSettings
Wscript.Echo "OS Name: " & objOperatingSystem.Name
Wscript.Echo "Version: " & objOperatingSystem.Version
Wscript.Echo "Service Pack: " & _
objOperatingSystem.ServicePackMajorVersion _
& "." & objOperatingSystem.ServicePackMinorVersion
Wscript.Echo "OS Manufacturer: " & objOperatingSystem.Manufacturer
Wscript.Echo "Windows Directory: " & _
objOperatingSystem.WindowsDirectory
Wscript.Echo "Locale: " & objOperatingSystem.Locale
Wscript.Echo "Available Physical Memory: " & _
objOperatingSystem.FreePhysicalMemory
Wscript.Echo "Total Virtual Memory: " & _
objOperatingSystem.TotalVirtualMemorySize
Wscript.Echo "Available Virtual Memory: " & _
objOperatingSystem.FreeVirtualMemory
Wscript.Echo "OS Name: " & objOperatingSystem.SizeStoredInPagingFiles
Next
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer in colSettings
Wscript.Echo "System Name: " & objComputer.Name
Wscript.Echo "System Manufacturer: " & objComputer.Manufacturer
Wscript.Echo "System Model: " & objComputer.Model
Wscript.Echo "Time Zone: " & objComputer.CurrentTimeZone
Wscript.Echo "Total Physical Memory: " & _
objComputer.TotalPhysicalMemory
Next
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_Processor")
For Each objProcessor in colSettings
Wscript.Echo "System Type: " & objProcessor.Architecture
Wscript.Echo "Processor: " & objProcessor.Description
Next
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_BIOS")
For Each objBIOS in colSettings
Wscript.Echo "BIOS Version: " & objBIOS.Version
Next
0
Comment
Question by:mmoya
[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
  • 2
4 Comments
 
LVL 11

Expert Comment

by:Tasmant
ID: 35037340

Set oFSO = CreateObject("scripting.filesystemobject")
Const ForReading = 1

Path = "c:\servers.txt"

Set ofile = ofso.OpenTextFile(Path,ForReading)

Do Until ofile.AtEndOfStream
	strComputer = ofile.ReadLine
	
	Set objWMIService = GetObject("winmgmts:" _
	& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
	
	Set colSettings = objWMIService.ExecQuery _
	("Select * from Win32_OperatingSystem")
	
	For Each objOperatingSystem in colSettings
		Wscript.Echo "OS Name: " & objOperatingSystem.Name
		Wscript.Echo "Version: " & objOperatingSystem.Version
		Wscript.Echo "Service Pack: " & _
		objOperatingSystem.ServicePackMajorVersion _
		& "." & objOperatingSystem.ServicePackMinorVersion
		Wscript.Echo "OS Manufacturer: " & objOperatingSystem.Manufacturer
		Wscript.Echo "Windows Directory: " & _
		objOperatingSystem.WindowsDirectory
		Wscript.Echo "Locale: " & objOperatingSystem.Locale
		Wscript.Echo "Available Physical Memory: " & _
		objOperatingSystem.FreePhysicalMemory
		Wscript.Echo "Total Virtual Memory: " & _
		objOperatingSystem.TotalVirtualMemorySize
		Wscript.Echo "Available Virtual Memory: " & _
		objOperatingSystem.FreeVirtualMemory
		Wscript.Echo "OS Name: " & objOperatingSystem.SizeStoredInPagingFiles
	Next
	
	Set colSettings = objWMIService.ExecQuery _
	("Select * from Win32_ComputerSystem")
	
	For Each objComputer in colSettings
		Wscript.Echo "System Name: " & objComputer.Name
		Wscript.Echo "System Manufacturer: " & objComputer.Manufacturer
		Wscript.Echo "System Model: " & objComputer.Model
		Wscript.Echo "Time Zone: " & objComputer.CurrentTimeZone
		Wscript.Echo "Total Physical Memory: " & _
		objComputer.TotalPhysicalMemory
	Next
	
	Set colSettings = objWMIService.ExecQuery _
	("Select * from Win32_Processor")
	
	For Each objProcessor in colSettings
		Wscript.Echo "System Type: " & objProcessor.Architecture
		Wscript.Echo "Processor: " & objProcessor.Description
	Next
	
	Set colSettings = objWMIService.ExecQuery _
	("Select * from Win32_BIOS")
	
	For Each objBIOS in colSettings
		Wscript.Echo "BIOS Version: " & objBIOS.Version
	Next
Loop
ofile.Close

Open in new window

0
 

Author Comment

by:mmoya
ID: 35039977
Last question..what about this one? I need to read list of servers from a file and execute this against it.. Thank you.

Option Explicit 'all variables must be defined

Dim oReg, oShell, oFSO
Dim UninstallString, ProductCode
Dim strComputer, colItems, objWMIService, objItem
Dim strKeyPath, subkey, arrSubKeys
strComputer = "."

'********************************
'Enter Product Code Of The Application Here That You Want To Uninstall within the Bracket
ProductCode = "{5B478A76-6432-4296-9668-50FF58CA343B}"

'********************************

' Get scripting objects needed throughout script.
Set oShell = CreateObject("WScript.Shell")

'**************************
UninstallString = "MsiExec.exe /X" & ProductCode & " /qn" & " /norestart"

Const HKEY_LOCAL_MACHINE = &H80000002

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
 
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
 
For Each subkey In arrSubKeys
 
 IF subkey = ProductCode Then
 oShell.Run UninstallString, 1, True
 End If

Next

Set oShell = Nothing
Set oReg = Nothing
'************* End Code ************
0
 

Author Comment

by:mmoya
ID: 35040014
Please disregard the previous one. This is a more efficient way to uninstall an app. Use this instead..Thanks a bunch!

strApplicationName = "MSN Messenger 6.1"

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery("Select * From Win32_Product Where Name = '" & strApplicationName & "'")

For Each objSoftware in colSoftware
objSoftware.Uninstall()
Next
0
 
LVL 11

Accepted Solution

by:
Tasmant earned 500 total points
ID: 35055498

Set oFSO = CreateObject("scripting.filesystemobject")
Const ForReading = 1

strApplicationName = "MSN Messenger 6.1"
strPath = "c:\servers.txt"

Set ofile = ofso.OpenTextFile(strPath,ForReading)

Do Until ofile.AtEndOfStream
	strComputer = ofile.ReadLine
	
	Set objWMIService = GetObject("winmgmts:" _
	& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
	Set colSoftware = objWMIService.ExecQuery("Select * From Win32_Product Where Name = '" & strApplicationName & "'")
	
	For Each objSoftware in colSoftware
		objSoftware.Uninstall()
	Next
Loop

Open in new window

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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