private void Application_Startup(object sender, StartupEventArgs e) { ExitCode = 0; StartupArgs = e.Args; WasLocalSettingReset = false; TemposDesktop = null; IsAppShuttingDown = false; IsUsingDesktop = false; Current.SessionEnding += Current_SessionEnding; // Set the current directory to the application path // So we don't start-up in the \windows\System32\ folder at windows login try { //System.IO.Directory.SetCurrentDirectory( // System.IO.Path.GetDirectoryName(VistaSecurity.GetExecutablePath()) //); System.IO.Directory.SetCurrentDirectory( System.IO.Path.GetDirectoryName(ResourceAssembly.Location) ); } catch (Exception ex) { // Ignore, since the original app was in the currect folder, so should // the app on the alternate desktop. //MessageBox.Show(ex.Message); } #if DEBUG if (SpecialStart.IsEnabled) { LocalSetting.Initialize(); SpecialStart.Start(); Process.GetCurrentProcess().Kill(); return; } #endif if ((e.Args.Length == 1) && e.Args[0].Equals("/INSTALLTMA")) { bool isDone = false; LocalSetting.Initialize(); TaskManagerServiceHelper.InstallFailed += (o, args) => { ExitCode = -1 * TaskManagerServiceHelper.FailCode; isDone = true; }; TaskManagerServiceHelper.Installed += (o, args) => { TaskManagerServiceHelper.Start(); }; TaskManagerServiceHelper.StartFailed += (o, args) => { ExitCode = -2; isDone = true; }; TaskManagerServiceHelper.Started += (o, args) => { isDone = true; }; TaskManagerServiceHelper.Install(); while (!isDone) { Thread.Sleep(300); } Current.Shutdown(); return; } if ((e.Args.Length == 1) && e.Args[0].Equals("/UNINSTALLTMA")) { bool isDone = false; LocalSetting.Initialize(); TaskManagerServiceHelper.UninstallFailed += (o, args) => { ExitCode = -1; isDone = true; }; TaskManagerServiceHelper.Uninstalled += (o, args) => { isDone = true; }; TaskManagerServiceHelper.Uninstall(); while (!isDone) { Thread.Sleep(300); } Current.Shutdown(); return; } if ((e.Args.Length == 1) && e.Args[0].Equals("/STARTTMA")) { bool isDone = false; LocalSetting.Initialize(); TaskManagerServiceHelper.StartFailed += (o, args) => { ExitCode = -1; isDone = true; }; TaskManagerServiceHelper.Started += (o, args) => { isDone = true; }; TaskManagerServiceHelper.Start(); while (!isDone) { Thread.Sleep(300); } Current.Shutdown(); return; } if ((e.Args.Length == 1) && e.Args[0].Equals("/STOPTMA")) { bool isDone = false; LocalSetting.Initialize(); TaskManagerServiceHelper.StopFailed += (o, args) => { ExitCode = -1; isDone = true; }; TaskManagerServiceHelper.Stopped += (o, args) => { isDone = true; }; TaskManagerServiceHelper.Stop(); while (!isDone) { Thread.Sleep(300); } Current.Shutdown(); return; } if ((e.Args.Length == 1) && e.Args[0].Equals("/STOPSQL")) { LocalSetting.Initialize(); if (ServiceHelper.IsSqlServiceRunningLocally) { ServiceHelper.StopSqlService(20000); } if (ServiceHelper.IsSqlBrowserServiceRunningLocally) { ServiceHelper.StopSqlBrowserService(20000); } Thread.Sleep(1000); Process.GetCurrentProcess().Kill(); return; } if ((e.Args.Length == 1) && e.Args[0].Equals("/STARTSQL")) { LocalSetting.Initialize(); if (!ServiceHelper.IsSqlBrowserServiceRunningLocally && !string.IsNullOrEmpty(LocalSetting.DatabaseServerLoginName)) { ServiceHelper.StartSqlBrowserService(20000); } if (!ServiceHelper.IsSqlServiceRunningLocally) { ServiceHelper.StartSqlService(20000); } Thread.Sleep(1000); Process.GetCurrentProcess().Kill(); return; } // Initialize Local Settings WasLocalSettingReset = LocalSetting.Initialize(); // Some old LocalSettings file doesn't have LocalSetting.Values.Boolean in it, old if (LocalSetting.Values.Boolean == null) { LocalSetting.Reset(); LocalSetting.Update(); } string desktopName = Desktop.GetDesktopName(); if (desktopName != null) { if (LocalSetting.Values.Boolean["KioskMode"] && desktopName.Contains("Default")) { // Relaunch application on the TemposDesktop { TemposDesktop = Desktop.CreateDesktop("TemposDesktop"); try { Process protectedProcess = TemposDesktop.CreateProcess(ResourceAssembly.Location); TemposDesktop.Show(); protectedProcess.WaitForExit(); //TemposDesktop.Close(false); } catch (Exception ex) { if (TemposDesktop != null) { TemposDesktop.Close(); } MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace); } Current.Shutdown(); return; } } if (desktopName.Contains("TemposDesktop")) { IsUsingDesktop = true; TemposDesktop = Desktop.GetCurrent(); } } if (((desktopName == null) || desktopName.Contains("Default")) && ((e.Args.Length != 1) || !e.Args[0].ToUpper().Equals("/RESTART"))) { if (!IsOnlyProcess()) { Process.GetCurrentProcess().Kill(); return; } } #if !DEMO Updater.RemoveUpdateDirectory(); #else // Just show the Strings.SystemSettings dialog and exit if (Keyboard.GetKeyStates(Key.LeftCtrl) != KeyStates.Down) { return; } StartupWindow.PromptForConnectionString(true); Process.GetCurrentProcess().Kill(); #endif }