Results 1 to 8 of 8

Thread: how to use a fuction call to turn off the computer?

  1. #1

    Thread Starter
    Member bamboosam's Avatar
    Join Date
    Feb 2001
    Posts
    61

    Unhappy how to use a fuction call to turn off the computer?

    Does any one can tell me which fuction call in VB can use to turn off the computer, thanks.
    _______________________
    VB 6 professional
    java2 SDK 1.3

  2. #2
    Lively Member
    Join Date
    Apr 2001
    Posts
    64
    Originally from pavan:


    ' In the declararations section
    Const EWX_LOGOFF = 0
    Const EWX_SHUTDOWN = 1
    Const EWX_REBOOT = 2
    Const EWX_FORCE = 4
    Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long


    Private Sub Form_Unload()
    msg = MsgBox("This program is going to reboot your computer. Press OK to continue or Cancel to stop.", vbCritical + vbOKCancel + 256, App.Title)
    If msg = vbCancel Then End
    'reboot the computer
    ret& = ExitWindowsEx(EWX_FORCE Or EWX_REBOOT, 0)
    End Sub


    This code restarts the system

    U can replace EWX_REBOOTwith EWX_SHUTDOWN to shutdown the system

  3. #3
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    Note that code works for 9x - NT you have to call security apis first.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  4. #4
    Megatron
    Guest
    Depending if your computer supports this, you can use EWX_POWEROFF to turn the power off (a complete shutdown).

    Here is the constant.
    VB Code:
    1. Private Const EWX_POWEROFF = &H00000008

  5. #5
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    I haven't had success with the Poweroff on computers that don't support it. I had NT4 boxes that would reboot rather than display "It is now safe to turn off the computer" message.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  6. #6

    Thread Starter
    Member bamboosam's Avatar
    Join Date
    Feb 2001
    Posts
    61

    the code works perfect, but .....

    The code works perfect, but i need a little explanation :
    --------------------------------------------------------------------
    Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
    -------------------------------------------------------------------

    what is "ExitWindowsEx Lib " and "user32"?

    --------------------------------------------------------------------
    ret& = ExitWindowsEx(EWX_FORCE Or EWX_REBOOT, 0)
    ------------------------------------------------------------------------

    why "ret" have to with a "&"?
    and what " EWX_FORCE " ,"EWX_REBOOT","0" these
    parameter's meaning?

    why i can not find any reference in VB about EWX_...?

    How to apply this this stament?
    Private Const EWX_POWEROFF = &H00000008
    just change "Const EWX_SHUTDOWN = 1 " to "Const EWX_SHUTDOWN = &H00000008 " ? or change to "Const EWX_POWEROFF = &H00000008" ?

    thanks
    _______________________
    VB 6 professional
    java2 SDK 1.3

  7. #7
    Megatron
    Guest
    [quote]
    what is "ExitWindowsEx Lib " and "user32"?
    [quote]
    ExitWindowsEx is the function name. User32 is the library it's stored in.

    why "ret" have to with a "&"?
    and what " EWX_FORCE " ,"EWX_REBOOT","0" these
    parameter's meaning?
    Ret& is not needed. You could easily use
    ExitWindowsEx EWX_FORCE Or EWX_REBOOT, 0

    EWX_FORCE and EWX_REBOOT are constants that tell ExitWindowsEx what operation to preform. 0 must be 0 as it is a reserved argument.

    why i can not find any reference in VB about EWX_...?
    Because it's part of the Win32 API. See the API section of this site, or see www.vbapi.com for more information.

    To change to EWX_POWEROFF, modify your code so it looks like this:

    ExitWindowsEx(EWX_FORCE Or EWX_POWEROFF, 0

  8. #8
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    Prague, Czech Republic
    Posts
    350
    what about to try Shell "rundll32 krnl386.exe,exitkernel"

    PS: I think it works only on W9X.
    PS: Save your work first.

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