示例#1
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());
            }
        }
		/// <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());
			}
		}