12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using Microsoft.Win32;
- namespace ProcessDaemonTool
- {
- internal class DisableShowErrorUIHelper
- {
- static string WindowsErrorReportingLocalPath = @"SOFTWARE\Microsoft\Windows\Windows Error Reporting";
- static string DontShowUIKey = "DontshowUI";
- static string DisabledKey = "Disabled";
- static string LoggingDisabledKey = "LoggingDisabled";
- static string DontSendAdditionalDataKey = "DontSendAdditionalData";
- private static bool SetLocalMachineRegistryValue(string Keypath,string name,bool value)
- {
- var key = Registry.LocalMachine.OpenSubKey(Keypath, true);
- if (key != null)
- {
- key.SetValue(name, value?0: 1);
- key.Close();
- }
- return GetRegistryValue(Keypath, name);
- }
- private static bool SeCurrentUserRegistryValue(string Keypath, string name, bool value)
- {
- var key = Registry.CurrentUser.OpenSubKey(Keypath, true);
- if (key != null)
- {
- key.SetValue(name, value ? 0 : 1);
- key.Close();
- }
- return GetCurrentUserRegistryValue(Keypath, name);
- }
- private static bool GetRegistryValue(string Keypath, string name)
- {
- bool success=false;
- try
- {
- var key = Registry.LocalMachine.OpenSubKey(Keypath);
- if (key != null)
- {
- success = (int)key.GetValue(name) > 0;
- key.Close();
- }
- }
- catch (System.Exception ex)
- {
- }
-
- return success;
- }
- private static bool GetCurrentUserRegistryValue(string Keypath, string name)
- {
- bool success = false;
- try
- {
- var key = Registry.CurrentUser.OpenSubKey(Keypath);
- if (key != null)
- {
- success = (int)key.GetValue(name) > 0;
- key.Close();
- }
- }
- catch (System.Exception ex)
- {
- }
- return success;
- }
- public static bool SetDontShowUI()
- {
- if (SetLocalMachineRegistryValue(WindowsErrorReportingLocalPath , DontShowUIKey, false) &&
- SetLocalMachineRegistryValue(WindowsErrorReportingLocalPath , DisabledKey, false)&&
- SeCurrentUserRegistryValue(WindowsErrorReportingLocalPath, DontShowUIKey, false) &&
- SeCurrentUserRegistryValue(WindowsErrorReportingLocalPath, DisabledKey, false)
- )
- {
- return true;
- }
- return false;
- }
- }
- }
|