Solved

Is it possible to have a WMI script create and write a vbs script on a remote computer then run it

Posted on 2011-03-21
3
227 Views
Last Modified: 2012-05-11
Is it possible to have a WMI script create and write a vbs script on a remote computer then run it. Purpose of this script is to monitor virtual desktop environments. We would like to eliminate any network drive dependence to get the vbs file.
0
Comment
Question by:williamfl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Expert Comment

by:virtualmess
ID: 35183976
If I was going to do this, I'd most likely do it through a combination of VBScript and the Microsoft Sysinternals PSEXEC utility.  Attached is a (tested and working in my environment) sample VBScript which:

Takes as input a PC name.
Generates a customized DOS batch script based on the PC name.
Copies the generated script to the remote machine.
Uses PSEXEC to run the script on the remote machine.

In theory, you could replace the code to generate the script with code to generate a VBScript, PowerShell script, etc.  

Running the attached script with administrator credentials (on both the source and target machines), it worked without error going from a Windows XP SP3 box on a Windows domain to another Windows XP system on the same domain.

Your mileage may vary but this should get you pretty close.

expdemo.vbs
0
 
LVL 6

Expert Comment

by:Lee_YCP
ID: 35184114
You should note that PSEXEC may be stripped by AntiVirus based on your settings and end up with a file that copies to the destination, but contains 0KB data and hence does not run.
0
 
LVL 1

Accepted Solution

by:
virtualmess earned 500 total points
ID: 35184865
If you really want to stick with JUST WMI, this example would work also.  It was interesting to figure out a way to sneak a text file onto a remote machine (none of the examples I found would quite do it).

The attached example uses the vanilla DOS "echo" command to create a script line-by-line on the target machine, then runs it using WMI.  Since the echo command treats certain characters as "special", the script has to "clean up" the lines of code before transmitting them, or the echo command will garble them.

Still, this is a WMI-only example of how to do what you are looking for.  I've only tested it with simple DOS examples, but I see no reason it couldn't pipe a VBScript, Perl Script, or PowerShell script to the remote machine using the same method.  It might require the cleanup routine to be modified, but that should be about it.

wmitest.vbs
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question