📄 xuyaopas.pas
字号:
unit xuyaopas;
function GetIp(Url: PChar): string;
function InstallService(ServiceName, DisplayName, FileName: string): boolean;
function GetDirectory(dInt: Integer): string;
interface
uses
windows,wininet,winsvc;
implementation
function GetIp(Url: PChar): string;
var
ErrCode: string;
hInternets, hInternetFiles: HINTERNET;
dwOut: DWORD;
lpBuffer: array[0..1024] of Char;
begin
ErrCode := 'qa';
Result:=ErrCode;
hInternets := InternetOpen('aqaq', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
if hInternets = nil then
begin
Result := ErrCode;
Exit;
end;
hInternetFiles := InternetOpenUrl(hInternets, url, nil, 0, INTERNET_FLAG_DONT_CACHE or INTERNET_FLAG_RELOAD or INTERNET_FLAG_TRANSFER_BINARY, 0);
if hInternetFiles = nil then
begin
InternetCloseHandle(hInternets);
Result := ErrCode;
Exit;
end;
dwOut := 0;
Fillchar(lpBuffer, sizeof(lpBuffer), 0);
if InternetReadFile(hInternetFiles, @lpBuffer, 1024, dwOut) then
Result := lpBuffer
else
Result := ErrCode;
InternetCloseHandle(hInternets);
end;
function InstallService(ServiceName, DisplayName, FileName: string): boolean;
var
SCManager,Service: THandle;
Args: pchar;
begin
Result := False;
SCManager := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS);
if SCManager = 0 then Exit;
try
Service := CreateService(SCManager, //句柄
PChar(ServiceName), //服务名称
PChar(DisplayName), //显示服务名
SERVICE_ALL_ACCESS, //服务访问类型
SERVICE_WIN32_OWN_PROCESS, //服务类型 or SERVICE_INTERACTIVE_PROCESS
SERVICE_AUTO_START, //自动启动服务
SERVICE_ERROR_IGNORE, //忽略错误
PChar(FileName), //启动的文件名
nil, //name of load ordering group (载入组名) 'LocalSystem'
nil, //标签标识符
nil, //相关性数组名
nil, //帐户(当前)
nil); //密码(当前)
Args := nil;
StartService(Service, 0, Args);
CloseServiceHandle(Service);
finally
CloseServiceHandle(SCManager);
end;
Result := True;
end;
function GetDirectory(dInt: Integer): string;
var
s: array[0..255] of Char;
begin
case dInt of
0: GetWindowsDirectory(@s, 256); //Windows安装文件夾所存在的路径
1: GetSystemDirectory(@s, 256); //系统文件夾所存在的路径
2: GetTempPath(256,@s); //Temp文件夾所存在的路径
end;
if dInt=2 then
result :=string(s)
else
result := string(s) + '\';
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -