Script Tips

Pushing the Envelope

Simple script to push out administrative executables to remote computers.

Here's a quick trick where you can use Windows Script Host 5.6 to push out scripts to a remote computer and have them execute locally on that computer. It's a useful administrative trick!

Say you have a script named C:\Script.vbs on your computer, and you want that computer to be copied to a computer named ClientB and executed. Nothing could be simpler! Just use this code:

Dim oController, oRemote
Set oController = WScript.CreateObject("WSHController")
Set oRemote = oController.CreateScript("c:\Script.vbs", _
   "ClientB")
oRemote.Execute


The oRemote has a Status property that tells you what's going on; to be notified when the remote script has finished, just add this code:

Do While oRemote.Status = 0
   WScript.Sleep 1000
Loop
WScript.Echo "Remote script finished!"

It's that easy. Now you can push out scripts to execute in a distributed fashion (sounds fancy, doesn't it?) and even keep track of when they're finished. It's all built into WSH 5.6 and it only takes a few lines of code to operate!

About the Author

Don Jones has more than a decade of professional experience in the IT industry. He's the author of more than 30 IT books, including Windows PowerShell: TFM; VBScript, WMI, and ADSI Unleashed; Managing Windows with VBScript and WMI; and many more. He's a top-rated and in-demand speaker at conferences such as Microsoft TechEd and TechMentor, and writes the monthly Windows PowerShell column for Microsoft TechNet Magazine. Don is a multiple-year recipient of Microsoft's Most Valuable Professional (MVP) Award with a specialization in Windows PowerShell. Don's broad IT experience includes work in the financial, telecommunications, software, manufacturing, consulting, training, and retail industries and he's one of the rare IT professionals who can not only "cross the line" between administration and software development, but also between IT workers and IT management.

Reader Comments:

Thu, Dec 20, 2007 Anonymous Anonymous

If you are going to post an article like this, could you atleast test it out a bit better... So many things on the internet that claim something but don't hold any water...

Fri, Jun 24, 2005 WH Anonymous

Hi, I am running Windows XP SP2. After the command wscript -regserver, I still get a problem and the error description complains that the system is unavailable. It is sure that the computer name is correct as I can run the same script in a W2k Pro PC. The target is always a W2K Pro PC. Any idea why it does not work on a XP SP2?
Thank you

Fri, Mar 25, 2005 Mike KS

I have the same issue Tom reported. XP Pro SP2 with all hotfixes up to MS05-15. Reinstalled WSH 5.6 just in case. Error is on this line....Set oRemote = oController Char: 1

Wed, Mar 23, 2005 Tom PA

Not able to get script to run... ActiveX Component can't create object .....administrator on all systems....downloaded latest WSH 5.6 etc...Would be great if I could get it to work.

Tue, Mar 22, 2005 Anonymous Anonymous

In the last section of the script, why the code on MSDN lists the "Do While Remote.Status Not Equal 2" and your script has do while status equal 0?

Mon, Mar 21, 2005 jv nj

Windows supports numerous versions of secure shell.

IPSec can be used with various remote utilities from the Resource Kit.

Remote scripting is meant to solve problems that are more complex than just running a WMI script remotely. It can be very useful but should not be used just because it's cool.

SO far no one has come up with a resolution to the DCOM issues that works in all situations but I am sure one exists.

Mon, Mar 21, 2005 Anonymous Anonymous

Lame. Use ssh. Allows secure execution of remote commands without opening holes for script kiddies. Oh, I forgot this is Windows.

Mon, Mar 21, 2005 Anonymous Anonymous

Unfortunately, this will not work as described. The remote computer must have a string value Remote set to 1 in the registry key HKLM-Software-Microsoft-Windows Script Host-Settings (those dashes should be back slashes but it wouldn't accept that character). With that it still probably won't work. You will probably get a "permission denied" error because of DCOM settings.

Mon, Mar 21, 2005 Anonymous Anonymous

Thanks!!

Add Your Comment Now:

Your Name:(optional)
Your Email:(optional)
Your Location:(optional)
Comment:
Please type the letters/numbers you see above