線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2229
推到 Plurk!
推到 Facebook!

控制Windows關機的方法(簡體)

 
axsoft
版主


發表:681
回覆:1056
積分:969
註冊:2002-03-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-06-25 10:54:04 IP:61.218.xxx.xxx 未訂閱
資料來源:中華網科技頻道--網路教室http://tech.china.com/zh_cn/netschool/programme/cbuilder/ 控制Windows關機的方法(簡體)http://tech.china.com/zh_cn/netschool/programme/cbuilder/4019/20000816/220554.htm
jasbeing
一般會員


發表:6
回覆:19
積分:5
註冊:2002-08-09

發送簡訊給我
#2 引用回覆 回覆 發表時間:2002-08-09 19:30:21 IP:140.135.xxx.xxx 未訂閱
哪其他windows me,2000,xp,又該如何呢?
kkid
一般會員


發表:1
回覆:5
積分:1
註冊:2002-07-25

發送簡訊給我
#3 引用回覆 回覆 發表時間:2002-08-12 11:52:15 IP:61.219.xxx.xxx 未訂閱
引言: 哪其他windows me,2000,xp,又該如何呢? < face="Verdana, Arial, Helvetica"> 我用win2000也可以用ExitWindowsEx關機阿... 不知道你的問題是什麼?
meamea
一般會員


發表:2
回覆:3
積分:1
註冊:2002-08-09

發送簡訊給我
#4 引用回覆 回覆 發表時間:2002-08-13 11:07:43 IP:202.106.xxx.xxx 未訂閱
這是在msdn找到的,在exit以前需要做這個動作.        HANDLE hToken;  TOKEN_PRIVILEGES tkp;    // Get a token for this process.    if (!OpenProcessToken(GetCurrentProcess(),          TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))      error("OpenProcessToken");    // Get the LUID for the shutdown privilege.    LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,          &tkp.Privileges[0].Luid);    tkp.PrivilegeCount = 1;  // one privilege to set     tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;    // Get the shutdown privilege for this process.    AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,          (PTOKEN_PRIVILEGES)NULL, 0);    // Cannot test the return value of AdjustTokenPrivileges.    if (GetLastError() != ERROR_SUCCESS)      error("AdjustTokenPrivileges");    // Shut down the system and force all applications to close.    if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))      error("ExitWindowsEx");      發表人 -
meamea
一般會員


發表:2
回覆:3
積分:1
註冊:2002-08-09

發送簡訊給我
#5 引用回覆 回覆 發表時間:2002-08-13 11:35:09 IP:202.106.xxx.xxx 未訂閱
忘了說,上面的sample是在2000/XP底下用的.
axsoft
版主


發表:681
回覆:1056
積分:969
註冊:2002-03-13

發送簡訊給我
#6 引用回覆 回覆 發表時間:2002-08-13 14:20:15 IP:61.218.xxx.xxx 未訂閱
這裡也有一篇    

實做關機程序

資料來源: http://home.kimo.com.tw/jyemii.jue/artifacts/delphi/faq/faq19003001.htm 作者: 朱子 先生 在 Windows NT 的環境下使用 ExitWindowsEx 的 API 時,必須另外再呼叫AdjustTokenPrivileges,有誰能告訴我該如何使用 ExitWindowsEx 加上 AdjustTokenPrivileges 來做到關機的功能? 解答 請參閱以下的程式碼及相關說明 //iFlags: // one of the following must be specified // EWX_LOGOFF // EWX_REBOOT // EWX_SHUTDOWN // following attributes may be combined with above flags // EWX_POWEROFF // EWX_FORCE : terminate processes function WinExitInNT( iFlags : integer ) : boolean; begin Result := True; if ( SetPrivilege( 'SeShutdownPrivilege', True ) ) then begin if( not ExitWindowsEx( iFlags, 0 ) )then begin Result := False; end; SetPrivilege( 'SeShutdownPrivilege', False ) end else begin // handle errors... Result := False; end; end; //Enabled or DisEnabled the SE_SHUTDOWN_NAME privilege //sPrivilegeName: // 'SE_SHUTDOWN_NAME' //bEnabled : // Enabled or DisEnabled 'SE_SHUTDOWN_NAME' privilege function SetPrivilege(sPrivilegeName : string; bEnabled : boolean ): boolean; var TPPrev, TP : TTokenPrivileges; Token : THandle; dwRetLen : DWord; begin Result := False; //opens the access token associated with a process. OpenProcessToken(GetCurrentProcess, //handle to process TOKEN_ADJUST_PRIVILEGES //Required to change the // privileges specified in an access token. or TOKEN_QUERY, //Required to query the contents //of an access token. Token); TP.PrivilegeCount := 1; //retrieves the locally unique identifier (LUID) used on a specified system to //locally represent the specified privilege name. if( LookupPrivilegeValue( Nil, //attempts to find the privilege name on the local system. PChar( sPrivilegeName ), // address of string specifying the privilege TP.Privileges[ 0 ].LUID ) // address of locally unique identifier ) then begin if( bEnabled )then //Give this privileges begin TP.Privileges[ 0 ].Attributes := SE_PRIVILEGE_ENABLED; end else begin //NOT Give this privileges TP.Privileges[ 0 ].Attributes := 0; end; dwRetLen := 0; //enables or disables privileges in the specified access token. Result := AdjustTokenPrivileges( Token, // handle to token that contains privileges False, //modifies privileges TP, // pointer to new privilege information SizeOf( TPPrev ), // size, in bytes, of the TPPrev buffer TPPrev, // receives original state of changed privileges dwRetLen // receives required size of the TPPrev buffer ); end; CloseHandle( Token ); end; 時間就是金錢---[ 發問前請先找找舊文章]
ericosur
一般會員


發表:0
回覆:15
積分:8
註冊:2002-08-08

發送簡訊給我
#7 引用回覆 回覆 發表時間:2002-08-31 18:15:15 IP:61.64.xxx.xxx 未訂閱
在 win2000 下若執行這個程式的使用者本來就沒有關機的選項, 程式好像也關不了機?
系統時間:2024-04-24 14:59:32
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!