function CheckTask(ExeFileName: string): Boolean; //检测XX进程是否存在函数
const
PROCESS_TERMINATE = $0001;
var
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
result := False;
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
while integer(ContinueLoop) <> 0 do begin
if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = UpperCase(ExeFileName))
or (UpperCase(FProcessEntry32.szExeFile) = UpperCase(ExeFileName))) then
result := True;
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
end;
function KillTask(ExeFileName: string): integer; // 把XX进程结束掉的函数
const
PROCESS_TERMINATE = $0001;
var
ContinueLoop: Boolean;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
result := 0;
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
while integer(ContinueLoop) <> 0 do begin
if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =
UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) =
UpperCase(ExeFileName))) then
result := integer(TerminateProcess(
OpenProcess(PROCESS_TERMINATE,
BOOL(0),
FProcessEntry32.th32ProcessID),
0));
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;
procedure TForm1.MinAllWindows; //最小化所有窗口的过程,有两招哦。
var h: HWnd;
begin
//Form1.WindowState:=wsMinimized;
// 第一招,检测当前所有可视窗口,逐一最小化。
h := Handle;
while h > 0 do begin
if IsWindowVisible(h) then
Postmessage(h, WM_SYSCOMMAND, SC_MINIMIZE, 0);
h := GetnextWindow(h, GW_HWNDNEXT);
end;
//锁定这个软件的正常运行,若其它人想使用它,先输入密码吧。密码是什么??? ~~~
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
s := s + chr(Key); //用户输入"Author"这显示
if StrUpper(Pchar(s)) = 'BEYOND' then begin
Form1.Caption := 'Auto clicker by 黄仁来(已解锁)';
Locked := False;
s := '';
Button1.Enabled := True;
Button2.Enabled := True;
Button3.Enabled := True;
Edit1.Enabled := True;
Edit2.Enabled := True;
Button4.Enabled := True;
Check.Enabled:=True;
end;
if Key = 13 then s := '';
end;
//添加一个基本无用的过程,锁定这个小软件不被其它随意关闭。哈哈。
//不过这个功能明显不够专业,在“任务管理器里还是很容易被关掉的”
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if Locked then begin
CanClose := False;
showmessage('请先解锁');
exit;
end;
end;
procedure TForm1.AutoRun(Flag: Boolean); //自动运行函数,注意主键是 HKEY_CURRENT_USER
var
tempreg: TRegistry;
begin
try
tempreg := TRegistry.Create;
tempreg.RootKey := HKEY_CURRENT_USER;
tempreg.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run', True);
if Flag then tempreg.WriteString('AutoClicker', '"' + Application.ExeName + '"')
else
begin
if not Tempreg.DeleteValue ('AutoClicker') then showmessage('删除失败');
end;
finally
tempreg.Closekey;
tempreg.Free;
end;
end;
procedure TForm1.CheckClick(Sender: TObject);
begin
if not Check.Checked then Autorun(False) else Autorun(True); //是否自动运行。
end;