Friday, March 7, 2008

Scheduling a Task to run on a remote server

If you want to set up a scheduled task to execute remote code on another box you can do the following.

Assuming the you have a job server and code server where the executable lives.



Step 1: Create job.bat and job.vbs on the job server
Step 2: Create Scheduled Task to execute job.bat on a regular basis

For more on Scheduling Tasks you can try
http://www.iopus.com/guides/winscheduler.htm or http://www.google.com for more details

The files job.bat and job.vbs will reside on the job server and execute code living on the code server.


On the job server:

You will have a job.bat file to reference the job.vbs file:
"C:\Jobs\job.vbs"


Which will call a job.vbs file:

On Error Resume Next

Dim strComputer
Dim strCommand
Dim strUsername
Dim strPassword

'Configuration of Remote Server Location and credentials
strComputer = "computername"
strUsername = "username"
strPassword = "password"

'Task to execute on remote server
strCommand = """C:\Code\program.exe"""

'Script to execute remote command
ExecuteCommand strComputer,strCommand, strUsername, strPassword

Sub ExecuteCommand(strComputer,strCommand, strUsername, strPassword)

'wscript.echo("Executing " & strCommand & " on " & strComputer)

Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSwbemServices = objSWbemLocator.ConnectServer(strComputer,"root\cimv2", strUsername , strPassword)
Set objSWbemObject = objSWbemServices.Get("win32_Process")

errReturn = objSWbemObject.Create(strCommand,null,null,intProcessID)

'if errReturn = 0 then
' Wscript.Echo strCommand & " was started with a process ID of " & intProcessID & "."
'else
' Wscript.Echo strCommand & " could not be started due to error " & errReturn & "."
'end if

End Sub

1 comment:

Anonymous said...

Can anyone recommend the top Network Monitoring program for a small IT service company like mine? Does anyone use Kaseya.com or GFI.com? How do they compare to these guys I found recently: N-able N-central remote support
? What is your best take in cost vs performance among those three? I need a good advice please... Thanks in advance!