全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:3007
推到 Plurk!
推到 Facebook!

如何設定電腦在某特定時間一到即自動關閉

答題得分者是:christie
ry_lee
高階會員


發表:367
回覆:251
積分:123
註冊:2002-03-19

發送簡訊給我
#1 引用回覆 回覆 發表時間:2009-03-20 21:04:46 IP:125.224.xxx.xxx 未訂閱
如何設定電腦在某特定時間一到即自動關閉,比如每天下午六點我就下班離開我的電腦,但希望到下午九點時電腦能自動關閉,如同下午九點到時,我坐在電腦前執行 開始 | 電腦關機 之選單指令.
boss.tw
高階會員


發表:15
回覆:109
積分:194
註冊:2005-05-17

發送簡訊給我
#2 引用回覆 回覆 發表時間:2009-03-20 23:50:32 IP:122.116.xxx.xxx 訂閱
開始 -> 執行 -> cmd 打開 command line 視窗
打入 shutdown -t xx(幾秒後關機)
可以寫 bat 或是程式UI設幾秒之後shellexecute

shutdown /? 可以看說明

使用方式: shutdown [-i | -l | -s | -r | -a] [-f] [-m \\computername] [-t xx] [-c
"comment"] [-d up:xx:yy]
沒有引數 顯示這個訊息 (和 -? 相同)
-i 顯示 GUI 介面,必須是第一個選項
-l 登出 (不能和 -m 選項一起使用)
-s 電腦關機
-r 關機並重新啟動電腦
-a 中止系統關機
-m \\\\computername 從遠端進行關機/重新啟動/中止
-t xx 將關機等候時間設定成 xx 秒
-c "comment" 關機註解 (最多 127 個字元)
-f 強制關閉執行中的應用程式,不顯示警告
-d [u][p]:xx:yy 關機原因代碼
u 是使用者代碼
p 是預先計劃的關機代碼
xx 是主要原因代碼 (小於 256 的正整數)
yy 是次要原因代碼 (小於 65536 的正整數)
===================引 用 ry_lee 文 章===================
如何設定電腦在某特定時間一到即自動關閉,比如每天下午六點我就下班離開我的電腦,但希望到下午九點時電腦能自動關閉,如同下午九點到時,我坐在電腦前執行 開始 | 電腦關機 之選單指令.
編輯記錄
boss.tw 重新編輯於 2009-03-20 23:53:19, 註解 無‧
老大仔
尊榮會員


發表:77
回覆:835
積分:1082
註冊:2006-07-06

發送簡訊給我
#3 引用回覆 回覆 發表時間:2009-03-21 02:46:16 IP:59.114.xxx.xxx 未訂閱
以下這篇應該有您要的東西
請參考看看吧~
http://delphi.ktop.com.tw/board.php?cid=30&fid=72&tid=95408
Coffee
版主


發表:31
回覆:878
積分:561
註冊:2006-11-15

發送簡訊給我
#4 引用回覆 回覆 發表時間:2009-03-22 01:09:43 IP:59.124.xxx.xxx 訂閱
不搜尋就過份了,連自己問過的問題也沒有印象?可以不要太扯嗎?

如何讓電腦自動在每天的固定時間開機及關機?
------
不論是否我發的文,在能力範圍皆很樂意為大家回答問題。
為了補我的能力不足之處,以及讓答案可以被重複的使用,希望大家能儘量以公開的方式問問題。
在引述到我的文時自然會儘量替各位想辦法,謝謝大家!
編輯記錄
Coffee 重新編輯於 2009-03-22 01:10:35, 註解 無‧
christie
資深會員


發表:28
回覆:299
積分:475
註冊:2005-03-25

發送簡訊給我
#5 引用回覆 回覆 發表時間:2009-03-23 14:56:47 IP:59.125.xxx.xxx 訂閱
How to shutdown / reboot / logoff Windows 9x/NT/Me/2000/XP?
http://www.swissdelphicenter.ch/torry/showcode.php?id=168

{1.}

function MyExitWindows(RebootParam: Longword): Boolean;
var
TTokenHd: THandle;
TTokenPvg: TTokenPrivileges;
cbtpPrevious: DWORD;
rTTokenPvg: TTokenPrivileges;
pcbtpPreviousRequired: DWORD;
tpResult: Boolean;
const
SE_SHUTDOWN_NAME = 'SeShutdownPrivilege';
begin
if
Win32Platform = VER_PLATFORM_WIN32_NT
then
begin
tpResult := OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,
TTokenHd);
if tpResult
then
begin
tpResult := LookupPrivilegeValue(nil,
SE_SHUTDOWN_NAME,
TTokenPvg.Privileges[0].Luid);
TTokenPvg.PrivilegeCount := 1;
TTokenPvg.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
cbtpPrevious := SizeOf(rTTokenPvg);
pcbtpPreviousRequired := 0;
if tpResult
then
Windows.AdjustTokenPrivileges(TTokenHd,
False,
TTokenPvg,
cbtpPrevious,
rTTokenPvg,
pcbtpPreviousRequired);
end;
end;
Result := ExitWindowsEx(RebootParam, 0);
end;

// Example to shutdown Windows:

procedure TForm1.Button1Click(Sender: TObject);
begin
MyExitWindows(EWX_POWEROFF or EWX_FORCE);
end;

// Example to reboot Windows:

procedure TForm1.Button1Click(Sender: TObject);
begin
MyExitWindows(EWX_REBOOT or EWX_FORCE);
end;


////////////////////////////////////
// Parameters for MyExitWindows() //
////////////////////////////////////
EWX_LOGOFF

Shuts down all processes running in the security context of the process that called the
ExitWindowsEx function. Then it logs the user off.


EWX_POWEROFF

Shuts down the system and turns off the power.
The system must support the power-off feature.
Windows NT/2000/XP:
The calling process must have the SE_SHUTDOWN_NAME privilege.


EWX_REBOOT

Shuts down the system and then restarts the system.
Windows NT/2000/XP: The calling process must have the SE_SHUTDOWN_NAME privilege.


EWX_SHUTDOWN

Shuts down the system to a point at which it is safe to turn off the power.
All file buffers have been flushed to disk, and all running processes have stopped.
If the system supports the power-off feature, the power is also turned off.
Windows NT/2000/XP: The calling process must have the SE_SHUTDOWN_NAME privilege.


EWX_FORCE

Forces processes to terminate. When this flag is set,
the system does not send the WM_QUERYENDSESSION and WM_ENDSESSION messages.
This can cause the applications to lose data.
Therefore, you should only use this flag in an emergency.


EWX_FORCEIFHUNG

Windows 2000/XP: Forces processes to terminate if they do not respond to the
WM_QUERYENDSESSION or WM_ENDSESSION message. This flag is ignored if EWX_FORCE is used.




{************************************************************************}

{2. Console Shutdown Demo}

program Shutdown;
{$APPTYPE CONSOLE}

uses
SysUtils,
Windows;

// Shutdown Program
// (c) 2000 NeuralAbyss Software
// www.neuralabyss.com

var
logoff: Boolean = False;
reboot: Boolean = False;
warn: Boolean = False;
downQuick: Boolean = False;
cancelShutdown: Boolean = False;
powerOff: Boolean = False;
timeDelay: Integer = 0;

function HasParam(Opt: Char): Boolean;
var
x: Integer;
begin
Result := False;
for x := 1 to ParamCount
do
if
(ParamStr(x) = '-' opt) or (ParamStr(x) = '/' opt) then Result := True;
end;

function GetErrorstring: string;
var
lz: Cardinal;
err: array[0..512] of Char;
begin
lz := GetLastError;
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, nil, lz, 0, @err, 512, nil);
Result := string(err);
end;

procedure DoShutdown;
var
rl, flgs: Cardinal;
hToken: Cardinal;
tkp: TOKEN_PRIVILEGES;
begin
flgs := 0;
if downQuick then flgs := flgs or EWX_FORCE;
if not reboot then flgs := flgs or EWX_SHUTDOWN;
if reboot then flgs := flgs or EWX_REBOOT;
if poweroff and (not reboot) then flgs := flgs or EWX_POWEROFF;
if logoff then flgs := (flgs and (not (EWX_REBOOT or EWX_SHUTDOWN or EWX_POWEROFF)))
or
EWX_LOGOFF;
if Win32Platform = VER_PLATFORM_WIN32_NT
then
begin
if not
OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,
hToken)
then
Writeln('Cannot open process token. [' GetErrorstring ']')
else
begin
if
LookupPrivilegeValue(nil, 'SeShutdownPrivilege', tkp.Privileges[0].Luid)
then
begin
tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
tkp.PrivilegeCount := 1;
AdjustTokenPrivileges(hToken, False, tkp, 0, nil, rl);
if GetLastError <> ERROR_SUCCESS
then
Writeln('Error adjusting process privileges.');
end
else
Writeln('Cannot find privilege value. [' GetErrorstring ']');
end;
{ if CancelShutdown then
if AbortSystemShutdown(nil) = False then
Writeln(\'Cannot abort. [\' GetErrorstring \']\')
else
Writeln(\'Cancelled.\')
else
begin
if InitiateSystemShutdown(nil, nil, timeDelay, downQuick, Reboot) = False then
Writeln(\'Cannot go down. [\' GetErrorstring \']\')
else
Writeln(\'Shutting down!\');
end;
}
end;
// else begin
ExitWindowsEx(flgs, 0);
// end;
end;

begin
Writeln('Shutdown v0.3 for Win32 (similar to the Linux version)');
Writeln('(c) 2000 NeuralAbyss Software. All Rights Reserved.');
if HasParam('?') or (ParamCount = 0)
then
begin
Writeln('Usage: shutdown [-akrhfnc] [-t secs]');
Writeln(' -k: don''t really shutdown, only warn.');
Writeln(' -r: reboot after shutdown.');
Writeln(' -h: halt after shutdown.');
Writeln(' -p: power off after shutdown');
Writeln(' -l: log off only');
Writeln(' -n: kill apps that don''t want to die.');
Writeln(' -c: cancel a running shutdown.');
end
else
begin
if
HasParam('k') then warn := True;
if HasParam('r') then reboot := True;
if HasParam('h') and reboot
then
begin
Writeln('Error: Cannot specify -r and -h parameters together!');
Exit;
end;
if HasParam('h') then reboot := False;
if HasParam('n') then downQuick := True;
if HasParam('c') then cancelShutdown := True;
if HasParam('p') then powerOff := True;
if HasParam('l') then logoff := True;
DoShutdown;
end;
end.
------
What do we live for if not to make life less difficult for each other?
編輯記錄
christie 重新編輯於 2009-03-23 14:59:12, 註解 無‧
christie 重新編輯於 2009-03-23 15:01:24, 註解 無‧
系統時間:2017-10-17 19:25:58
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!