tkonan
asked on
Shutting down using Microsoft SDK API doesn't go all the way
Trying to effect a shutdown by software. It has an effect on my 98 system (which otherwise shuts down ok). Have tried other flags but like this, system just goes as far as logging off. Though once (maybe with different flags), got as far as shutting down but then rebooted. Attempting to shutdown only. Here's the core code with flag constants. Last run I got r=0:
-------------------------- ---------- ----------
'Function and Flags from "user32.lib"
'http://msdn2.microsoft.com/en-us/library/aa376868.aspx
'flags as long!?
Private Declare Function ExitWindowsEx Lib "user32" (flags As Integer, reason As Long) As Boolean
Const EWX_LOGOFF As Integer = &H0&
Const EWX_POWEROFF As Integer = &H8&
Const EWX_REBOOT As Integer = &H2&
Const EWX_RESTARTAPPS As Integer = &H40&
Const EWX_SHUTDOWN As Integer = &H1&
Const EWX_FORCE As Integer = 4
Const EWX_FORCEIFHUNG As Integer = &H10&
'************************* ******
'***** Effect the Shutdown *****
'************************* ******
Private Sub cmdDoTheDeed_Click()
Dim r As Boolean
Dim exit_type As Integer
exit_type = EWX_SHUTDOWN
MsgBox ("bye..." + Str$(exit_type) + "")
r = ExitWindowsEx(exit_type, 0)
lblCountdown = Val(r)
'End 'exit program
End Sub
-------------------------- ---------- --
exit_type displayed = 1
microsoft's page gives the main paramater of ExitWindowsEx as an integer but other code on the net shows it as a long. Its supposed to be an unsigned integer but they aren't available in VB6. I'm assuming integer is equal in this case. Interestingly, microsoft list their flags in msdn in 8-digit hex format, i.e. 32-bit, or long format. This has got to be ambiguous surely.
--------------------------
'Function and Flags from "user32.lib"
'http://msdn2.microsoft.com/en-us/library/aa376868.aspx
'flags as long!?
Private Declare Function ExitWindowsEx Lib "user32" (flags As Integer, reason As Long) As Boolean
Const EWX_LOGOFF As Integer = &H0&
Const EWX_POWEROFF As Integer = &H8&
Const EWX_REBOOT As Integer = &H2&
Const EWX_RESTARTAPPS As Integer = &H40&
Const EWX_SHUTDOWN As Integer = &H1&
Const EWX_FORCE As Integer = 4
Const EWX_FORCEIFHUNG As Integer = &H10&
'*************************
'***** Effect the Shutdown *****
'*************************
Private Sub cmdDoTheDeed_Click()
Dim r As Boolean
Dim exit_type As Integer
exit_type = EWX_SHUTDOWN
MsgBox ("bye..." + Str$(exit_type) + "")
r = ExitWindowsEx(exit_type, 0)
lblCountdown = Val(r)
'End 'exit program
End Sub
--------------------------
exit_type displayed = 1
microsoft's page gives the main paramater of ExitWindowsEx as an integer but other code on the net shows it as a long. Its supposed to be an unsigned integer but they aren't available in VB6. I'm assuming integer is equal in this case. Interestingly, microsoft list their flags in msdn in 8-digit hex format, i.e. 32-bit, or long format. This has got to be ambiguous surely.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Can't I wait for someone to give me a modified answer, that I would be better able to comprehend/put to use? Not enough points for that maybe?
ASKER
fine. thanks. brilliant. good plan. maybe even 175 points. 100 fine too. cheers
Forced accept.
modus_operandi
EE Moderator
modus_operandi
EE Moderator
ASKER