/// <summary> /// Called whenever the app is shut down with an authorized key, or when the system is /// shutting down, or when the user is logging off. /// </summary> /// <param name="installSafeguards"> /// Indicates whether or not safeguards should be put in place when we exit the application /// here. Safeguards means that we're going to do all that we can to ensure that our function /// is not bypassed, and that we're going to be forced to run again. /// </param> private void DoCleanShutdown(bool installSafeguards) { // No matter what, ensure that all GUI instances for all users are // immediately shut down, because we, the service, are shutting down. lock (m_cleanShutdownLock) { if (!m_cleanShutdownComplete) { try { // Pull our critical status. CriticalKernelProcessUtility.SetMyProcessAsNonKernelCritical(); } catch (Exception e) { LoggerUtil.RecursivelyLogException(m_logger, e); } if (installSafeguards) { try { // Ensure we're automatically running at startup. var scProcNfo = new ProcessStartInfo("sc.exe"); scProcNfo.UseShellExecute = false; scProcNfo.WindowStyle = ProcessWindowStyle.Hidden; scProcNfo.Arguments = "config \"FilterServiceProvider\" start= auto"; Process.Start(scProcNfo).WaitForExit(); } catch (Exception e) { LoggerUtil.RecursivelyLogException(m_logger, e); } try { var cfg = m_provider.PolicyConfiguration.Configuration; if (cfg != null && cfg.BlockInternet) { // While we're here, let's disable the internet so that the user // can't browse the web without us. Only do this of course if configured. try { WFPUtility.DisableInternet(); } catch { } } } catch (Exception e) { LoggerUtil.RecursivelyLogException(m_logger, e); } } else { // Means that our user got a granted deactivation request, or installed but // never activated. m_logger.Info("Shutting down without safeguards."); } // Flag that clean shutdown was completed already. m_cleanShutdownComplete = true; } } }
public void DisableInternet() { m_logger.Info("Disabling internet."); WFPUtility.DisableInternet(); }