Solved

silent logout in NT 4

Posted on 2001-06-20
6
243 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 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you very much.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 22

Expert Comment

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

Expert Comment

by:djbusychild
Comment Utility
it was a comment
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
Thanks.
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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

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