Hi there.
i was wondering if anyone knew how to turn a computer off using Visual Basic. Like a Subroutine what turns the computer off when referred to.
Printable View
Hi there.
i was wondering if anyone knew how to turn a computer off using Visual Basic. Like a Subroutine what turns the computer off when referred to.
VB Code:
Private Declare Function ExitWindowsEx Lib "User32" ( _ ByVal dwOptions As Long, _ ByVal dwReserved As Long) As Long Private Const EWX_SHUTDOWN = 1 Private Const EWX_FORCE = 4 Public Sub ShutDown(Optional blnForce As Boolean) Dim nFlags As Long nFlags = EWX_SHUTDOWN + IIf(blnForce, EWX_FORCE, 0) Call ExitWindowsEx(nFlags, 0&) End Sub
You could also use this command (on XP)
VB Code:
Shut down a server in a controlled manner. TSSHUTDN [wait_time] [/SERVER:servername] [/REBOOT] [/POWERDOWN] [/DELAY:logoffdelay] [/V] wait_time Seconds to wait after user notification before terminating all user sessions (default is 60). /SERVER:servername The server to shut down (default is current). /REBOOT Reboot the server after user sessions are terminated. /POWERDOWN The server will prepare for powering off. /DELAY:logoffdelay Seconds to wait after logging off all connected sessions (default is 30). /V Display information about actions being performed.
You can shut of networked computers this way, also