private void RdpConfigDlg_Load(object sender, EventArgs e) { WindowsPrincipal winPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent()); bool isAdmin = winPrincipal.IsInRole(WindowsBuiltInRole.Administrator); if (!isAdmin) { txtRdpPort.Enabled = false; rbOpen.Enabled = false; rbClose.Enabled = false; btnSave.Enabled = false; Text += " (非管理员无法修改)"; } txtRdpPort.Text = RdpHelper.GetRdpPort(); if (RdpHelper.GetRdpStatus()) { rbOpen.Checked = true; } else { rbClose.Checked = true; } }
private void RdpConfig_Click(object sender, EventArgs e) { RdpConfigDlg dlg = new RdpConfigDlg(); if (dlg.ShowDialog() == DialogResult.OK) { if (dlg.RdpPort.ToString() != RdpHelper.GetRdpPort()) { if (RdpHelper.SetRdpPort(dlg.RdpPort)) { MessageBox.Show("RDP 端口修改成功"); } else { MessageBox.Show("RDP 端口修改失败"); } } if (dlg.RdpOpen != RdpHelper.GetRdpStatus()) { RdpHelper.SetRdpStatus(dlg.RdpOpen); MessageBox.Show($"RDP开启状态:{RdpHelper.GetRdpStatus()}"); } } }