Launching programs remotely via WMI

Launching programs remotely via WMI

  • Comments 2

One thing that people regularly ask how to do with Virtual Server / Virtual PC is to be able to remotely, programmatically start a program running inside of a virtual machine.  We do not provide anyway to do this directly with our products - however you can do this by using the built in support in Windows.  The following script will open a copy of notepad on a remote computer:

strComputer = "NameOrIPAdressOfVirtualMachine"
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2:Win32_Process")

Error = objWMIService.Create("notepad.exe", null, null, intProcessID)
If Error = 0 Then
    Wscript.Echo "Notepad was started with a process ID of " _
         & intProcessID & "."
Else
    Wscript.Echo "Notepad could not be started due to error " & _
        Error & "."
End If

In order to do this you will need to follow the same network configuration as discussed in this article: http://blogs.msdn.com/virtual_pc_guy/archive/2006/03/02/541124.aspx

Cheers,
Ben

Leave a Comment
  • Please add 6 and 3 and type the answer here:
  • Post
  • Hi, Ben, your work it's great...congratulations

    I'm new with the Virtual PC and the MS environment (I'm a basic Linux user).
    So, maybe my question sound like a dummy-issue :).. anyway..

    ¿ How I can execute this code? Cutting & paste over the Visual Basic ide ? Visual Studio C, c++ ? #C ? .Net ? because from a *.cmd or *.bat impossible.

    Thanks for your help !
    Arturo
    arturo.matos@gmail.com



  • Arturo,

    I'm pretty new to this stuff too, and was also confused at first.  It's just a snippet of VBscript code.

    I'm guessing you'll soon be seeing a lot of these :)
Page 1 of 1 (2 items)