1

I have used the following code to shutdown the system but it will perform logoff windows

Private Const EWX_LogOff = 0  
Private Const EWX_SHUTDOWN = 1  
Private Const EWX_REBOOT = 2  
Private Const EWX_FORCE = 4  

Public Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long

Public Sub ShutDownComputer()  
  Call ExitWindowsEx(EWX_FORCE, &HFFFFFFFF)   
End Sub 

3 Answers 3

2

try this

Private Const EWX_POWEROFF = 8 
Call ExitWindowsEx(EWX_POWEROFF, &HFFFFFFFF) 

also this link may help you

Why simply calling ExitWindowsEx won’t Shutdown/Restart the Computer

Sign up to request clarification or add additional context in comments.

2 Comments

While this is correct, you really should say that 8 is EWX_POWEROFF and poweroff might not work on really old machines (Win95/NT4 era)
thanks for your response,I am using above code but still the same problem persists. I am using it in Windows 7
1

Try combining SHUTDOWN with FORCE.

1 Comment

And the reason for this is that FORCE is a flag, the other constants specify which shutdown operation (You could probably combine SHUTDOWN with POWEROFF, otherwise you should only specify one of the "operations")
0

In addition to what Eugene said, its better to use the declaration from pinvoke:

Declare Function ExitWindowsEx Lib "user32" (ByVal dwOptions As Int32, ByVal dwReserved As Int32) As Int32

which declares as arguments two four-bytes integers (as the ExitWindowsEx function in the dll).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.