Input from a text file
- From: "Jeremy Schubert" <jscc-nospam@xxxxxxxxxxx>
- Date: Fri, 1 Jun 2007 20:47:30 -0600
Below, I have posted the part of an inventory script that connects to WMI. Currently I have the script running as a logon GPO. I'd like to change it so I don't have to wait for a user to logon for me to update the inventory. I'd like to be able to connect to each computer remotely. From Microsoft, I got the following that I thought might help. It's not connecting remotely but it's how to read from a text file. Surely, where they say just type the following at the command prompt, they don't mean all the text below. I'm assuming there's been a typo. Can someone help clarify that for me. I'm getting a bit confused with this.
--------------------------------------------------------------------------------
FROM http://www.microsoft.com/technet/scriptcenter/resources/tales/sg1102.mspx#ELDAC
--------------------------------------------------------------------------------
And now here's the script that reads the preceding file. To run this script, you don't need to use any command-line parameters; just type the following at the command prompt and press ENTER:
cscript ListServices.vbs.Const INPUT_FILE_NAME = "C:\Scripts\Computers.txt"
Const FOR_READING = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(INPUT_FILE_NAME, FOR_READING)
strComputers = objFile.ReadAll
objFile.Close
arrComputers = Split(strComputers, vbCrLf)
For Each strComputer In arrComputers
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRunningServices = objWMIService.ExecQuery _
("Select * from Win32_Service")
For Each objService in colRunningServices
Wscript.Echo objService.DisplayName & vbTab & objService.State
Next
Next
--------------------------------------------------------------
PART OF THE INVENTORY CODE
--------------------------------------------------------------
'Change this to the UNC path where inventory files should be created
'Anyone running this script must have read and write access to the
'path.
strInvFilePath = "C:\test\"
'If each user will run this inventory file locally, do not change the value
'of strComputer.
strComputer = "."
'Connect to WMI
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
.
- Follow-Ups:
- Re: Input from a text file
- From: Jeremy
- Re: Input from a text file
- Prev by Date: Re: Trouble with Date String
- Next by Date: Re: auditing
- Previous by thread: Re: Last used value in software
- Next by thread: Re: Input from a text file
- Index(es):
Relevant Pages
|