English 中文(简体)
How to abort shutdown in Windows Vista and 7 programatically?
原标题:

In the second example (in the section examples) on this link, there is a description on using WM_QUERYENDSESSION to abort a shutdown. It also states that this does not work on versions of windows later than XP. This is conflicting with the advice given on another question here at stackoverflow. What is the correct answer? I do not have a computer with either so I am unable to test.

最佳回答

Some applications got the WM_QUERYENDSESSION handling wrong (Not passing to DefWindowProc, they incorrectly returned 0 even though they did not intend to block shutdown) and so MS changed it with Vista, you now need to call ShutdownBlockReasonCreate()

@Konamiman: shutdown.exe -a will abort a "scheduled" shutdown yes, but not a "normal" shutdown by someone calling ExitWindowsEx()

问题回答

If anything else fails, remember that from command line it is shutdown.exe -a; maybe you could invoke this using the Process class.

EDIT. When mentioning the Process class I happily assumed that the question was about .NET programming, now I see that .NET is not mentioned neither in the question nor in the tags. Anyway I believe that there are ways to run executables from other programming environments as well.





相关问题
How does Vistalizer work

How does Vistalizer manage to override the language limit in Windows Vista Home edition. Which api s does it use to allow installation of Multiple language packages.

Ericsson f3507g WWAN (3G Broadband) and AT commands

I have a lenovo x200t tablet with WWAN built into it. I m trying to connect to the internet using AT commands and a C# program which I am making so that the program can connect to the net and upload ...

Correct place to install demostration projects?

With the new Windows 7 restrictions (well, new to Windows Vista anyways), we can no longer install demo projects to %ProgramFilesFolder%OurApplicationdemo since restricted users will not be able to ...

How Can I Check To See If the User Set His Clock Back?

In my desktop program, I want to check that to see if the user has set his clock back. To do so, I compare the timestamp of certain Operating System files to the current computer date. If any are ...

Vista/Win7 Listview "View Slider"

In Vista and Windows 7 almost any time the system uses a standard Listview (ie: Explorer Windows) it s accompanied by a little split button that shows a slider when the split is clicked that allows ...

热门标签