Click here to Skip to main content
16,019,514 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Delay Windows shutdown Pin
led mike15-Feb-08 5:56
led mike15-Feb-08 5:56 
GeneralRe: Delay Windows shutdown Pin
Mark Salsbery15-Feb-08 6:13
Mark Salsbery15-Feb-08 6:13 
GeneralRe: Delay Windows shutdown Pin
led mike15-Feb-08 6:18
led mike15-Feb-08 6:18 
GeneralRe: Delay Windows shutdown Pin
Mark Salsbery15-Feb-08 6:57
Mark Salsbery15-Feb-08 6:57 
GeneralRe: Delay Windows shutdown Pin
Rajkumar R15-Feb-08 7:04
Rajkumar R15-Feb-08 7:04 
GeneralRe: Delay Windows shutdown Pin
led mike15-Feb-08 7:06
led mike15-Feb-08 7:06 
GeneralRe: Delay Windows shutdown Pin
Mark Salsbery15-Feb-08 7:11
Mark Salsbery15-Feb-08 7:11 
GeneralRe: Delay Windows shutdown Pin
Randor 15-Feb-08 6:06
professional Randor 15-Feb-08 6:06 
AbortSystemShutdown()

http://msdn2.microsoft.com/en-us/library/aa376630(VS.85).aspx[^]

Sample Usage:

BOOL AbortShutdown(LPTSTR lpMachineName)
{
	HANDLE hToken;              // handle to process token 
	TOKEN_PRIVILEGES tkp;       // pointer to token structure 
	 
	BOOL fResult;               // system shutdown flag 

 // Get the current process token handle  so we can get shutdown 
    // privilege. 
	if (!OpenProcessToken(GetCurrentProcess(), 
            TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) 
    {
        TRACE("OpenProcessToken failed.\n"); 
		return false;
    }
 
    // Get the LUID for shutdown privilege. 
     LookupPrivilegeValue(lpMachineName, SE_SHUTDOWN_NAME, 
            &tkp.Privileges[0].Luid); 
 
    tkp.PrivilegeCount = 1;  // one privilege to set    
    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 
 
    // Get 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) 
    {
        TRACE("AdjustTokenPrivileges(setting) enable failed.\n"); 
		return false;
    }
 
    // Prevent the system from shutting down. 
    fResult = AbortSystemShutdown(lpMachineName); 
 
    if (!fResult) 
    { 
        TRACE("AbortSystemShutdown failed.\n"); 
		return false;
    }
	else
		m_bIsShuttingDown = false; // Reset shut down flag
 
    // Disable shutdown privilege. 
    tkp.Privileges[0].Attributes = 0; 
    AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, 
        (PTOKEN_PRIVILEGES) NULL, 0); 
 
    if (GetLastError() != ERROR_SUCCESS) 
    {
        TRACE("AdjustTokenPrivileges(re-setting) disable failed.\n"); 
		return false;
    }
	return true;
}

GeneralRe: Delay Windows shutdown Pin
Mark Salsbery15-Feb-08 6:21
Mark Salsbery15-Feb-08 6:21 
GeneralRe: Delay Windows shutdown Pin
Rajesh R Subramanian15-Feb-08 7:30
professionalRajesh R Subramanian15-Feb-08 7:30 
GeneralRe: Delay Windows shutdown Pin
JudyL_MD15-Feb-08 9:34
JudyL_MD15-Feb-08 9:34 
GeneralRe: Delay Windows shutdown Pin
RoyceF19-Feb-08 4:36
RoyceF19-Feb-08 4:36 
GeneralWH_KEYBOARD_LL Pin
codeinelogic15-Feb-08 3:38
codeinelogic15-Feb-08 3:38 
AnswerRe: WH_KEYBOARD_LL Pin
Rajesh R Subramanian15-Feb-08 3:56
professionalRajesh R Subramanian15-Feb-08 3:56 
GeneralRe: WH_KEYBOARD_LL Pin
David Crow15-Feb-08 4:10
David Crow15-Feb-08 4:10 
GeneralRe: WH_KEYBOARD_LL Pin
codeinelogic16-Feb-08 5:50
codeinelogic16-Feb-08 5:50 
QuestionRe: WH_KEYBOARD_LL Pin
David Crow18-Feb-08 2:32
David Crow18-Feb-08 2:32 
GeneralRedirect the output Pin
bhat15-Feb-08 3:28
bhat15-Feb-08 3:28 
GeneralRe: Redirect the output Pin
led mike15-Feb-08 4:08
led mike15-Feb-08 4:08 
GeneralRe: Redirect the output Pin
David Crow15-Feb-08 4:09
David Crow15-Feb-08 4:09 
QuestionHow to assign/ map Left arrow key to a specific character suppose letter 'L' Pin
Abhijit D. Babar15-Feb-08 2:38
Abhijit D. Babar15-Feb-08 2:38 
AnswerRe: How to assign/ map Left arrow key to a specific character suppose letter 'L' Pin
Rajesh R Subramanian15-Feb-08 2:51
professionalRajesh R Subramanian15-Feb-08 2:51 
AnswerRe: How to assign/ map Left arrow key to a specific character suppose letter 'L' Pin
Maximilien15-Feb-08 2:57
Maximilien15-Feb-08 2:57 
GeneralRe: How to assign/ map Left arrow key to a specific character suppose letter 'L' Pin
Rajesh R Subramanian15-Feb-08 3:42
professionalRajesh R Subramanian15-Feb-08 3:42 
GeneralBackground color of CToolBar. [modified] Pin
Paresh Chitte15-Feb-08 1:24
Paresh Chitte15-Feb-08 1:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.