如何在Windows关闭时执行函数 [英] How can I Execute a Function when Windows Shut down
问题描述
如何在Windows关闭时执行函式。这里是我的方案,我使用 WNetAddConnection2 功能在我的应用程序加载驱动器。现在我想让用户设置选项,如果驱动器将在下次系统启动时挂载。
How Can I execute a function when Windows shutdown. Here is my scenario, I am mounting a drive using WNetAddConnection2 function in my application. Now I want user to set the option if the drive will be mounted on next system startup or not.
如果他选择不在下次启动时挂载,则需要使用 WNetCancelConnection2 ,但这只应在用户关闭系统时发生。
If he selects , not to mount on next startup , then I need to remove the drive using WNetCancelConnection2 , but this should only happen when user shutdown the system.
我只能想到解决方案。创建一个服务,它将检查用户选项,然后决定是否挂接驱动器。
I can only think of only solution. Create a service which will check the user option and then decide whether to mount the drive or not.
有其他方法可以使用吗?
Are there any other ways to go ahead with it?
推荐答案
如果你有一个可以处理消息的主窗口(即使是不可见的窗口),你可以处理WM_ENDSESSION消息。
If you have a main window (even an invisible one) that can process messages, you can handle the WM_ENDSESSION message.
请参阅: http://msdn.microsoft.com/zh-TW/library/aa376889(v=VS.85).aspx
这篇关于如何在Windows关闭时执行函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!