private void IsSysDns_Checked(object sender, RoutedEventArgs e) { if (new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator)) { SysDnsSet.SetDns("127.0.0.1", DnsSettings.SecondDnsIp.ToString()); Snackbar.MessageQueue.Enqueue(new TextBlock() { Text = "主DNS:" + IPAddress.Loopback + Environment.NewLine + "辅DNS:" + DnsSettings.SecondDnsIp }); IsSysDns.ToolTip = "已设为系统 DNS"; } else { var snackbarMsg = new SnackbarMessage() { Content = "权限不足", ActionContent = "Administrator权限运行", }; snackbarMsg.ActionClick += RunAsAdmin_OnActionClick; Snackbar.MessageQueue.Enqueue(snackbarMsg); IsSysDns.IsChecked = false; } }
private void IsSysDns_OnClick(object sender, RoutedEventArgs e) { try { if (MyTools.IsNslookupLocDns()) { if (new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator)) { SysDnsSet.ResetDns(); Snackbar.MessageQueue.Enqueue(new TextBlock { Text = "已将 DNS 重置为自动获取" }); } else { SysDnsSet.ResetDnsCmd(); Snackbar.MessageQueue.Enqueue(new TextBlock { Text = "已通过 Netsh 将 DNS 重置为自动获取" }); } IsSysDns.ToolTip = "设为系统 DNS"; IsSysDns.IsChecked = false; } else { if (new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole( WindowsBuiltInRole.Administrator)) { SysDnsSet.SetDns(IPAddress.Loopback.ToString(), DnsSettings.SecondDnsIp.ToString()); IsSysDns.ToolTip = "已设为系统 DNS"; } else { SysDnsSet.SetDnsCmd(IPAddress.Loopback.ToString(), DnsSettings.SecondDnsIp.ToString()); Snackbar.MessageQueue.Enqueue(new TextBlock { Text = "已通过 Netsh 设为系统 DNS" }); } Snackbar.MessageQueue.Enqueue(new TextBlock { Text = "主DNS:" + IPAddress.Loopback + Environment.NewLine + "辅DNS:" + DnsSettings.SecondDnsIp }); IsSysDns.ToolTip = "已设为系统 DNS"; IsSysDns.IsChecked = true; } } catch (Exception exception) { MessageBox.Show(exception.ToString()); } }
private void IsSysDns_Checked(object sender, RoutedEventArgs e) { if (new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator)) { SysDnsSet.SetDns("127.0.0.1", DnsSettings.SecondDnsIp.ToString()); } else { SysDnsSet.SetDnsCmd("127.0.0.1", DnsSettings.SecondDnsIp.ToString()); Snackbar.MessageQueue.Enqueue(new TextBlock() { Text = "已通过 Netsh 设置" }); } IsSysDns.ToolTip = "已设为系统 DNS"; Snackbar.MessageQueue.Enqueue(new TextBlock() { Text = "主DNS:" + IPAddress.Loopback + Environment.NewLine + "辅DNS:" + DnsSettings.SecondDnsIp }); }