Home > Blogs > VIX API Blog


Starting and stopping services inside VMs.

We launched our VI Toolkit for Windows 1.0 a little over a week ago and it’s been a bit of a time sink. Now that I’m looking to direct some attention toward some of the other things I deal with around here, this blog should start looking a bit more lively.

As I mentioned a long time ago in my first post, VIX provides some capabilities that you can’t get through any of our other APIs, specifically the ability to perform some very useful guest operations. In this post I’m going to examine how we can use some of these guest calls to run programs inside of VMs.

In this week’s edition: starting and stopping services with VIX.

This week I’ve got a sample of how you can use VIX to start and restart services inside of VMs. The key APIs here are APIs that let you log into a VM guest and run a program inside the VM guest. Here’s the code I use so you can play along at home. To run this code you’ll need 3 things:

  1. A compatible VMware product to run it against.
  2. A VM with VMware tools installed.
  3. VIX with Perl support. If you want to run this code against ESX like I do, you’ll need VIX 1.5, which you can get from the VMware Server 2.0 Beta or VMware Workstation 6.5 Beta.

The specific example I’ll cover here is that of starting the print service inside a Windows VM running on an ESXi server. Here’s a screenshot of my environment:

Vixshot1_2

Using the script above, here’s the command I can use to start the print spooler.

Vixshot2

Notice that this script requires two logins: first we must log into the host, then we must login to the VM itself to run the program. If you’re running this against a local VMware Workstation or Server, you don’t need to authenticate to the VM host, but you will still need a login to the VM guest. After executing this script, here’s what I see on the command line:

Vixshot3_2

There are some pretty ugly warnings there, but it gets the job done. In addition, we see the output of the command I executed so we know it was successful After hitting F5 in the guest console, here’s the "after" screenshot from the VI Client.

Vixshot4

As you can see, the service is started. Of course the script lets you run arbitrary commands, it’s not really specific to service management, there are a lot of things you can do with it. A few examples would be:

  1. Editing configuration files.
  2. Setting IP addresses on VMs that may not be networked.
  3. Lots, lots more.

Some assembly required.

This example is in Perl for two reasons, 1) It’s possible to run it on either Windows or Linux and 2) I have no idea how to write VB Script. If you’re on Linux, installing the VIX Perl module is fairly straightforward, but if you’re on Windows it can be very tricky since it requires a compilation environment that can be difficult to set up properly. To try to help for Windows users I’ve create an ActiveState PPM module that might work for you if you’re using ActiveState Perl. If anyone tries it, let me know your experiences — good or bad.

6 thoughts on “Starting and stopping services inside VMs.

  1. Wade H.

    Tested this out with your PPM module, works great!

  2. Carter Shanklin

    /me tries not to look surprised 🙂

  3. Nate

    I tried the PPM module and received “ppm install failed: The PPD does not provide code to install for this platform”
    I am using ActiveState Perl 5.10 and I am using VMware Workstation 6.05

  4. Nate

    Sigh…maybe because the ppm file was specifically for 5.8. I changed the architecture name in the ppd file and it worked fine.

  5. Roman

    Any vision for Vmware to create command lets for Vix? If not, I’d be happy to start a project on codeplex for this.

  6. Carter Shanklin

    Hi Roman,
    When the VI Toolkit for Windows 1.5 is released we’ll be able to run scripts with output inside VMs running on ESX and VC. There are caveats, for the first iteration it will assume PowerShell is installed in the guest. Also there will be no file copy support in the first rev.
    There are a couple of thoughts of what to do with the VIX integration. We want to get script execution and copy in/out for all platforms (Windows and Linux). We’ve also considered using VIX to add support for Server and Workstation — we’re not really sure how valuable that is.
    What did you have in mind?
    We have a project on CodePlex, http://codeplex.com/vitoolkitextensions that might be a good starting point for this stuff. I’d love to work with you to get this going.

Comments are closed.