Example #1
0
		internal ServiceHelper(string servcieName, string serviceFilename)
		{
			_serviceFilename = serviceFilename;
			_serviceName = servcieName;
			_service = new ServiceController(_serviceName);

			_logger = FileLogger.GetLogger("InstallationLog.txt");
			try
			{
				// actually we need to try access ANY of service properties
				// at least once to trigger an exception
				// not neccessarily its name
				_status = _service.Status;
				_isInstalled = true;
			}
			catch (InvalidOperationException)
			{
				_isInstalled = false;
			}
			

		}
Example #2
0
		static void Main(string[] args)
		{
			try
			{
				using (var serviceHelper = new ServiceHelper("TWAIN@Web", "TwainWeb.Standalone.exe"))
				{

					var parameter = string.Concat(args);
					switch (parameter)
					{
						case "-install":
							if (serviceHelper.Install())
								return;

							Environment.Exit(-1);
							break;
						case "-uninstall":
							if (serviceHelper.Uninstall())
								return;

							Environment.Exit(-1);
							break;
						case "-start":
							serviceHelper.Start();
							return;
						case "-stop":
							serviceHelper.Stop();
							return;
						case "-restart":
							serviceHelper.Restart();
							return;

						case "-run-uninstaller":

							var logger = new FileLogger("InstallationLog.txt");
							try
							{
								var uninstallString = GetUninstallString();

								if (File.Exists(uninstallString))
								{
									var process = new Process {StartInfo = {FileName = uninstallString}};
									process.Start();
									process.WaitForExit();

									var pr = Process.GetProcessesByName("appun-1");
									if (pr.Length > 0)
									{
										pr[0].WaitForExit();
										var exitCode = File.Exists(uninstallString) ? 1 : 0;
										Environment.Exit(exitCode);

									}
								}
							}
							catch (Exception e)
							{
								logger.Error("Error occured while run uninstaller: " + e);
							}

							return;
					}
				}
			}
			catch (Exception e)
			{
				MessageBox.Show(e.ToString());
			}
		}