[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Visual Studio 2012 - Remote shutdown command not working

Posted on 2014-04-14
2
Medium Priority
?
791 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

656 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