caterpilla 发表于 2006-6-22 11:02:14

提交一个定时关机程序

用DELPHI写了个,试着玩下。。。。。

飘云 发表于 2006-6-22 11:07:17

不错,建议把原创程序放到置顶的 “原创软件交流贴” 中,然后自己独占一个楼层,以后好更新~~
以便我们以后收集

黑夜彩虹 发表于 2006-6-22 11:12:22

支持一下~~ /:D

放出源码,我给你加精... ;P

[ 本帖最后由 黑夜彩虹 于 2006-6-22 11:14 编辑 ]

caterpilla 发表于 2006-6-22 11:22:48

DELPHI 2006编译,比较粗糙。。。。。。。。

unit TimerShutDown;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, XPMan, StdCtrls, Buttons, ComCtrls, ExtCtrls, Menus, ImgList,
AppEvnts;

type
TForm1 = class(TForm)
    TrayIconTimer: TTrayIcon;
    TimerShutDown: TTimer;
    GroupBox1: TGroupBox;
    UpDown1: TUpDown;
    Edit1: TEdit;
    UpDown2: TUpDown;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    ImageList1: TImageList;
    PopupMenu1: TPopupMenu;
    RestoreMenu: TMenuItem;
    N2: TMenuItem;
    ExitMenu: TMenuItem;
    AboutMenu: TMenuItem;
    ApplicationEvents1: TApplicationEvents;
    RadioGroup1: TRadioGroup;
    CheckBox1: TCheckBox;

    procedure TimerShutDownTimer(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure ApplicationEvents1Minimize(Sender: TObject);
    procedure AboutMenuClick(Sender: TObject);
    procedure ExitMenuClick(Sender: TObject);
    procedure RestoreMenuClick(Sender: TObject);
private
    { Private declarations }
    Count: Integer;
    procedure AdjustToken;
public
    { Public declarations }

end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.AboutMenuClick(Sender: TObject);
begin
ShowMessage('飘云阁定时关机1.0版');
end;

procedure TForm1.AdjustToken;
var
hdlProcessHandle: Cardinal;
hdlTokenHandle: Cardinal;
tmpLuid: Int64;
tkp: TOKEN_PRIVILEGES;
tkpNewButIgnored: TOKEN_PRIVILEGES;
lBufferNeeded: Cardinal;
Privilege: array of _LUID_AND_ATTRIBUTES;
begin
hdlProcessHandle := GetCurrentProcess; //get current process pseudohandle
OpenProcessToken(hdlProcessHandle, (TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY), hdlTokenHandle);
// Get the LUID for shutdown privilege.
LookupPrivilegevalue('', 'SeShutdownPrivilege', tmpLuid);
Privilege.Luid := tmpLuid;
Privilege.Attributes := SE_PRIVILEGE_ENABLED;
tkp.PrivilegeCount := 1; // One privilege to set
tkp.Privileges := Privilege;
// Enable the shutdown privilege in the access token of this process.
AdjustTokenPrivileges(hdlTokenHandle, False, tkp, Sizeof(tkpNewButIgnored), tkpNewButIgnored, lBufferNeeded);
end;

procedure TForm1.ApplicationEvents1Minimize(Sender: TObject);
begin
TrayIconTimer.Visible := True;
//   Application.ShowMainForm:=False;
ShowWindow(Application.Handle, SW_HIDE);
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
try
    Count := StrToInt(Edit1.Text) * 60 + StrToInt(edit2.Text);
    TrayIconTimer.Hint := '距离' + RadioGroup1.Items + '还有' + IntToStr(count div 60) + '小时' + IntToStr(count mod 60) + '分钟';
    TimerShutDown.Enabled := True;
    Application.Minimize;
    TrayIconTimer.Animate:=CheckBox1.Checked;
    TrayIconTimer.AnimateInterval:=TimerShutDown.Interval div 2;
    BitBtn1.Enabled:=False;
except
    ShowMessage('Please input integer!');
end;
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
begin
TrayIconTimer.Visible := False;
TimerShutDown.Enabled := False;
Close;
end;

procedure TForm1.RestoreMenuClick(Sender: TObject);
begin
ShowWindow(Application.Handle, SW_SHOWNORMAL);
end;

procedure TForm1.TimerShutDownTimer(Sender: TObject);
begin
Dec(Count);
TrayIconTimer.Hint := '距离' + RadioGroup1.Items + '还有' + IntToStr(count div 60) + '小时' + IntToStr(count mod 60) + '分钟';
if Count = 0 then
begin
    AdjustToken;
    case RadioGroup1.ItemIndex of
      0:
      ExitWindowsEx(EWX_LOGOFF or EWX_FORCE, 0);

      1:
      ExitWindowsEx(EWX_REBOOT or EWX_FORCE, 0);

      2:
      ExitWindowsEx(EWX_POWEROFF or EWX_SHUTDOWN or EWX_FORCE, 0);

    end;
end;
end;

procedure TForm1.ExitMenuClick(Sender: TObject);
begin
Form1.Close;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Count := 0;
end;


end.
+++++++++++++++++++++++++++++
为了奖历开源,加精,HOHO...

[ 本帖最后由 黑夜彩虹 于 2006-6-22 14:04 编辑 ]

野猫III 发表于 2006-6-22 22:23:45

快哉! 兄弟好棒... 猫还不会.呵呵...

[ 本帖最后由 野猫III 于 2006-6-22 22:25 编辑 ]

~逍遥~ 发表于 2006-7-21 09:52:58

还是不错的   

可是用shutdown命令同样可以达到效果

joker27 发表于 2006-7-24 18:53:38

在天极看过

caterpilla 发表于 2006-8-2 12:41:20

原帖由 ~逍遥~ 于 2006-7-21 09:52 发表
还是不错的   

可是用shutdown命令同样可以达到效果
SHUTDOWN中销定或未登录状态时无法工作。。。。。。。。。。

sandes 发表于 2008-3-1 16:08:18

快哉! 兄弟好棒..先看看 了

lcj240856742 发表于 2008-5-10 14:25:02

看看了不错的东西
页: [1] 2
查看完整版本: 提交一个定时关机程序