如何區別重新開機與關機的分別? |
答題得分者是:wameng
|
mine
中階會員 發表:28 回覆:129 積分:56 註冊:2004-03-31 發送簡訊給我 |
|
qoo1234
版主 發表:256 回覆:1167 積分:659 註冊:2003-02-24 發送簡訊給我 |
|
mine
中階會員 發表:28 回覆:129 積分:56 註冊:2004-03-31 發送簡訊給我 |
qoo 版大你好:
參考你為小的找的文章,幾經端詳還是分不清如何從中判別目前使用者要求的是關機還是重新開機 由於從WM_QUERYENDSESSION 或WM_ENDSESSION中小的已經可以知道目前使用者登出與重開(關機)之間的區別,跟文章中所提也不一樣,在小的測試中登出的Lparam會收到<>0 ,關機或重開則Wparam,lparam,Result都會傳回零,原因在關閉所有程式的過程中會無法關閉我的程式(故意設定的),所以在我的程式作完要作的動作後,才會依使用者的要求繼續登出或關機或重開,依大大所提的文章僅能知道,闗機是否可以正常動作無法得知使用者的要求(關或重開),還是小的有遺漏的地方,還請大大指正!! 搞不懂!搞不懂!永遠都搞不懂!! 發表人 - mine 於 2005/01/19 16:24:02
|
chris_shieh
高階會員 發表:46 回覆:308 積分:240 註冊:2004-04-26 發送簡訊給我 |
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/wm_queryendsession.asp
WM_QUERYENDSESSION ... ... A window receives this message through its WindowProc function. LRESULT CALLBACK WindowProc( HWND hwnd, // handle to window WM_QUERYENDSESSION, // the message to send WPARAM wParam, // not used LPARAM lParam // logoff option ); Parameters wParam This parameter is reserved for future use. lParam If this parameter includes ENDSESSION_LOGOFF, the user is logging off. (Note that this parameter is a bit mask. To test for this value, use a bit-wise operation; do not test for equality.) If this parameter is zero, the system is shutting down or restarting (it is not possible to determine which event is occurring).看來好像沒辦法分辨(至少WM_QUERYENDSESSION不行) @瞭解越多.懂得越少@ |
wameng
版主 發表:31 回覆:1336 積分:1188 註冊:2004-09-16 發送簡訊給我 |
提供個人看法。 1. 如同樓上所言。HOOK ExitWindow 也是一種方式。 只不過會擔心是否會影響到系統的穩定度。 2. 早期我在 Win98/ME 中,偵測使用者開啟關機對話視窗是選了哪一項。 做了一個取巧的方法。由於重開、關機、.... 會間接調用 Rundll32.exe Shell32.dll ......(忘了) 因此自己寫了一個Rundll32去取代原來的Rundll32,辨識所執行時的代入參 數以達成偵測的目的。在 Windows 2000 不知是否有用?給您做些參考。 3. 老實說,以下的方法我還沒有時間去試試!Try 看看吧!說不定有用。how to detect NT 4.0 shutdown type? ----------------------------------- When NT 4.0 sends out the wm_queryendsession message, how do I find out whether the system is shutting down, restarting, or the user is logging off. There are several ways of doing this. I will tell you one of the easiest ways of solving your problem. Look at the following registry setting : HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer "Shutdown Setting"=dword:00000000 When windows exits a message is flashed to explorer and the following is set : 0 - Log on as another user 1 - Shutdown the machine 2 - Restart the machine The other ways of doing it is to write a kernel mode device driver to watch the reboot process. Write a GINA DLL to override the MSGINA.DLL , the GINA DLL has capability of getting Shutdown, Restart and Logon messages on itself. 發表人 - wameng 於 2005/01/23 10:32:36 |
mine
中階會員 發表:28 回覆:129 積分:56 註冊:2004-03-31 發送簡訊給我 |
|
merphy2000
一般會員 發表:2 回覆:9 積分:2 註冊:2005-01-10 發送簡訊給我 |
請問一下: 我的電腦是Wndow XP, 我在registry內找不到Shutdown Setting這個機碼耶?
是隱藏的機碼嗎? 我寫了程式(如下)去找也沒看到這個機碼?自己在registry建了一個但還是沒找到,怎麼會這樣? 以下測試跑完結果是5 long ret0; HKEY MyKey,Key0,Key1,Key2,Key3,Key4,Key5; DWORD VarType = REG_DWORD; //the value's a REG_DWORD type DWORD BuffSize = 4; unsigned char *Buff = (unsigned char*)malloc(BuffSize); if ( RegOpenKeyEx(HKEY_CURRENT_USER, "Software\0", 0, KEY_READ, &Key0)==ERROR_SUCCESS) { if ( RegOpenKeyEx(Key0, "Microsoft", 0, KEY_READ, &Key1)==ERROR_SUCCESS) { if ( RegOpenKeyEx(Key1, "Windows", 0, KEY_READ, &Key2)==ERROR_SUCCESS) { if ( RegOpenKeyEx(Key2, "CurrentVersion", 0, KEY_READ, &Key3)==ERROR_SUCCESS) { if ( RegOpenKeyEx(Key3, "Explorer", 0, KEY_READ, &Key4) ==ERROR_SUCCESS) { if ( RegOpenKeyEx(Key4, "Shutdown Setting", 0, KEY_READ, &Key5)==ERROR_SUCCESS) { ret0=RegQueryValueEx(Key4,"Shutdown Setting",NULL,&VarType,Buff,&BuffSize); } else {wsprintf(temp,"5\n");fputs(temp,out);fflush(out);} } else {wsprintf(temp,"4\n");fputs(temp,out);fflush(out);} } else {wsprintf(temp,"3\n");fputs(temp,out);fflush(out);} } else {wsprintf(temp,"2\n");fputs(temp,out);fflush(out);} } else {wsprintf(temp,"1\n");fputs(temp,out);fflush(out);} } else {wsprintf(temp,"0\n");fputs(temp,out);fflush(out);} |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |