Click here to Skip to main content
15,916,379 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralStatic library and dialog box Pin
Liobsynde9-Apr-04 9:00
Liobsynde9-Apr-04 9:00 
GeneralRe: Static library and dialog box Pin
Prakash Nadar9-Apr-04 9:11
Prakash Nadar9-Apr-04 9:11 
GeneralRe: Static library and dialog box Pin
Liobsynde9-Apr-04 9:28
Liobsynde9-Apr-04 9:28 
GeneralRe: Static library and dialog box Pin
Prakash Nadar9-Apr-04 9:41
Prakash Nadar9-Apr-04 9:41 
GeneralRe: Static library and dialog box Pin
Liobsynde9-Apr-04 9:57
Liobsynde9-Apr-04 9:57 
GeneralRe: Static library and dialog box Pin
Prakash Nadar9-Apr-04 15:05
Prakash Nadar9-Apr-04 15:05 
GeneralRe: Static library and dialog box Pin
Ravi Bhavnani9-Apr-04 9:23
professionalRavi Bhavnani9-Apr-04 9:23 
GeneralShutting Down when not Logged on Pin
reymano9-Apr-04 8:33
reymano9-Apr-04 8:33 
I want to shut down my computer at a certain time of the day, so I wrote a small program that calls InitiateSystemShutdownEx() and scheduled it using the Task Scheduler. The program works whenever I'm logged in on my computer. However when I'm logged off (i.e. the computer displays the welcome or logon screen), the shutdown doesn't occur. The scheduler does show that the program was executed, so I'm guessing it might have something to do with security.

Here's a section of the code:

if (!mode)  //shutdown<br />
{<br />
    HANDLE procHnd, tokHnd;<br />
<br />
    procHnd = GetCurrentProcess();<br />
    if (!OpenProcessToken(procHnd,TOKEN_ADJUST_PRIVILEGES,&tokHnd))<br />
	return;<br />
<br />
    TOKEN_PRIVILEGES tp;<br />
    LUID luid;<br />
<br />
    if (!LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &luid))<br />
        return; <br />
<br />
    tp.PrivilegeCount = 1;<br />
    tp.Privileges[0].Luid = luid;<br />
    tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;<br />
<br />
    AdjustTokenPrivileges(tokHnd, FALSE, &tp, 0, NULL, 0); <br />
<br />
//  ExitWindowsEx(EWX_POWEROFF | EWX_FORCEIFHUNG, 0);<br />
    InitiateSystemShutdownEx(NULL, NULL, 15, TRUE, FALSE, SHTDN_REASON_FLAG_PLANNED);<br />
<br />
}<br />
else if (mode == 1) // standby<br />
    SetSuspendState(FALSE,TRUE,FALSE);<br />
else if (mode == 2) // hibernate<br />
    SetSuspendState(TRUE,TRUE,FALSE);


I tried using ExitWindowsEx() but have the same problem. However, hibernating does work when I'm logged off.

I'm puzzled Confused | :confused:
reymano
GeneralRe: Shutting Down when not Logged on Pin
avenger_sb2510-Apr-04 17:45
avenger_sb2510-Apr-04 17:45 
GeneralRe: Shutting Down when not Logged on Pin
reymano11-Apr-04 3:10
reymano11-Apr-04 3:10 
GeneralDisplay Items on Active Desktop Pin
microcyb9-Apr-04 7:58
microcyb9-Apr-04 7:58 
General&quot;Cl.exe - No Disk&quot; Pin
Matthew Fleming9-Apr-04 6:53
Matthew Fleming9-Apr-04 6:53 
GeneralRe: "Cl.exe - No Disk" Pin
Andrew Lawrence9-Feb-10 12:07
Andrew Lawrence9-Feb-10 12:07 
GeneralCapturing Resing of Window event Pin
Adi Narayana9-Apr-04 6:44
Adi Narayana9-Apr-04 6:44 
GeneralRe: Capturing Resing of Window event Pin
Ravi Bhavnani9-Apr-04 6:56
professionalRavi Bhavnani9-Apr-04 6:56 
GeneralRe: Capturing Resing of Window event Pin
Michael Dunn9-Apr-04 15:00
sitebuilderMichael Dunn9-Apr-04 15:00 
GeneralRe: Capturing Resing of Window event Pin
Adi Narayana10-Apr-04 1:53
Adi Narayana10-Apr-04 1:53 
GeneralShell Extension ....ICopyHook Interface Pin
ZarrinPour9-Apr-04 4:28
ZarrinPour9-Apr-04 4:28 
GeneralHiding Application from task list Pin
Anonymous9-Apr-04 4:02
Anonymous9-Apr-04 4:02 
GeneralRe: Hiding Application from task list Pin
2249179-Apr-04 4:28
2249179-Apr-04 4:28 
GeneralRe: Hiding Application from task list Pin
Prakash Nadar9-Apr-04 7:51
Prakash Nadar9-Apr-04 7:51 
GeneralRe: Hiding Application from task list Pin
Anonymous9-Apr-04 7:58
Anonymous9-Apr-04 7:58 
GeneralRe: Hiding Application from task list Pin
Prakash Nadar9-Apr-04 8:23
Prakash Nadar9-Apr-04 8:23 
GeneralRe: Hiding Application from task list Pin
Anonymous9-Apr-04 9:09
Anonymous9-Apr-04 9:09 
GeneralRe: Hiding Application from task list Pin
Prakash Nadar9-Apr-04 9:16
Prakash Nadar9-Apr-04 9:16 

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.