Ejemplo n.º 1
2
		/// <summary>
		/// Public Constructor for WindowsService.
		/// - Put all of your Initialization code here.
		/// </summary>
		public VBoxService()
		{
			this.ServiceName = resources.GetString("Application.Name");
			this.EventLog.Log = "Application";
			this.extradatakey = new StringBuilder(resources.GetString("VBoxService.ExtraDataKey"));
            
			// These Flags set whether or not to handle that specific
			//  type of event. Set to true if you need it, false otherwise.
			this.CanHandlePowerEvent = true;
			this.CanHandleSessionChangeEvent = true;
			this.CanPauseAndContinue = true;
			this.CanShutdown = true;
			this.CanStop = true;
			
			vbox = new VirtualBox.VirtualBox();
			machines = (Array)vbox.Machines;
		}
Ejemplo n.º 2
1
 private void Init()
 {
     EventLog.CreateEventSource("vboxservice", "Application");
     EventLog.Log = "Application";
     EventLog.Source = "vboxservice";
     vb	  = new VirtualBox.VirtualBox();
     ServiceName = SERVICE_NAME;
     CanShutdown = true;
     CanStop     = true;
     Machines    = vb.Machines;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// The Main Thread: This is where the Service is Run.
        /// </summary>
        static void Main(string[] args)
        {
            try {
                VirtualBox.VirtualBox vbx = new VirtualBox.VirtualBox();
            } catch {
                MessageBox.Show("Unable to open Virtualbox DCOM object.\r\nBe sure that Virtualbox is installed!",
                                "DCOM error!",
                                MessageBoxButtons.OK);
                return;
            }
            if (args.Length > 0)
            {
                if (args[0] == "-install")
                {
                    try {
                        System.Configuration.Install.ManagedInstallerClass.InstallHelper(new string[] { "/LogToConsole=false", Assembly.GetExecutingAssembly().Location });
                    } catch {
                        Console.WriteLine("Unable to install server.");
                    }
                }
                else if (args[0] == "-uninstall")
                {
                    try {
                        System.Configuration.Install.ManagedInstallerClass.InstallHelper(new string[] { "/u", "/LogToConsole=false", Assembly.GetExecutingAssembly().Location });
                    } catch {
                        Console.WriteLine("Unable to uninstall server.");
                    }
                }
                else if (args[0] == "-console")
                {
                    //vbx = new VirtualBox.VirtualBox();
                    VBoxService vb = new VBoxService();
                    while (true)
                    {
                        Thread.Sleep(10000);
                    }
                }
                else if (args[0] == "-tray")
                {
                    Console.Title = "VirtualBox Server Service TrayIcon";
#if !DEBUG
                    ShowWindow(ThisConsole, HIDE);
#endif
                    SysTrayIcon systrayicon = new SysTrayIcon();
                    systrayicon.Run();
#if DEBUG
                    ShowWindow(ThisConsole, RESTORE);
#endif
                }
            }
            else
            {
                ServiceBase.Run(new VBoxService());
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Public Constructor for WindowsService.
        /// - Put all of your Initialization code here.
        /// </summary>
        public VBoxService()
        {
            this.ServiceName  = resources.GetString("Application.Name");
            this.EventLog.Log = "Application";
            this.extradatakey = new StringBuilder(resources.GetString("VBoxService.ExtraDataKey"));

            // These Flags set whether or not to handle that specific
            //  type of event. Set to true if you need it, false otherwise.
            this.CanHandlePowerEvent         = true;
            this.CanHandleSessionChangeEvent = true;
            this.CanPauseAndContinue         = true;
            this.CanShutdown = true;
            this.CanStop     = true;

            vbox     = new VirtualBox.VirtualBox();
            machines = (Array)vbox.Machines;
        }
Ejemplo n.º 5
0
        private const int SleepTime = 5 * 1000; // 5s

        public static void Main(string[] args)
        {
            var name = args[0];

            Console.WriteLine("Macine name: " + name);

            IVirtualBox vBox    = new VirtualBox.VirtualBox();
            var         machine = vBox.FindMachine(name);

            Console.WriteLine("Wainting for machine to run...");
            while (machine.State != MachineState.MachineState_Running)
            {
                Console.WriteLine($"Machine state: {machine.State}, waiting...");
                Thread.Sleep(SleepTime);
            }
            Console.WriteLine($"Machine is running - state: {machine.State}.");

            var session = new Session();

            machine.LockMachine(session, LockType.LockType_Shared);

            var console = session.Console;
            var mouse   = console.Mouse;

            Console.WriteLine("Clicking and waiting for shutdown...");

            while (machine.State == MachineState.MachineState_Running)
            {
                try
                {
                    mouse.PutMouseEventAbsolute(625, 440, 0, 0, 1);
                    Thread.Sleep(500);
                    mouse.PutMouseEventAbsolute(625, 440, 0, 0, 0);
                    Thread.Sleep(SleepTime);
                    Console.WriteLine("Clicked.");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Click failed: " + ex.ToString());
                }
            }

            Console.WriteLine($"Done - machine state: {machine.State}.");
        }
Ejemplo n.º 6
0
        private int GetActiveVirtualMachineCount(VirtualBox.VirtualBox virtualBox)
        {
            int activeVMs = 0;

            foreach (IMachine machine in virtualBox.Machines)
            {
                if (
                    machine.State == MachineState.MachineState_Running ||
                    machine.State == MachineState.MachineState_Restoring ||
                    machine.State == MachineState.MachineState_RestoringSnapshot ||
                    machine.State == MachineState.MachineState_LiveSnapshotting ||
                    machine.State == MachineState.MachineState_DeletingSnapshot
                    )
                {
                    activeVMs++;
                }
            }

            return(activeVMs);
        }
Ejemplo n.º 7
0
		/// <summary>
		/// The Main Thread: This is where the Service is Run.
		/// </summary>
		static void Main(string[] args)
		{
			try {
				VirtualBox.VirtualBox vbx = new VirtualBox.VirtualBox();
			} catch {
				MessageBox.Show("Unable to open Virtualbox DCOM object.\r\nBe sure that Virtualbox is installed!",
				           "DCOM error!",
				           MessageBoxButtons.OK);
				return;
			}
			if (args.Length>0) {
				if (args[0] == "-install") {
					try {
						System.Configuration.Install.ManagedInstallerClass.InstallHelper(new string[] { "/LogToConsole=false", Assembly.GetExecutingAssembly().Location }); 
					} catch {
						Console.WriteLine("Unable to install server.");
					}
				} else if (args[0] == "-uninstall") {
					try {
						System.Configuration.Install.ManagedInstallerClass.InstallHelper(new string[] { "/u", "/LogToConsole=false", Assembly.GetExecutingAssembly().Location }); 
					} catch {
						Console.WriteLine("Unable to uninstall server.");
					}
				} else if (args[0] == "-console") {
					//vbx = new VirtualBox.VirtualBox();
					VBoxService vb = new VBoxService();
					while(true) {
						Thread.Sleep(10000);
					}
				} else 	if (args[0] == "-tray") {
						Console.Title = "VirtualBox Server Service TrayIcon";
#if !DEBUG
						ShowWindow(ThisConsole, HIDE);
#endif
						SysTrayIcon systrayicon = new SysTrayIcon();
						systrayicon.Run();
#if DEBUG
						ShowWindow(ThisConsole, RESTORE);
#endif
					}
			} else	{
				ServiceBase.Run(new VBoxService());
			}
		}
Ejemplo n.º 8
0
        public static void Start(IVDController controller)
        {
            //var rrr = Utils.GetAppInfo($"-input tstimgs\\upgradeelibad.png -name upgradegood -match data\\check\\upgradeeligood.png 10000 -name upgradebad -match data\\check\\upgradeelibad.png 10000");
            //SwitchAccount.CheckAccount();
            //TestAccounts(); //TODO DEBUG REMOVE THIS
            //return;
            controller.Log("info", "Starting vm");
            Utils.executeVBoxMngr($"startvm {Utils.vmname}");
            controller.Log("info", "VmStarted, allocate machine");
            var vbox = new VirtualBox.VirtualBox();

            VirtualBox.IMachine machine    = vbox.FindMachine(Utils.vmname);
            VirtualBoxClient    vboxclient = new VirtualBoxClient();
            var session = vboxclient.Session;

            try
            {
                controller.Log("info", "found machine, lock machine");
                machine.LockMachine(session, LockType.LockType_Shared);
                var          console     = session.Console;
                IEventSource es          = console.EventSource;
                var          listener    = es.CreateListener();
                Array        listenTYpes = new VBoxEventType[] { VBoxEventType.VBoxEventType_InputEvent };
                es.RegisterListener(listener, listenTYpes, 0);
                controller.Log("info", "locked machine, entry try");
                try
                {
                    //session.Console.Display.SetSeamlessMode(1);
                    var  display = console.Display;
                    uint sw, sh, bpp;
                    int  xorig, yorig;
                    GuestMonitorStatus gmstat;
                    display.GetScreenResolution(0, out sw, out sh, out bpp, out xorig, out yorig, out gmstat);
                    //Console.WriteLine($"sw={sw} {sh} bpp {bpp} xorig={xorig} yorig={yorig}");

                    byte[] buf = new byte[sw * sh * bpp / 8];
                    //display.TakeScreenShot(0, ref buf[0], sw, sh, BitmapFormat.BitmapFormat_PNG);

                    var mouse    = session.Console.Mouse;
                    var keyboard = session.Console.Keyboard;
                    //MouseMouseTo(mouse, 515, 660);
                    //MouseClick(mouse);
                    //MouseMouseTo(mouse, 360, 156);
                    //MouseClick(mouse);
                    controller.Log("info", "main loop");
                    while (true)
                    {
                        try
                        {
                            checkLoop(new ProcessingContext(mouse, keyboard, controller));
                        } catch (SwitchProcessingActionException)
                        {
                            continue;
                        }
                        break;
                    }
                }
                finally
                {
                    es.UnregisterListener(listener);
                }
            }
            catch (Exception e)
            {
                controller.Log("error", e.ToString());
            }
            finally
            {
                if (session.State == SessionState.SessionState_Locked)
                {
                    session.UnlockMachine();
                }
                controller.Log("info", "powering off");
                Utils.executeVBoxMngr($"controlvm {Utils.vmname} poweroff");
                controller.KillVBox();
                controller.Log("info", "sleeping 10s after kill vbox");
                controller.Sleep(10000);
                controller.Log("info", "vbox killed, poweroff");
            }
            //Console.WriteLine(machine.VideoCaptureWidth);
        }
Ejemplo n.º 9
0
        public void initMachine()
        {
            if (MachineReady.getReadyOffline()) return;
            bool apiok = false;
            try
            {
                vb = new VirtualBox.VirtualBox();
                apiok = true;
            }
            catch (Exception) { }

            if (!apiok)
            {
                OnEvent("Brak API VB !!!", 3);
                return;
            }

            if (VbApiVersion != vb.APIVersion)
            {
                OnEvent("Niezgodna wersja API VB (Oczekiwano: "+VbApiVersion+" dostepna:" + vb.APIVersion + ")", 3);
                return;
            }
            VBVersion = vb.VersionNormalized;
            MachineReady.API = true;
            Session = new Session();

            reInit();

            Program.NL.OnReset += delegate(string auth)
            {
                Packet p = new Packet();
                p.dataIdentifier = Packet.DataIdentifier.Pong;
                p.message = "Resetting";
                Network_Broadcast.send(p);
                this.Restart();
            };
        }