下面隐藏一个程序,并使他从任务列表中消失。
TStartupInfo 这个结构中有一个 sShowWindow 栏位, 将之设为 SW_HIDE即可,
同时, dwFlags 标志中至少需含有 STARTF_USESHOWWINDOW, 否则CreateProcess
时, sShowWindow 栏位的设定会无效:
var
sCommandLine: string;
bCreateProcess: boolean;
lpStartupInfo: TStartupInfo;
lpProcessInformation: TProcessInformation;
begin
// sCommandLine 的内容请视您的情况修改
sCommandLine :='Xcopy d:/temp/temp1/*.* d:/temp/temp2 /v/y';
lpStartupInfo.dwFlags := STARTF_USESHOWWINDOW;
lpStartupInfo.wShowWindow := SW_HIDE;
bCreateProcess := CreateProcess(nil, PChar(sCommandLine),nil,nil,True,
HIGH_PRIORITY_CLASS, nil, nil,lpStartupInfo, lpProcessInformation);
if bCreateProcess then
begin
WaitForSingleObject(lpProcessInformation.hProcess, INFINITE);
RegisterServiceProcess(lpProcessInfomation.hprocess,RSP_SIMPLE_SERVICE);//从任务列表中隐藏
end;
end;