コード例 #1
0
        private void remote_button_Click(object sender, EventArgs e)
        {
            _parent._RESET_INACTIVITY();
            if (computer_ip.Text.Length > 0)
            {
                try
                {
                    Ping      ping    = new Ping();
                    IPAddress address = IPAddress.Loopback;
                    PingReply reply   = ping.Send(computer_ip.Text);
                    if (reply.Status == IPStatus.Success)
                    {
                        //ping1_text.Text = "Ping: " + reply.RoundtripTime.ToString() + "ms";

                        using (Encrypter ez = new Encrypter())
                        {
                            DialogResult dialogResult = MessageBox.Show("Are you sure you would like to remote to this PC?", "", MessageBoxButtons.YesNo);
                            if (dialogResult == DialogResult.Yes)
                            {
                                string enc_pw         = ez.Decrypt("r?Rqaj¡ wxy").Insert(1, "S").Remove(2, 1);
                                string remote_command = "mstsc /f /v:" + computer_ip.Text;

                                Process rdcProcess = new Process();
                                rdcProcess.StartInfo.FileName  = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\system32\cmdkey.exe");
                                rdcProcess.StartInfo.Arguments = "/generic:TERMSRV/" + computer_ip.Text + " /user:"******" /pass:"******"ADMIN_PASSWORD" ? enc_pw : password.Text);
                                rdcProcess.Start();

                                rdcProcess.StartInfo.FileName  = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\system32\mstsc.exe");
                                rdcProcess.StartInfo.Arguments = "/v " + computer_ip.Text;// ip or name of computer to connect
                                rdcProcess.Start();
                            }
                            else if (dialogResult == DialogResult.No)
                            {
                            }
                        }
                    }
                    else
                    {
                        using (Encrypter ez = new Encrypter())
                        {
                            DialogResult dialogResult = MessageBox.Show("Are you sure you would like to remote to this PC?", "", MessageBoxButtons.YesNo);
                            if (dialogResult == DialogResult.Yes)
                            {
                                string enc_pw         = ez.Decrypt("r?Rqaj¡ wxy").Insert(1, "S").Remove(2, 1);
                                string remote_command = "mstsc /f /v:" + computer_ip.Text;

                                Process rdcProcess = new Process();
                                rdcProcess.StartInfo.FileName  = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\system32\cmdkey.exe");
                                rdcProcess.StartInfo.Arguments = "/generic:TERMSRV/" + computer_ip.Text + " /user:"******" /pass:"******"ADMIN_PASSWORD" ? enc_pw : password.Text);
                                rdcProcess.Start();

                                rdcProcess.StartInfo.FileName  = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\system32\mstsc.exe");
                                rdcProcess.StartInfo.Arguments = "/v " + computer_ip.Text;// ip or name of computer to connect
                                rdcProcess.Start();
                            }
                        }
                        //MessageBox.Show("The IP chosen is unavailable");
                    }
                }
                catch
                {
                    MessageBox.Show("The IP chosen is unavailable");
                }
            }
            else
            {
                MessageBox.Show("Error: Missing IP - Please provide an IP");
            }
        }