Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running a program on multiple remote machines

Status
Not open for further replies.

combie81

Technical User
Jul 28, 2011
2
GB
Hi all,

I'm trying to run the below script on multiple machines over the network. It should run an auditing program on each machine that is in computers.txt list. The text file has 1 PC name per line. It works PERFECTLY when ran on a single PC, even a remopte one, however I just cannot get it to read from the txt file and run on multiple PC's. Any help or pointers as to where exactly I'm going wrong would be great as I'm fairly new to VB and this problem has been getting to me for over a week now. I'd like to perform the task this way as it'll save me having to remotely connect to each PC/go to each PC/kick a user off whilst I do this.

Many thanks, Steven

Code:
On Error Resume Next

Set objGetComputerList = CreateObject("Scripting.FileSystemObject")
Set fsoReadComputerList = objGetComputerList.OpenTextFile("computers.txt", 1, TristateFalse)
aryComputers = Split(fsoReadComputerList.ReadAll, vbCrLf)
fsoReadComputerList.Close
    
For Each strComputer In aryTasks

'*******************************************
'Single PC
'strComputer = "."


Const INTERVAL = "n"
Const MINUTES = 1

strCommand = "C:\WinAudit.exe /r=gso"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objScheduledJob = objWMIService.Get("Win32_ScheduledJob")
Set objSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")

objSWbemDateTime.SetVarDate(DateAdd(INTERVAL, MINUTES, Now()))
errReturn = objScheduledJob.Create(strCommand, objSWbemDateTime.Value, False, 0, 0, True, intJobID)

If errReturn = 0 Then
Wscript.Echo "WinAudit was started with a process ID: " & intJobID
Else
Wscript.Echo "WinAudit could not be started due to error: " & errReturn
End If
'*******************************************
Next
 
Replace this:
For Each strComputer In aryTasks
with this:
For Each strComputer In aryComputers

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for your help - Silly mistake on my part. Sadly that wasn't part of my problem though!!

After correcting this I realised I'd made a VERY stupid error - I had named the computer list file "computer.txt" - so the actual name was "conmputers.txt.txt" - I fogot thought I already had file extensions showing!! A silly mistake I shall be more wary of in the future!!!

Again thank's for pointing out my other error though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top