Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
Medium Priority
?
232 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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

636 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