jacob Denis
jacob Denis

Reputation: 51

Trying to shutdown computer remotely in vb.net

Helps master's, here is my coded when i try to shutdown remotely

  Process.Start("shutdown", "-s -m \\COMPUTER NAME")

Then when i executed the program nothing happens.. I think my coded is not correct or i am missing something.

Upvotes: 0

Views: 1880

Answers (1)

FloatingKiwi
FloatingKiwi

Reputation: 4506

The shutdown command can fail for a number of reasons but you're not checking for success. Try this instead and then lookup the error.

    Dim proc = Process.Start("shutdown", "/s /m \\COMPUTER_NAME")
    proc.WaitForExit()
    If proc.ExitCode <> 0 Then
        MsgBox("Failed - Code = " & proc.ExitCode)
    Else
        MsgBox("Success")
    End If

Note: you may need to run your application as an elevated process.


Before testing your application you should test that the command works from the command prompt.

  • Open cmd
  • Run shutdown /s /m \\COMPUTER_NAME
  • Check the output and make sure it worked. I suspect you'll get an access denied error. If so the right click on cmd and choose Launch as administrator. Then repeat this and make sure it works.
  • If this doesn't work then your program wont either. Google shutdown access denied and work through some of the trouble shooting tips.

Upvotes: 3

Related Questions