private void button1_Click(object sender, EventArgs e) { string address = remoteConnectionAddressCB.Text; string username = remoteUsernameTB.Text; string password = remotePasswordTB.Text; string filename = rdpFileNameTB.Text.Trim() + ".rdp"; remoteConnectionAddressCB.Items.Add(address); var TemplateStr = RDPdemo.Properties.Resources.TemplateRDP; var pwstr = BitConverter.ToString(DataProtection.ProtectData(Encoding.Unicode.GetBytes(password), "")); pwstr = pwstr.Replace("-", ""); var NewStr = TemplateStr.Replace("{#address}", address).Replace("{#username}", username).Replace("{#password}", pwstr); StreamWriter sw = new StreamWriter(filename); sw.Write(NewStr); sw.Close(); ProcCmd(filename); }
private void button1_Click(object sender, EventArgs e) { string address = AddressComboBox.Text; string username = UsernameTextBox.Text; string password = PasswordTextBox.Text; string filename = NameTextBox.Text.Trim() + ".rdp"; AddressComboBox.Items.Add(address); var TemplateStr = RDPdemo.Properties.Resources.TemplateRDP;//获取RDP模板字符串 //用DataProtection加密密码,并转化成二进制字符串 var pwstr = BitConverter.ToString(DataProtection.ProtectData(Encoding.Unicode.GetBytes(password), "")); pwstr = pwstr.Replace("-", ""); //替换模板里面的关键字符串,生成当前的drp字符串 var NewStr = TemplateStr.Replace("{#address}", address).Replace("{#username}", username).Replace("{#password}", pwstr); //将drp保存到文件,并放在程序目录下,等待使用 StreamWriter sw = new StreamWriter(filename); sw.Write(NewStr); sw.Close(); //利用CMD命令调用MSTSC ProcCmd("mstsc " + filename); }