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 or 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:

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 & "."
' Wscript.Echo strCommand & " could not be started due to error " & errReturn & "."
'end if

End Sub


Natarajaprabhu said...

If you are in need of high paying job just search jobs in India, since in India more companies are emerging with more job openings

Anonymous said...

Can anyone recommend the top Network Monitoring program for a small IT service company like mine? Does anyone use or 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!