Solved

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

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

828 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