📄 fun2.pas
字号:
unit fun2;
interface
uses
windows, messages, URLMon, Sysutils, Classes, Tlhelp32;
procedure AdjustToken(); //获取关机权限
function Dlf(SourceFile, DestFile: string): Boolean; //从网上下文件
function FindProcess(ExeName: string): Longword; //寻找指定进程,返回其ID
implementation
procedure AdjustToken();
{设置关机权限}
var
hdlProcessHandle : Cardinal;
hdlTokenHandle : Cardinal;
tmpLuid : Int64;
tkp : TOKEN_PRIVILEGES;
tkpNewButIgnored : TOKEN_PRIVILEGES;
lBufferNeeded : Cardinal;
Privilege : array[0..0] of _LUID_AND_ATTRIBUTES;
begin
hdlProcessHandle := GetCurrentProcess;
OpenProcessToken(hdlProcessHandle, (TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY),
hdlTokenHandle);
LookupPrivilegeValue('', 'SeShutdownPrivilege', tmpLuid);
Privilege[0].Luid := tmpLuid;
Privilege[0].Attributes := SE_PRIVILEGE_ENABLED;
tkp.PrivilegeCount := 1;
tkp.Privileges[0] := Privilege[0];
AdjustTokenPrivileges(hdlTokenHandle,
false,
tkp,
SizeOf(tkpNewButIgnored),
tkpNewButIgnored,
lBufferNeeded);
end;
function Dlf(SourceFile, DestFile: string): Boolean;
{下载文件}
begin
try
Result := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0, nil) = 0;
except
Result := false;
end;
end;
function FindProcess(ExeName: string): Longword; //寻找指定进程,返回其ID.
function AnsiEndsText(const ASubText, AText: string): Boolean;
var
P : PChar;
L, L2 : Integer;
begin
P := PChar(AText);
L := Length(ASubText);
L2 := Length(AText);
Inc(P, L2 - L);
if L > L2 then
Result := False
else
Result := CompareString(LOCALE_USER_DEFAULT, NORM_IGNORECASE, P, L, PChar(ASubText), L) = 2;
end;
var
sphandle : DWORD;
Found : BOOL;
PStruct : TProcessEntry32;
begin
Result := 0;
sphandle := CreateToolhelp32Snapshot($00000002, 0);
PStruct.dwSize := SizeOf(PStruct);
Found := Process32First(sphandle, PStruct);
while Found do
begin
if AnsiEndsText(ExeName, PStruct.szExeFile) then
begin
Result := PStruct.th32ProcessID;
Break;
end;
Found := Process32Next(sphandle, PStruct);
end;
CloseHandle(sphandle);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -