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
223 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

11 Experts available now in Live!

Get 1:1 Help Now