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

Hello Jojo,

Sorry for the misunderstanding.

During my test, I get the same result that you described. As the MSDN
for InitiateSystemShutdown said:

If the caller chooses not to force these applications closed, and an
application with unsaved changes is running on the console session, the
shutdown will remain in progress until the user logged into the console
session aborts the shutdown, saves changes, closes the application, or
forces the application to close.

In Windows XP, Windows Server 2003, and earlier versions of the Windows
operating system, the console session (session 0) is for services and the
first user who logs on. Say, if we have two users on Windows XP(UserA and
UserB), when Windows XP starts, we log on to it with UserA first(UserA is
under session 0) and don't leave any application with unsaved changes
running under UserA. Then fast switch to UserB(UserB is under session 1)
and call the InitiateSystemShutdown function under UserB, windows always
shutdown regardless if there were unsaved data under UserB. However, in
Windows Vista, your users' application can't run in the console session any
more for some security reasons. Only system processes and services run in
session 0. The first user logs on to session 1, and subsequent users log on
to subsequent sessions.

As a possible workaround, I find that the API
may help. Based on my tests, ExitWindowsEx waits for the user's interaction
to cancel/save the changed data.

During a shutdown or log-off operation, running applications are allowed a
specific amount of time to respond to the shutdown request. If this time
expires before all applications have stopped, the system displays a user
interface that allows the user to forcibly shut down the system or to
cancel the shutdown request. If the EWX_FORCE value is specified, the
system forces running applications to stop when the time expires.

One problem with ExitWindowsEx is that, the ExitWindowsEx function is
designed to stop all processes in the caller's logon session. Therefore, if
you are not the interactive user, the function can succeed without actually
shutting down the computer. I tried to call ExitWindowsEx from an
non-interactive user, and it log off or shutdown the system without waiting
for user's response.

By the way, after discussing with the product group, they confirmed my
understanding in my last reply.

Please try the ExitWindowsEx function and let me know if it meets your
requirement. If you have additional questions and concerns, please feel
free to contact me.

Have a nice day.

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:

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


Relevant Pages