Solved

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

Posted on 2011-03-04
4
674 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
  • 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

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!

Join & Write a Comment

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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