[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 320
  • Last Modified:

Calling ExitWindows API

I'm trying to write a simple login program, which should probably act in the normal way:
1. User logs on
2. If the ID or password is wrong, prompt the user to key in again
3. After 3 tries (or if the user clicks on Cancel), i call the ExitWindows API and get out of Windows and shut down the PC.

The declaration in General/Declaration is:
Private Declare Function ExitWindows Lib "user32" (ByVal dwReserved As Long, ByVal uReturnCode As Long) As Long

The problem is, i don't know what parameters to put in the ExitWindows function.

Can someone help me?  Thanks!!

daphne
0
daphne
Asked:
daphne
  • 2
  • 2
1 Solution
 
DalinCommented:
daphne,
here is my routine, you can just put it in a module, and call it.
Good luck, and best wishes.
Dalin


Const EWX_LOGOFF = 0
Const EWX_REBOOT = 2
Const EWX_SHUTDOWN = 1


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

Sub sShutdownWindow()
ExitWindowsEx EWX_REBOOT, 0
End Sub


0
 
mrmickCommented:
daphne, when you ask a question, you should provide as many details as you can.  At least specify the version of VB and the target OS for the app.  I suspect you're writing this app for NT; if this is the case, the ExitWindows function will not be enough to shut down (or reboot) the computer.

0
 
daphneAuthor Commented:
mrmick: oops... sorry... didn't realize that details like that are important.  i'm writing this for Win95 using VB5.0.

Dalin: what's the difference between ExitWindowsEx and ExitWindows?
0
 
DalinCommented:
daphne, I have not used the ExitWindow function. My understanding on the difference between the two:

ExitWindows() close down any user application and logoff the current user, and leave the machine at the logon screen. It is a micro to call the the ExitWindowEx(0 function using the logoff option. The two parameters are reserved and must be zero.

The ExitWindowEx() is the function doing the actual work.  You can specify whether you wanted to leave it in the login screen like the ExitWindow() does, or Restart the system, or power off.

Regards.
0
 
daphneAuthor Commented:
Thanks so much, Dalin!  :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now