Mohammed Ashraf

Mohammed Ashraf

  • 837
  • 2.1k
  • 402.4k

C# code to shut down remote pc in Lan network

Jan 18 2017 11:48 PM
 Dear All.
 
I tried with following code to shut down remote pc in Lan network. But not working. Can anyone rectify the issue. The code is given belove.
 
public void Shutdown(string strComputerNameInLan)
{
       string shutdownString = @"/c shutdown /s /t 1 -f -m \\" + strComputerNameInLan;
try
{
           ProcessStartInfo psiOpt = new ProcessStartInfo("cmd.exe", shutdownString);
           psiOpt.WorkingDirectory =                 Environment.GetFolderPath(Environment.SpecialFolder.System);
           psiOpt.WindowStyle = ProcessWindowStyle.Hidden;
          psiOpt.RedirectStandardOutput = true;
          psiOpt.UseShellExecute = false;
          psiOpt.CreateNoWindow = true;
          Process procCommand = Process.Start(psiOpt);
          procCommand.WaitForExit();
}
catch (Exception ex)
{
             MessageBox.Show(ex.Message);
}
}
private void button1_Click(object sender, EventArgs e)
{
          Shutdown(textBox1.Text);
}
 

Answers (1)