by Nuclear X2 (1 Submission)
Category: Windows System Services
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Fri 24th November 2006
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Use this code to remotely shutdown or restart a computer.
API Declarations
'textbox - txtSeconds
'textbox - txtComments
'comboBox - cboAction
'option - optYes
'option - optNo
'frame with caption: "Force shutdown?"
'command button - cmdGo
'command button - cmdClear
Option Explicit
Private forceShutdown As Boolean
Dim computerName As String, seconds As Integer, comments As String
Dim selected As String, command As String, forced As String
computerName = txtComputerName.Text
seconds = Val(txtSeconds.Text)
selected = Combo1.Text
comments = txtComments.Text
If Not forceShutdown Then
forced = ""
Else
forced = "-f"
End If
' Chr(34) = "
If selected = "Shutdown" Then
command = "shutdown -s " & forced & " -m \\" & computerName & _
" -t " & seconds & " -c " & Chr(34) & comments & Chr(34)
MsgBox command, , ""
Shell (command)
ElseIf selected = "Restart" Then
command = "shutdown -r" & forced & "-m \\" & computerName & _
"-t " & seconds & " -c" & Chr(34) & comments & Chr(34)
Shell command
ElseIf selected = "Logoff" Then
command = "shutdown -l" & forced & "-m \\" & computerName & _
"-t " & seconds & " -c" & Chr(34) & comments & Chr(34)
Shell command
Else
MsgBox "Please select an action!", vbExclamation, ""
End If
End Sub
Private Sub cmdClear_Click()
txtComputerName.Text = ""
txtSeconds.Text = ""
Combo1.Text = "-- Select one --"
txtComments.Text = ""
optYes.Value = False
optNo.Value = True
End Sub
Private Sub optYes_Click()
forceShutdown = True
End Sub
Private Sub optNo_Click()
forceShutdown = False
End Sub