Re: Why It didn't work when calling InitiateSystemShutdown() with local system privilege in Vista and 2008?



Hi Jojo,

Thanks for your feedback.

Please let me describe my workaround in details.

First, I create a new Windows application (Notifyapp.exe). This application
just pops up a common message box to show the user that the system will
shutdown in 10 minutes.

MessageBox(NULL,TEXT("System will shutdown in 10
minutes!"),TEXT("Warning"),MB_OK);

Second, I create windows service to call the CreateProcessAsUser the run
the Notifyapp.exe under logged on user session.

//use CreateProcessAsUser to run the Notifyapp.exe under users' session
bResult = CreateProcessAsUser(
hUserTokenDup, // client's access token
NULL, // file to
execute
CommandLine, // command line
&sa, // pointer to
process SECURITY_ATTRIBUTES
&sa, // pointer to
thread SECURITY_ATTRIBUTES
FALSE, // handles are not
inheritable
dwCreationFlags, // creation flags
pEnv, // pointer to new
environment block
NULL, // name of current
directory
&si, // pointer to
STARTUPINFO structure
&pi ); // receives
information about new process

Then, I make the service sleep for 10 minutes.

//force the service pause for 10 minutes
::Sleep(600000);

Finally, I call IniciateSystemShutdown to shutdown the system.

//call the InitiateSystemShutdown to shutdown the system
fResult = InitiateSystemShutdown(
NULL, // shut down local computer
lpMsg, // message for user
30, // time-out period, in seconds
FALSE, // ask user to close apps
TRUE); // reboot after shutdown

I am not very sure about what you mean by "launch my UI program which calls
the InitiateSystemShutdown() in the 'Console Session'". Since the Session 0
is reserved for service and system process in Windows Vista and later.
Therefore it is not good idea to create a user interface (UI), such as a
dialog box, in Session 0. Because the user is not running in Session 0, he
or she never sees the UI and therefore cannot provide the input. I assume
that the 'Console Session' here you mean is the first logged on user
session. Please correct me if I misunderstand you.

When I call InitiateSystemShutdown in a user session(e.g. session 1), the
shutdown dialog box will be displayed and show that the system will be shut
down in a few minutes/seconds. However, there is no full-screen UI to block
shutdown process, and system is always shut down.

Let me know if you have any additional questions and concerns.

Regards,
Rongchun Zhang (v-rzhang@xxxxxxxxxxxxxxxxxxxx, remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@xxxxxxxxxxxxxx

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================

.



Relevant Pages