问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

delphi7 求自动关机源码

发布网友 发布时间:2022-04-20 05:08

我来回答

1个回答

热心网友 时间:2023-07-17 09:08

这是以前写的自动关机的代码,一个PAS文件源,一个是DFM的(具体什么时间调用这个关机的你就自己写吧,写个计时器判断就好了。) PAS代码: unit Form_AutoShutWindows;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Buttons;type
TFrm_AutoShutWindows = class(TForm)
Timer: TTimer;
P_Tip: TPanel;
L1: TLabel;
LB_Hint: TLabel;
IMG_TIP: TImage;
procere FormClose(Sender: TObject; var Action: TCloseAction);
procere TimerTimer(Sender: TObject);
procere FormShow(Sender: TObject);
procere FormCreate(Sender: TObject);
procere FormResize(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Frm_AutoShutWindows: TFrm_AutoShutWindows;
Check_AutoT:Integer=3;implementation{$R *.dfm}Function System_Ver:String;
var VersionInfo: TOSVersionInfo;
begin
VersionInfo.dwOSVersionInfoSize := Sizeof(TOSVersionInfo);
GetVersionEx(VersionInfo);
Case VersionInfo.dwPlatformID of
VER_PLATFORM_WIN32S: Result:='';
VER_PLATFORM_WIN32_WINDOWS: Result:='WINDOWS9X';
VER_PLATFORM_WIN32_NT: Result :='WINDOWSNT';
End;
end;procere ADJUST_;
var
hToken : THandle;
Tkp : TTokenPrivileges;
Zero:DWORD;
begin
OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,hToken);
LookupPrivilegeValue(nil,'SeShutdownPrivilege',tkp.Privileges[0].Luid);
Tkp.PrivilegeCount :=1;
Tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken,False,Tkp,SizeOf(TTokenPrivileges),nil,Zero);
end;procere TFrm_AutoShutWindows.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action:=Cafree;
Self:=nil;
end;procere TFrm_AutoShutWindows.TimerTimer(Sender: TObject);
Var
I:Integer;
ProcessWnd,ExitCode:Cardinal;
Mem_List:TStringList;
function GetCurrentRun:Integer;
var
aryCaption: array[0..255] of Char;
hFound: THandle;
nProcId: DWord;
IsCanOpen : THandle;
begin
Result := 0;
hFound := FindWindowEx(0, 0, nil, nil);
MEM_List.Clear;
while hFound <> 0 do
begin
if GetWindow(hFound, GW_OWNER) = 0 then
if IsWindowVisible(hFound) then
if GetWindowText(hFound, aryCaption, 255) > 0 then
if (AnsiCompareText(StrPas(aryCaption), 'Program Manager') <> 0) then
begin
GetWindowThreadProcessId(hFound, @nProcId);
If (nProcId<>windows.GetCurrentProcessId()) then
Begin
IsCanOpen:=OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ
or PROCESS_VM_WRITE or PROCESS_QUERY_INFORMATION,true,nProcId);
if (IsCanOpen<>0) Then //能打开
begin
windows.CloseHandle(IsCanOpen);
MEM_List.Add(FloatToStr(nProcID));
Result:=Result+1;
end; //end if
end; //end if
end;
hFound := FindWindowEx(0, hFound, nil, nil);
end;
end;
begin
Dec(Check_AutoT);
LB_Hint.Caption:=Inttostr(Check_AutoT)+' 秒 ';
If Check_AutoT<=0 then
begin
Timer.Enabled:=false;
Mem_List:=TStringList.Create ;
If GetCurrentRun>0 then
Begin
For I:=0 to Mem_list.Count-1 do
Begin
ProcessWnd := OpenProcess(PROCESS_ALL_ACCESS, True, StrToInt(Mem_List.Strings[I]));
GetExitCodeProcess(ProcessWnd,ExitCode);
TerminateProcess(ProcessWnd, ExitCode);
END;
End;
If System_Ver<>'WINDOWS9X' then
Begin
ADJUST_;
ExitWindowsEx(EWX_POWEROFF,EWX_SHUTDOWN+EWX_FORCE+EWX_POWEROFF); //关闭系统并关闭电源
End else
begin
Winexec(pchar('Net use * /del /yes'),SW_HIDE);
ExitWindowsEx(EWX_SHUTDOWN,1);
end;
Application.Terminate;
end;
end;procere TFrm_AutoShutWindows.FormShow(Sender: TObject);
begin
WindowState:=wsMinimized;
WindowState:=wsNormal;
Timer.Enabled:=True;
end;procere TFrm_AutoShutWindows.FormCreate(Sender: TObject);
begin
Width:=Screen.Width;
Height:=Screen.Height;
Application.BringToFront;
end;procere TFrm_AutoShutWindows.FormResize(Sender: TObject);
begin
P_Tip.Top:=(Height div 2)-115;
P_Tip.Left:=(Width Div 2)-280;
end;end.
DFM代码: object Frm_AutoShutWindows: TFrm_AutoShutWindows
Left = 52
Top = 53
BorderIcons = [biMinimize, biMaximize]
BorderStyle = bsNone
Caption = '自动关机提示'
ClientHeight = 615
ClientWidth = 880
Color = clWindow
Font.Charset = ANSI_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = '宋体'
Font.Style = []
FormStyle = fsStayOnTop
OldCreateOrder = False
Position = poScreenCenter
Scaled = False
OnClose = FormClose
OnCreate = FormCreate
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 12
object Shape1: TShape
Left = 0
Top = 0
Width = 880
Height = 615
Align = alClient
end
object Label1: TLabel
Left = 86
Top = 106
Width = 697
Height = 87
Caption = '30秒后将自动关机'
Font.Charset = ANSI_CHARSET
Font.Color = clNavy
Font.Height = -87
Font.Name = '宋体'
Font.Style = []
ParentFont = False
Transparent = True
end
object Label2: TLabel
Left = 81
Top = 280
Width = 785
Height = 87
Caption = '还剩下   秒 ...'
Font.Charset = ANSI_CHARSET
Font.Color = clNavy
Font.Height = -87
Font.Name = '宋体'
Font.Style = []
ParentFont = False
Transparent = True
end
object LB_Hint: TLabel
Left = 357
Top = 216
Width = 222
Height = 223
Alignment = taCenter
AutoSize = False
Caption = '30'
Font.Charset = ANSI_CHARSET
Font.Color = clNavy
Font.Height = -200
Font.Name = 'Arial'
Font.Style = []
ParentFont = False
Transparent = True
end
object Label3: TLabel
Left = 536
Top = 568
Width = 296
Height = 16
Caption = '点击取消,可暂时将关机时间延迟10分钟。'
Font.Charset = ANSI_CHARSET
Font.Color = clRed
Font.Height = -16
Font.Name = '宋体'
Font.Style = []
ParentFont = False
end
object Btn_CloseWindows: TBitBtn
Left = 240
Top = 432
Width = 161
Height = 121
Caption = '立即关机'
Font.Charset = ANSI_CHARSET
Font.Color = clMaroon
Font.Height = -27
Font.Name = '宋体'
Font.Style = []
ParentFont = False
TabOrder = 0
OnClick = Btn_CloseWindowsClick
end
object Btn_CanCel: TBitBtn
Left = 496
Top = 432
Width = 153
Height = 121
Caption = '取消'
Font.Charset = ANSI_CHARSET
Font.Color = clMaroon
Font.Height = -27
Font.Name = '宋体'
Font.Style = []
ParentFont = False
TabOrder = 1
OnClick = Btn_CanCelClick
end
object MEM_List: TMemo
Left = 72
Top = 56
Width = 185
Height = 89
TabOrder = 2
Visible = False
end
object Timer: TTimer
Enabled = False
OnTimer = TimerTimer
Left = 240
Top = 48
end
end
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
黑鱼身上有寄生虫吗 寄生虫是否可能存在于鱼的身体里? 取保候审没拘留怎么办 支付宝开通快捷支付后,能在支付宝查银行卡余额吗? 秋天,正是吃板栗的季节,分享7种经典吃法别错过,老少皆宜! CHOW TAI SENG 周大生 P0PC0078 桃花Pt950铂金项链 购买最佳价格 周大生的钻戒PT950 0.27ct I-J VS 7892元贵吗? 周大生铂950项链J1909011916 重量:4.69g 和Pt950吊坠J191000191967 重量... CHOW TAI SENG/周大生 P0PC0078 桃花Pt950铂金项链 45cm 3.63g-详细介... 白金多少钱一克PT950 如何高效 online 创建大表的索引 oracle 什么时候使用索引 sql profile和SPM baseline谁的优先级高 Oracle中表建立联合索引后,其中的一个字段是否可... 如何从硬盘直接进入DOS,再使用GHOST。. set autotrace on时候为什么会报Cannot SET AUTOTRACE 我的系统是vista,开机的时候有两个启动项是我不想... 如何获取执行计划 如何启用sqlplus的AutoTrace功能 如何做trace 每一步 每一行 哪里有Autot cad2007教学视频下载 提示 autoit v3:autot3.exe-损坏文件 怎么修复?请... AutotCAD中怎么删除已定义的块??? 为什么很多人宁愿买小米8SE也不买小米8? 安利这个牌子是哪个国家的呢? 安利为什么消失了 郑州出租车网官网怎么不能预约? 我想在郑州考取出租车资格证,请问在哪儿报名?多... 郑州出租车网怎么打不开 郑州市出租车往车上上人员从业上传多久才能营运 如何计算某个sql语句所产生的redo和undo大小 Oracle 如何控制查询不区分大小写? oralce 计算当前记录排在总记录数的百分之多少 oracle的recursive calls为什么这么高 oracle hint cardinality 提示什么意思 请教高手:oracle临时表创建优化 常用理发工具有哪些?都有什么用途? 你好请问欧派电热水器显示E1故障? 剪头发需要哪些工具? 理发店像狼牙棒的工具叫什么,可蓬松头发的那种 削薄头发使用的剪子叫什么 自己理发需要买什么工具? 理发店用品名称都有哪些 理发工具有哪些 理发店常用工具有哪些? 理发店用的那个把头发拉直的夹子叫什么? 剃头的头子是什么东西 (理发)什么是卡尺,剃完啥样? 理发拉线工具叫什么? 过去理发喊人工具叫什么