We help IT Professionals succeed at work.

Shutting down using Microsoft SDK API doesn't go all the way

455 Views
Last Modified: 2013-12-04
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.
Comment
Watch Question

Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Excellent idea JonMny. Still not found time to try Cookre's suggestion...vb6/winapi/conversion from c code is such a slog... also am a tad sceptical about the privileges thing being the issue in win98.

Author

Commented:
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?

Author

Commented:
fine. thanks. brilliant. good plan. maybe even 175 points. 100 fine too. cheers
CERTIFIED EXPERT

Commented:
Forced accept.
modus_operandi
EE Moderator

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.