stefan

EDIT: wrong forum. New here...Shoudl have been in C# code repository - sorry, Please move it fellows...

This is a very sloppy contribution, I guess I could have given you more exact info on the

sdk

 s - but I am so busy coding these days...

not sure if this is "too" basic for this rather impressive forum either but here I go

I have VMWare server setup - one one of those virtual boxes I run Tor/Privoxy. On the host I have a few apps running at occasions. However, automation is king, so I want those apps to check if that VMWare virtual

mac

 hine isn't running I need the app to start it up automagically.

1. I use C#

2. There is a

SDK

  API for VMWare. Active X controls. To be honest I am not sure (was a month ago or so) if I did download something from
http://www.vmware.com/download/

sdk

 /
or of files are always there after installing VMWare server:
CApplauserogram filesVMwareVMware VmCOM Scripting APIVmCOM.dll is the file you should reference

3. I have created a VM called TorPrivoxy which is what we want to check if running - and if not, then fire it up

4. Now for the code

using System;
using System.Collections.Generic;
using System.Text;
using VMCOMLib;

namespace ControlPanelJobs
{
    public class EnsureProxy
    {
        public static void Ensure()
        {
            VmConnectParams vmConn = new VmConnectParams();

            vmConn.Hostname = "localhost";
            vmConn.Username = "administrator";
            vmConn.Password = "foobaradminpassword";



            VmServerCtl vmSrvCtl;

            vmSrvCtl = new VmServerCtl();
            vmSrvCtl.Connect(vmConn);
            foreach (string s in vmSrvCtl.RegisteredVmNames)
            {
                if (s.IndexOf("TorPrivoxy"Applause>= 0 )
                {
                    VmCtl vm = new VmCtl();
                    vm.Connect(vmConn, s);
                    if (vm.ExecutionState != VmExecutionState.vmExecutionState_On)
                    {
                        vm.Start(VmPowerOpMode.vmPowerOpMode_TrySoft);
                        System.Threading.Thread.Sleep(60 * 1000);
                    }

                }
            }


        }



    }
}





I am not sure if it's possible to check when it's up - I guess one single way is just check if the proxy is indeed available , but this one is easy - waiting 60 seconds IS enough and I have no hurry in these cases.
You need to change the admin name and password of course.

For non C#ers - there ARE

Perl

  API:s as well.

The main reason for me needing this is I have found myself - when disturbed by a customer on phone etc - I sometimes (without knowing it) click around my open windows - and it has happened I closed the whole virtual

mac

 hine down...


Perkiset's Place Home   Politics @ Perkiset's