/// <summary> /// StopADFSService method implementation /// </summary> private void StopADFSService() { SvcController ADFSController = null; try { ADFSController = new SvcController("adfssrv"); if ((ADFSController.Status != ServiceControllerStatus.Stopped) && (ADFSController.Status != ServiceControllerStatus.StopPending)) { ADFSController.Stop(); ADFSController.GetStatus(); if (ADFSController.Status != ServiceControllerStatus.Stopped) { ADFSController.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 1, 0)); } } } catch (Exception e) { this.EventLog.WriteEntry("Error Stopping ADFS Service \r" + e.Message, EventLogEntryType.Error, 3); return; } finally { ADFSController.Close(); } }
public void Start() { if (started) { return; } PrinterPrefix = Configuration.PrinterPrefix; printerPermissions = new Dictionary <string, string>(); spooledNativePrinters = new ArrayList(); if (CheckAndInstallPortMonitor()) { if (CheckAndInstallXPSDriver()) { //Correct incase of an improper shutdown RemoveLocalSecurePrinters(); if (TempSpooler.Start()) { Thread changeListeningThread = new Thread(new ThreadStart(MyDLPEP.PrinterUtils.StartBlockingLocalChangeListener)); changeListeningThread.Start(); started = true; Configuration.GetLoggedOnUser(); HandlePrinterConnectionChange(); InstallLocalSecurePrinters(); } else { MyDLPEP.PrinterUtils.listenChanges = false; RemoveLocalSecurePrinters(); } } } if (!started) { SvcController.StartService("Spooler", 5000); } }
public void StartBackground() { lock (MainController.GetInstance()) { //notify logger that we are in main service Logger.GetInstance().InitializeMainLogger(serviceLogger); SvcController.StopMyDLP = new SvcController.StopMyDLPDelegate(Stop); //Keep watchdog tied up during debugging if (System.Environment.UserInteractive == false) { ServiceController service = new ServiceController("mydlpepwatchdog"); try { if (!service.Status.Equals(ServiceControllerStatus.Running) && !service.Status.Equals(ServiceControllerStatus.StartPending)) { Logger.GetInstance().Info("Starting mydlpepwatchdog at start up"); SvcController.StartServiceNonBlocking("mydlpepwatchdog", 10000); Logger.GetInstance().Info("Starting mydlpepwatchdog at start up finished"); } } catch (Exception e) { Logger.GetInstance().Error("Unable to start watchdog" + e); } //enable watchdog check Logger.GetInstance().Info("Watchdog check enabled"); watchdogTimer = new System.Timers.Timer(watchdogTimerPeriod); watchdogTimer.Elapsed += new ElapsedEventHandler(OnTimedWatchdogEvent); watchdogTimer.Enabled = true; } if (Configuration.GetAppConf() == false) { Logger.GetInstance().Error("Unable to get configuration exiting!"); //Environment.Exit(1); } else { //start backend engine Configuration.GetUserConf(); Configuration.StartTime = DateTime.Now; SessionManager.Start(); Engine.GetPhysicalMemory = new Engine.GetPhysicalMemoryDelegate(GetPhysicalMemory); Engine.Start(); Configuration.SetPids(); Logger.GetInstance().Debug("mydlpepwin tries to install mydlpmf"); MyDLPEP.MiniFilterController.GetInstance().Start(); MyDLPEP.FilterListener.getInstance().StartListener(); Logger.GetInstance().Info("mydlpepwin service started"); bool testSuccess = false; for (int i = 0; i < 10; i++) { testSuccess = SeapClient.SeapConnectionTest(); if (testSuccess) { break; } Logger.GetInstance().Debug("Seap connection test attempt:" + i); System.Threading.Thread.Sleep(3000); } if (!testSuccess) { Logger.GetInstance().Error("Seap connection test failed"); Stop(); } if (Configuration.BlockScreenShot) { ScreenShotContoller.Start(); } SessionServer.Start(); if (Configuration.PrinterMonitor) { Service.PrinterController.getInstance().Start(); } if (Configuration.RemovableStorageEncryption) { DiskCryptor.StartDcrypt(); } if (Configuration.UsbSerialAccessControl) { Core.USBController.Activate(); Core.USBController.GetUSBStorages(); } } //initialize configuration timer Logger.GetInstance().Info("Configuration check enabled"); confTimer = new System.Timers.Timer(confCheckTimerPeriod); confTimer.Elapsed += new ElapsedEventHandler(OnTimedConfCheckEvent); confTimer.Enabled = true; Logger.GetInstance().Info("mydlpepwin service started"); } }
private bool CheckAndInstallPortMonitor() { if (MyDLPEP.PrinterUtils.CheckIfPrinterPortExists("MyDLP")) { return(true); } else { try { Logger.GetInstance().Debug("No MyDLP Port found, installing"); SvcController.StopService("Spooler", 10000); //this is ugly but necessary Thread.Sleep(5000); String system32Path = Environment.GetEnvironmentVariable("windir") + @"\\System32"; if (Configuration.GetOs() == Configuration.OsVersion.Win7_64) { system32Path = Environment.GetEnvironmentVariable("windir") + @"\\Sysnative"; } String sourceFile; String sourceUIFile; String destinationFile; String destinationUIFile; Configuration.OsVersion version = Configuration.GetOs(); if (version == Configuration.OsVersion.Win7_32) { sourceFile = System.IO.Path.Combine(Configuration.PrintingDirPath, "mydlpportmon_win7_x86.dll"); sourceUIFile = System.IO.Path.Combine(Configuration.PrintingDirPath, "mydlpportui_win7_x86.dll"); } else if (version == Configuration.OsVersion.Win7_64) { sourceFile = System.IO.Path.Combine(Configuration.PrintingDirPath, "mydlpportmon_win7_x64.dll"); sourceUIFile = System.IO.Path.Combine(Configuration.PrintingDirPath, "mydlpportui_win7_x64.dll"); } else if (version == Configuration.OsVersion.XP) { sourceFile = System.IO.Path.Combine(Configuration.PrintingDirPath, "mydlpportmon_xp_x86.dll"); sourceUIFile = System.IO.Path.Combine(Configuration.PrintingDirPath, "mydlpportui_xp_x86.dll"); } else { Logger.GetInstance().Error("Unknown incompatible windows version"); return(false); } destinationFile = System.IO.Path.Combine(system32Path, "mydlpportmon.dll"); destinationUIFile = System.IO.Path.Combine(system32Path, "mydlpportui.dll"); //Copy files System.IO.File.Copy(sourceFile, destinationFile, true); System.IO.File.Copy(sourceUIFile, destinationUIFile, true); //Set registry for spooler service RegistryKey monitorsKey = Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\Control\Print\Monitors", true); RegistryKey mydlpMonitorKey; RegistryKey mydlpPortsKey; if (HasSubKey(monitorsKey, "MyDLP Port Monitor")) { mydlpMonitorKey = monitorsKey.OpenSubKey("MyDLP Port Monitor", true); } else { mydlpMonitorKey = monitorsKey.CreateSubKey("MyDLP Port Monitor", RegistryKeyPermissionCheck.ReadWriteSubTree); } mydlpMonitorKey.SetValue("Driver", "mydlpportmon.dll", RegistryValueKind.String); if (HasSubKey(mydlpMonitorKey, "Ports")) { mydlpPortsKey = mydlpMonitorKey.OpenSubKey("Ports", true); } else { mydlpPortsKey = mydlpMonitorKey.CreateSubKey("Ports", RegistryKeyPermissionCheck.ReadWriteSubTree); } mydlpPortsKey.SetValue("MyDLP", "", RegistryValueKind.String); SvcController.StartService("Spooler", 5000); Thread.Sleep(1000); Logger.GetInstance().Debug("MyDLP Port installation complete"); return(true); } catch (Exception e) { Logger.GetInstance().Error("Error in install port monitor:" + e); return(false); } } }