|
-
Jul 10th, 2001, 10:12 AM
#1
Thread Starter
Member
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
-
Jul 10th, 2001, 10:15 AM
#2
Lively Member
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
-
Jul 10th, 2001, 10:26 AM
#3
Black Cat
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.
-
Jul 10th, 2001, 10:26 AM
#4
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:
Private Const EWX_POWEROFF = &H00000008
-
Jul 10th, 2001, 10:47 AM
#5
Black Cat
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.
-
Jul 10th, 2001, 10:51 AM
#6
Thread Starter
Member
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
-
Jul 10th, 2001, 11:04 AM
#7
[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
-
Jul 10th, 2001, 11:15 AM
#8
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|