Solved

Calling ExitWindows API

Posted on 1998-03-15
5
275 Views
Last Modified: 2008-03-06
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
Comment
Question by:daphne
  • 2
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
Dalin earned 50 total points
Comment Utility
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
 
LVL 8

Expert Comment

by:mrmick
Comment Utility
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
 

Author Comment

by:daphne
Comment Utility
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
 
LVL 9

Expert Comment

by:Dalin
Comment Utility
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
 

Author Comment

by:daphne
Comment Utility
Thanks so much, Dalin!  :)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now