We help IT Professionals succeed at work.

VBScript to run executable on a number of servers

iptrader
iptrader asked
on
334 Views
Last Modified: 2012-06-27
Hello,

Does anyone have a script that will run an executable quietly on a number of servers in a server list?

Thanks in advance...
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2007

Commented:
What OS?
what type of executable?
You could do something like this with psexec (http://www.microsoft.com/technet/sysinternals/utilities/psexec.mspx)

Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
Dim objShell:Set objShell=CreateObject("Wscript.Shell")

Set objFile=objFSO.OpenTextFile("C:\Servers.txt")

Do while not objFile.AtEndOfStream
  strServer=objFile.ReadLine
  objShell.Run "cmd /c psexec \\" & strServer & " C:\RemoteFile.exe")
Loop

objFile.Close
Set objFSO=Nothing
Set objShell=Nothing

Author

Commented:
Windows Server 2000/2003.

It's a patch. I would rather not invoke another app like psexec due to regulations (has to be approved) but if we have to then we have to.  I want the exe to run quietly and immediately.  It does not require reboot.

Thanks for your help...
CERTIFIED EXPERT
Top Expert 2007

Commented:
Only other method I could think of right now is to determine the local time, and set up a scheduled task via the script to run x number of minutes from 'now' - more complicated if your servers cross time zones...

Author

Commented:
That would actually be perfect.  All our boxes are in the same time zone.

Thanks
CERTIFIED EXPERT
Top Expert 2007

Commented:
http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/taskscheduling/#ScheduleTask.htm details how to create the task...if you get stuck, let me konw - the only obstacle is really converting the time...
NewTime= format(dateadd("n",5,now),"hhnnss")
would get your current time + 5 minutes...


Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
Dim objShell:Set objShell=CreateObject("Wscript.Shell")

Set objFile=objFSO.OpenTextFile("C:\Servers.txt")

Do while not objFile.AtEndOfStream
  strServer=objFile.ReadLine
  Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strServer & "\root\cimv2")
  Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
  errJobCreated = objNewJob.Create ("Notepad.exe", "********" & NewTime & ".000000-420", False, ,, , , JobID)
  Wscript.Echo errJobCreated
Loop

objFile.Close
Set objFSO=Nothing
Set objShell=Nothing

Author

Commented:
sirbounty, the script looks good...can you modify it to run patch.exe from a certain location as part of the scheduled task?  Currently it only creates the task but not specifies the actions of the task correct?

Thanks
CERTIFIED EXPERT
Top Expert 2007

Commented:
any parameters?

Author

Commented:
just quiet switch, that's all
CERTIFIED EXPERT
Top Expert 2007

Commented:
I'm not sure what that is for patch.exe - just a /q?

Does this work? (try with only one system in your text file for testing)


Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
Dim objShell:Set objShell=CreateObject("Wscript.Shell")

Set objFile=objFSO.OpenTextFile("C:\Servers.txt")

Do while not objFile.AtEndOfStream
  strServer=objFile.ReadLine
  Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strServer & "\root\cimv2")
  Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
  errJobCreated = objNewJob.Create ("path.exe", "********" & NewTime & ".000000-420", False, ,, , , JobID)
  Wscript.Echo errJobCreated
Loop

objFile.Close
Set objFSO=Nothing
Set objShell=Nothing

Author

Commented:
Still no link to the executable that needs to run..
CERTIFIED EXPERT
Top Expert 2007

Commented:
Looks like I misspelled it..

errJobCreated = objNewJob.Create ("pacth.exe", "********" & NewTime & ".000000-420", False, ,, , , JobID)

But again, I don't know what switch you're using for a silent install...

Author

Commented:
there is still not path to patch.exe... everything else seems to be in order
CERTIFIED EXPERT
Top Expert 2007

Commented:
Man - I've got to quit drinking, eh?  Still misspelled it...

What's the full path to patch?

errJobCreated = objNewJob.Create ("C:\Windows\System32\patch.exe", "********" & NewTime & ".000000-420", False, ,, , , JobID)

Author

Commented:
\\cogtsx04\utils\patch.exe
CERTIFIED EXPERT
Top Expert 2007

Commented:
So, does this work for you?  I'm not familiar with patch, so I'm not sure how you'd run it silently...

errJobCreated = objNewJob.Create ("\\cogtsx04\utils\patch.exe", "********" & NewTime & ".000000-420", False, ,, , , JobID)

Author

Commented:
type mismatch

Line 10, char 3
CERTIFIED EXPERT
Top Expert 2007

Commented:
Did you add the NewTime?  I made mention of it, but never included it in any version above, apparently...this is for 'run 10 minutes from now'


Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
Dim objShell:Set objShell=CreateObject("Wscript.Shell")
Set objFile=objFSO.OpenTextFile("C:\Servers.txt")
NewTime= format(dateadd("n",10,now),"hhnnss")

Do while not objFile.AtEndOfStream
  strServer=objFile.ReadLine
  Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strServer & "\root\cimv2")
  Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
  errJobCreated = objNewJob.Create ("\\cogtsx04\utils\patch.exe", "********" & NewTime & ".000000-420", False, ,, , , JobID)
  Wscript.Echo errJobCreated
Loop

objFile.Close
Set objFSO=Nothing
Set objShell=Nothing

Author

Commented:
so close :).  it doesn't like format.  I'm trying formatdatetime, still debugging.  Ideas?
CERTIFIED EXPERT
Top Expert 2007
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Sorry about the late reply.  Thanks for your help!
CERTIFIED EXPERT
Top Expert 2007

Commented:
Happy to help - Thanx for the grade! :^ )
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.