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
224 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now