Results 1 to 3 of 3

Thread: How to shutdown a PC using VB code.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Location
    Malaysia
    Posts
    69
    How can I put the code that can do the closing application and shutdown Windows 98 chores?

  2. #2
    New Member
    Join Date
    May 2000
    Posts
    10
    Declare Function ExitWindowsEx Lib "user32.dll" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long

    ExitWindowsEx shuts down or reboots the user's computer. Of course, since the shutdown/reboot process will begin once the function is called, there won't normally be much left for your program to do. The function returns 0 if an error occured, or 1 if successful.

    Erez Boym
    Email : [email protected]

  3. #3
    Lively Member
    Join Date
    Apr 2000
    Posts
    110

    Cool This may help

    I am guessing you want to shutdown windows when your program closes... Anyway, the following code works well for me.

    Create a new class file and name it ExitWindows. Put the following code into it.

    Code:
    'ExitWindows.cls
    Option Explicit
    
    Private Declare Function ExitWindowsEx Lib "user32" _
    (ByVal uFlags As Long, ByVal dwReserved As Long) _
    As Long
    
    Private Const EWX_FORCE = 4
    Private Const EWX_LOGOFF = 0
    Private Const EWX_REBOOT = 2
    Private Const EWX_SHUTDOWN = 1
    
    '~~~Shutdown
    Public Sub ShutDown()
        ExitWindowsEx EWX_SHUTDOWN, 0
    End Sub
    
    '~~~Reboot
    Public Sub Reboot()
        ExitWindowsEx EWX_LOGOFF, 0
    End Sub
    
    '~~~Force Shutdown, closes all apps forcefully
    Public Sub Force()
        ExitWindowsEx EWX_FORCE, 0
    End Sub
    
    '~~~Logs the user off
    Public Sub Logoff()
        ExitWindowsEx EWX_LOGOFF, 0
    End Sub
    Next, in your form, use the following:

    Code:
    Dim exw as New ExitWindows
    
    'To shutdown call this
    exw.Shutdown
    
    'To reboot call this
    exw.Reboot
    
    'To forecfully shutdown, call this
    exw.Force
    
    'And to logoff, call this
    exw.Logoff
    Hope this helps...

    Laterz

    REM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width