?
Solved

silent logout in NT 4

Posted on 2001-06-20
6
Medium Priority
?
252 Views
Last Modified: 2010-04-02
Hi.
I need to force logout from my program on some condition. How can I do it without any questions like "Are you sure you want to logout?" from OS ?
Thank you in advance.
0
Comment
Question by:sisadmin
  • 3
  • 2
6 Comments
 
LVL 5

Accepted Solution

by:
djbusychild earned 400 total points
ID: 6213051
from http://msdn.microsoft.com/library/default.asp?URL=/library/psdk/sysmgmt/shutdown_7z8u.htm

you can do the following


HANDLE hToken;
TOKEN_PRIVILEGES tkp;
 
// Get a token for this process.
 
if (!OpenProcessToken(GetCurrentProcess(),
        TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
    error("OpenProcessToken");
 
// Get the LUID for the shutdown privilege.
 
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
        &tkp.Privileges[0].Luid);
 
tkp.PrivilegeCount = 1;  // one privilege to set    
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
 
// Get the shutdown privilege for this process.
 
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
        (PTOKEN_PRIVILEGES)NULL, 0);
 
// Cannot test the return value of AdjustTokenPrivileges.
 
if (GetLastError() != ERROR_SUCCESS)
    error("AdjustTokenPrivileges");
 
// Shut down the system and force all applications to close.
 
if (!ExitWindowsEx(EWX_LOGOFF | EWX_FORCE, 0))
    error("ExitWindowsEx");


0
 
LVL 5

Expert Comment

by:djbusychild
ID: 6213053
that last comment is misleading, it means to say

// Log off user and force all applications to close
0
 
LVL 1

Author Comment

by:sisadmin
ID: 6213136
Thank you very much.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 22

Expert Comment

by:nietod
ID: 6222847
Does anyone know if this accepted answer was posted as a comment or as an answer?
0
 
LVL 5

Expert Comment

by:djbusychild
ID: 6223065
it was a comment
0
 
LVL 22

Expert Comment

by:nietod
ID: 6224281
Thanks.
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!

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

864 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