?
Solved

silent logout in NT 4

Posted on 2001-06-20
6
Medium Priority
?
248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
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…
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 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…

741 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