Solved

silent logout in NT 4

Posted on 2001-06-20
6
245 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
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

828 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