?
Solved

Visual Studio 2012 - Remote shutdown command not working

Posted on 2014-04-14
2
Medium Priority
?
780 Views
Last Modified: 2014-04-15
I am putting together some code to shutdown or restart a remote PC but it just wont work!

Imports System.Net.NetworkInformation
Imports System.Net
Imports System.Threading
Imports System.Text
Imports System.Diagnostics

Public Class Shutdown

    Private _isNull As Object


    Private Sub Shutdown_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtPCName.Text = Main.txtHostName.Text()
    End Sub

    Private Sub txtPCName_TextChanged(sender As Object, e As EventArgs) Handles txtPCName.TextChanged

    End Sub

    Private Sub btnShutdown_Click(sender As Object, e As EventArgs) Handles btnShutdown.Click

        Dim result = MessageBox.Show("The computer " & txtPCName.Text & "  will be shut down, are you sure you want to do this?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)
        If DialogResult = Windows.Forms.DialogResult.Yes Then
            System.Diagnostics.Process.Start("C:\Windows\System32\shutdown.exe", " /m \\" & txtPCName.Text & " /s /t 10 /d p:0:0")
            Dim result2 = MessageBox.Show("The shutdown command has been sent to " & txtPCName.Text & " and it will shutdown in 10 seconds unless you click Cancel...", "Shutdown Command Sent", MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
            If DialogResult = Windows.Forms.DialogResult.Cancel Then
                System.Diagnostics.Process.Start("C:\Windows\System32\shutdown.exe", " /m \\" & txtPCName.Text & " /a")
            Else

            End If
        ElseIf DialogResult = Windows.Forms.DialogResult.No Then
        End If

    End Sub

    Private Sub btnRestart_Click(sender As Object, e As EventArgs) Handles btnRestart.Click
        Dim result = MessageBox.Show("The computer " & txtPCName.Text & " will be restarted, are you sure you want to do this?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)
        If DialogResult = Windows.Forms.DialogResult.Yes Then
            Process.Start("C:\Windows\System32\shutdown.exe", " /m \\" & txtPCName.Text & " /r /t 10 /d p:0:0")
        ElseIf DialogResult = Windows.Forms.DialogResult.No Then
        End If
    End Sub
End Class

Open in new window


The first message appears with a Yes/No question but then nothing else happens after that and the shutdown command doesnt run.

Can anyone offer some advice?
0
Comment
Question by:fruitloopy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 18

Accepted Solution

by:
dj_alik earned 2000 total points
ID: 40001279
first of all test from command line, may be you need credentials like username or passowrd
if you can do it from command line, read here:
Shutdown a remote computer connected in LAN in any preferable language
http://stackoverflow.com/questions/685528/shutdown-a-remote-computer-connected-in-lan-in-any-preferable-language
0
 
LVL 2

Author Closing Comment

by:fruitloopy
ID: 40001342
I solved it myself in the end. The problem was caused by the line:
"If Dialogresult = "
When it should have read:
"If Result = "

Here's the full code if anyone needs it...

    Private Sub btnShutdown_Click(sender As Object, e As EventArgs) Handles btnShutdown.Click
        Dim Timer As String
        Timer = ComTime.Text
        Dim result = MessageBox.Show("The computer " & txtPCName.Text & " will be shut down, are you sure you want to do this?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)
        If result = Windows.Forms.DialogResult.Yes Then
            System.Diagnostics.Process.Start("C:\Windows\System32\shutdown.exe", " /m \\" & txtPCName.Text & " /s /t " & Timer & " /d p:0:0")
            Dim result2 = MessageBox.Show("The shutdown command has been sent to " & txtPCName.Text & " and it will shutdown in " & Timer & " seconds unless you click Cancel...", "Shutdown Command Sent", MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
            If result2 = Windows.Forms.DialogResult.Cancel Then
                System.Diagnostics.Process.Start("C:\Windows\System32\shutdown.exe", " /m \\" & txtPCName.Text & " /a")
            Else

            End If
        ElseIf result = Windows.Forms.DialogResult.No Then
        End If
    End Sub
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month10 days, 18 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question