Solved

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

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

729 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