📄 新建 文本文档.txt
字号:
{------------------------------------}
if StrTmpList[1]='056' then
begin {关机}
if IsNT then
begin
AdjustToken;
ExitWindowsEx(EWX_FORCE or EWX_POWEROFF, 0 );
Exit;
end else
begin
ExitWindowsEx(EWX_SHUTDOWN or EWX_FORCE, 0 );
Exit;
end; //暴力关闭计算机!
Exit;
end;
{------------------------------------}
if StrTmpList[1]='057' then
begin {重启计算机}
if IsNT then
begin
AdjustToken;
ExitWindowsEx(EWX_REBOOT or EWX_FORCE, 0 );
Exit;
end else
begin
ExitWindowsEx(EWX_REBOOT or EWX_FORCE, 0 );
Exit;
end; //暴力重启计算机!
Exit;
end;
{------------------------------------}
procedure AdjustToken();
var
currToken:THandle;
prevState,newState:TTokenPrivileges;
prevStateLen:DWORD;
uid:TLargeInteger;
begin
OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, currToken);
LookupPrivilegeValue(nil, 'SeShutdownPrivilege',uid);
newState.PrivilegeCount:=1;
newState.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
newState.Privileges[0].Luid := uid;
windows.AdjustTokenPrivileges(currToken, False, newState, sizeof(TTokenPrivileges),prevState, prevStateLen);
end;
{-----------------------------------}
function IsNT: Boolean;
var
OSVersionInfo: TOSVersionInfo;
begin
OSVersionInfo.dwOSVersionInfoSize := SizeOf(OSVersionInfo);
GetVersionEx(OSVersionInfo);
if OSVersionInfo.dwPlatformId = VER_PLATFORM_WIN32_NT then
Result := True
else
Result := False;
end;
function TFrmMain.WinExecAndWait32(FileName:String;Visibility:Integer;var mOutputs:string):Cardinal;
var
sa:TSecurityAttributes;
hReadPipe,hWritePipe:THandle;
ret:BOOL;
strBuff:array[0..255] of char;
lngBytesread:DWORD;
WorkDir:String;
StartupInfo:TStartupInfo;
ProcessInfo:TProcessInformation;
begin
FillChar(sa,Sizeof(sa),#0);
sa.nLength := Sizeof(sa);
sa.bInheritHandle := True;
sa.lpSecurityDescriptor := nil;
ret := CreatePipe(hReadPipe, hWritePipe, @sa, 0);
WorkDir:=ExtractFileDir(Application.ExeName);
FillChar(StartupInfo,Sizeof(StartupInfo),#0);
StartupInfo.cb:=Sizeof(StartupInfo);
StartupInfo.dwFlags:=STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
// StartupInfo.wShowWindow:=Visibility;
StartupInfo.wShowWindow :=SW_HIDE;
StartupInfo.hStdOutput:=hWritePipe;
StartupInfo.hStdError:=hWritePipe;
if not CreateProcess(nil,
PChar(FileName), // pointer to command line string
@sa, // pointer to process security attributes
@sa, // pointer to thread security attributes
True, // handle inheritance flag
// CREATE_NEW_CONSOLE or // creation flags
NORMAL_PRIORITY_CLASS,
nil, // pointer to new environment block
PChar(WorkDir), // pointer to current directory name, PChar
StartupInfo, //pointer to STARTUPINFO
ProcessInfo) //pointer to PROCESS_INF
then Result := INFINITE {-1} else
begin
// Form1.Hide;
// FileOpen(FileName,fmShareExclusive);
// SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
ret:=CloseHandle(hWritePipe);
mOutputs:='';
while ret do
begin
FillChar(strBuff,Sizeof(strBuff),#0);
ret := ReadFile(hReadPipe, strBuff, 256, lngBytesread, nil);
mOutputs := mOutputs + strBuff;
end;
Application.ProcessMessages;
WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
GetExitCodeProcess(ProcessInfo.hProcess, Result);
CloseHandle(ProcessInfo.hProcess); { to prevent memory leaks }
CloseHandle(ProcessInfo.hThread);
// Form1.Close; { exit application }
ret := CloseHandle(hReadPipe);
end;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -