Solved

Calling ExitWindows API

Posted on 1998-03-15
5
286 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
ID: 1459134
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
ID: 1459135
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
ID: 1459136
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
ID: 1459137
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
ID: 1459138
Thanks so much, Dalin!  :)
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

809 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