Several days ago I faced with a simple task - I had to execute program (automated QTP test in my case) on several remote computers.
My goal was simple - if I can execute scripts on my computer, then why don't we execute them on remote computers?
I think, this task is very interesting and practical, isn't it? :)
There was one condition. I tried to use "native" Windows solutions, which do not require additional installed software or libraries. I didn't want to use external soft, files, etc.
As a result, I found two solutions. Both of them use WMI:
Running ahead, I will say that I decided in favour of second solution (Win32_ScheduledJob class).
Let's explore these solutions, and compare them.
For clarity, I will show how to execute simple application (notepad.exe) on remote computer.
- Execute program on remote computer with Win32_Process сlass
To create and start new process, I used Create method of the Win32_Process class.
VBScript code is simple enough:
String strComputer = "." means "local computer".
So, the result of notepad starting on my local computer was:
And notepad started on my computer! Great!
Then I tried execute my script on remote computer (I set strComputer = "servername"). The result was:
Script said, that the process was created.
Indeed, process was created. It was shown in Task Manager on remote computer:
But I didn't see it on a desktop of remote computer!
Further investigations shown, that:
For security reasons the Win32_Process.Create method cannot be used to start an interactive process remotely.
Win32_Process class is very useful to create and execute batch tasks on remote computer. But it can be applicable for interactive processes.
That's why I preferred the second way. I mean Win32_ScheduledJob сlass.
- Execute program on remote computer with Win32_ScheduledJob сlass
By analogy, to create and start new process, I used Create method of the Win32_ScheduledJob class.
VBScript code is :
Create method of Win32_ScheduledJob сlass creates new scheduled job on computer. (Hm... Have I said a tautology? :) ) In script I specified the time when scheduled job should be executed - in one minute from now. For that i used standard VBScript function - DateAdd.
Hint: Some time ago I wrote an article abount time/date functions in VBScript. Read it.
The result of execution was excellent! It created scheduled jobs both on local and remote computer.
This is result for remote computer is:
In one minute, the notepad was started and shown on desktop of remote computer!
I was happy :))
I hope, these two methods of remote application execution will be very helpful for you. Computer should calculate, human should think :)
So, I shown how to force your computers to work.
Do you have any ideas on how to force a human to think? :)
If you have to run batch tasks, I think first method (Win32_Process Class) is simpler.
If you have to run interactive programs, use Win32_ScheduledJob Class.