Reputation: 1
I have used C# winform to make a program that I can remote other pc's on and off as well as controlling software. Currently I've done PC ON part and it works well but I'm stuck at PC OFF part right now. I have no problem on running the program but I cannot control other PC by OFF button click. Program reads IP address but I think PC cannot receive data. Is there anything I should add more? Below are my codes.
public partial class Form1 : Form
{
private void PC_OFF_BTN_Click(object sender, EventArgs e)
{
String ipAddress = textBox2.Text.Trim();
if (string.IsNullOrWhiteSpace(ipAddress))
{
MessageBox.Show("유효한 IP 주소를 입력하세요");
return;
}
if (MessageBox.Show("종료?", "YesOrNo", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
MessageBox.Show("Yes");
}
else
{
MessageBox.Show("No");
}
ShutdownRemotePC(ipAddress);
}
private void ShutdownRemotePC(string ipAddress)
{
try
{
string shutdownCommand = $"shutdown /s /3DI \\\\{ipAddress} /t 0";
System.Diagnostics.Process.Start("cmd.exe", shutdownCommand);
ProcessStartInfo processInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = shutdownCommand,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
using (Process process = Process.Start(processInfo))
{
process.WaitForExit();
if (process.ExitCode == 0)
{
MessageBox.Show("전송 완료.");
}
}
}
catch (Exception ex)
{
MessageBox.Show("원격 종료 오류: " + ex.Message);
}
}
}
Upvotes: 0
Views: 60