Custom Search

Thursday, May 3, 2012

How to Execute program on remote computer?


Using below windows calss we can execute any program on remote machine.

1.Win32_Process Class
2.Win32_ScheduledJob Class

1. Win32_Process

strComputer = "10.76.10.202" ' here you should ahnge with your remote machine name
strCommand = "Iexplore.exe"
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objProcess = objWMIService.Get("Win32_Process")
errReturn = objProcess.Create(strCommand, null, null, intProcessID)
If errReturn = 0 Then
   Wscript.Echo "notepad.exe was started with a process ID: " & intProcessID
   Else
   Wscript.Echo "notepad.exe could not be started due to error: " & errReturn
End If

2.Win32_ScheduledJob

strComputer = "10.76.10.202"
strCommand = "iexplore.exe"
Const INTERVAL = "n"
Const MINUTES = 1
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 "notepad.exe was started with a process ID: " & intJobID
Else
Wscript.Echo "notepad.exe could not be started due to error: " & errReturn
End If

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.