-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
115 lines (96 loc) · 4.25 KB
/
Copy pathMainWindow.xaml.cs
File metadata and controls
115 lines (96 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;
using Microsoft.Win32;
namespace Win10Tweaker
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private static readonly RegistryKey CORTANA_PARENT_KEY = Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Policies").OpenSubKey("Microsoft").OpenSubKey("Windows", true);
private static string CORTANA_KEY_NAME = "Windows Search";
private static string CORTANA_STATE_VALUE_NAME = "AllowCortana";
private static readonly RegistryKey BING_SEARCH_PARENT_KEY = Registry.CurrentUser.OpenSubKey("SOFTWARE").OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Search", true);
private static string[] BING_SEARCH_VALUE_NAMES = { "BingSearchEnabled", "CortanaConsent" };
private static string BING_SEARCH_CORTANA_VALUE_NAME = "DisableWebSearch";
private static int IntFromBool(bool b)
{
return b ? 1 : 0;
}
private static bool CortanaIsEnabled()
{
RegistryKey cortanaParentKey = CORTANA_PARENT_KEY.OpenSubKey(CORTANA_KEY_NAME);
if (cortanaParentKey == null)
return true;
var allowCortana = cortanaParentKey.GetValue(CORTANA_STATE_VALUE_NAME);
if (allowCortana == null)
return true;
return (int)allowCortana == 1;
}
private static void CortanaSetEnabled(bool enabled)
{
RegistryKey cortanaParentKey = CORTANA_PARENT_KEY.OpenSubKey(CORTANA_KEY_NAME, true);
if (cortanaParentKey == null)
cortanaParentKey = CORTANA_PARENT_KEY.CreateSubKey(CORTANA_KEY_NAME);
cortanaParentKey.SetValue(CORTANA_STATE_VALUE_NAME, IntFromBool(enabled), RegistryValueKind.DWord);
}
private static bool BingSearchIsEnabled()
{
foreach (string valueName in BING_SEARCH_VALUE_NAMES)
{
var value = BING_SEARCH_PARENT_KEY.GetValue(valueName);
if (value == null || (int)value == 1)
return true;
}
RegistryKey cortanaParentKey = CORTANA_PARENT_KEY.OpenSubKey(CORTANA_KEY_NAME);
if (cortanaParentKey == null)
return true;
var disableWebSearch = cortanaParentKey.GetValue(BING_SEARCH_CORTANA_VALUE_NAME);
if (disableWebSearch == null || (int)disableWebSearch == 0)
return true;
return false;
}
private static void BingSearchSetEnabled(bool enabled)
{
foreach (string valueName in BING_SEARCH_VALUE_NAMES)
{
BING_SEARCH_PARENT_KEY.SetValue(valueName, IntFromBool(enabled), RegistryValueKind.DWord);
}
RegistryKey cortanaParentKey = CORTANA_PARENT_KEY.OpenSubKey(CORTANA_KEY_NAME, true);
if (cortanaParentKey == null)
return;
cortanaParentKey.SetValue(BING_SEARCH_CORTANA_VALUE_NAME, IntFromBool(!enabled), RegistryValueKind.DWord);
}
public MainWindow()
{
InitializeComponent();
CortanaStateComboBox.SelectedIndex = IntFromBool(CortanaIsEnabled());
BingSearchStateComboBox.SelectedIndex = IntFromBool(BingSearchIsEnabled());
}
private void RestoreDefaultsButton_Click(object sender, RoutedEventArgs e)
{
CortanaStateComboBox.SelectedIndex = 1;
BingSearchStateComboBox.SelectedIndex = 1;
}
private void ApplyButton_Click(object sender, RoutedEventArgs e)
{
CortanaSetEnabled(CortanaStateComboBox.SelectedIndex == 1);
BingSearchSetEnabled(BingSearchStateComboBox.SelectedIndex == 1);
MessageBox.Show("Tweaks applied successfully! Please restart to see effects.");
}
}
}