Batch File ExampleThe example below shows how to check for a specific error level using a DOS Batch file: @ECHO OFF DFC.EXE get /isfrozen IF Errorlevel 5 GOTO Error5 IF Errorlevel 4 GOTO Error4 IF Errorlevel 3 GOTO Error3 IF Errorlevel 2 GOTO Error2 IF Errorlevel 1 GOTO Error1 IF Errorlevel 0 GOTO Error0:Error5 Echo Errorlevel 5 Goto END:Error4 Echo Errorlevel 4 Goto END:Error3 Echo Errorlevel 3 Goto END:Error2 Echo Errorlevel 2 Goto END:Error1 Echo Errorlevel 1 Goto END:Error0 Echo Errorlevel 0 Goto END:ENDActions can be placed between the ECHO Errorlevel # statement and the Goto END statement for each of the detected error levels. To use this Batch file to automatically Thaw a Frozen workstation, the following section of the Batch file would have to changed: :Error1 Echo Errorlevel 1 DFC.EXE password /BOOTTHAWED EchoGoto END 这个DFC.exe是这样用的
cnpack是什么啊?CnPack 开放源码 IDE 专家包发布 0.7.5 版-...这个吗??
{* 运行一个文件并立即返回 }function WinExecAndWait32(FileName: string; Visibility: Integer = SW_NORMAL;
ProcessMsg: Boolean = False): Integer;
{* 运行一个文件并等待其结束}function WinExecWithPipe(const CmdLine, Dir: string; slOutput: TStrings;
var dwExitCode: Cardinal): Boolean; overload;
function WinExecWithPipe(const CmdLine, Dir: string; var Output: string;
var dwExitCode: Cardinal): Boolean; overload;
{* 用管道方式在 Dir 目录执行 CmdLine,Output 返回输出信息,
dwExitCode 返回退出码。如果成功返回 True }
---
// 运行一个文件并立即返回
function WinExecute(FileName: string; Visibility: Integer = SW_NORMAL): Boolean;
var
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
begin
FillChar(StartupInfo, SizeOf(StartupInfo), #0);
StartupInfo.cb := SizeOf(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := Visibility;
Result := CreateProcess(nil, PChar(FileName), nil, nil, False,
CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo,
ProcessInfo);
end;// 运行一个文件并等待其结束
function WinExecAndWait32(FileName: string; Visibility: Integer;
ProcessMsg: Boolean): Integer;
var
zAppName: array[0..512] of Char;
zCurDir: array[0..255] of Char;
WorkDir: string;
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
begin
StrPCopy(zAppName, FileName);
GetDir(0, WorkDir);
StrPCopy(zCurDir, WorkDir);
FillChar(StartupInfo, SizeOf(StartupInfo), #0);
StartupInfo.cb := SizeOf(StartupInfo); StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := Visibility;
if not CreateProcess(nil,
zAppName, { pointer to command line string }
nil, { pointer to process security attributes }
nil, { pointer to thread security attributes }
False, { handle inheritance flag }
CREATE_NEW_CONSOLE or { creation flags }
NORMAL_PRIORITY_CLASS,
nil, { pointer to new environment block }
nil, { pointer to current directory name }
StartupInfo, { pointer to STARTUPINFO }
ProcessInfo) then
Result := -1 { pointer to PROCESS_INF }
else
begin
if ProcessMsg then
begin
repeat
Application.ProcessMessages;
GetExitCodeProcess(ProcessInfo.hProcess, Cardinal(Result));
until (Result <> STILL_ACTIVE) or Application.Terminated;
end
else
begin
WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
GetExitCodeProcess(ProcessInfo.hProcess, Cardinal(Result));
end;
end;
end;// 用管道方式在 Dir 目录执行 CmdLine,Output 返回输出信息,
// dwExitCode 返回退出码。如果成功返回 True
function WinExecWithPipe(const CmdLine, Dir: string; slOutput: TStrings;
var dwExitCode: Cardinal): Boolean;
var
HOutRead, HOutWrite: THandle;
StartInfo: TStartupInfo;
ProceInfo: TProcessInformation;
sa: TSecurityAttributes;
InStream: THandleStream;
strTemp: string;
PDir: PChar; procedure ReadLinesFromPipe(IsEnd: Boolean);
var
s: string;
ls: TStringList;
i: Integer;
begin
if InStream.Position < InStream.Size then
begin
SetLength(s, InStream.Size - InStream.Position);
InStream.Read(PChar(s)^, InStream.Size - InStream.Position);
strTemp := strTemp + s;
ls := TStringList.Create;
try
ls.Text := strTemp;
for i := 0 to ls.Count - 2 do
slOutput.Add(ls[i]);
strTemp := ls[ls.Count - 1];
finally
ls.Free;
end;
end; if IsEnd and (strTemp <> '') then
begin
slOutput.Add(strTemp);
strTemp := '';
end;
end;
begin
dwExitCode := 0;
Result := False;
try
FillChar(sa, sizeof(sa), 0);
sa.nLength := sizeof(sa);
sa.bInheritHandle := True;
sa.lpSecurityDescriptor := nil;
InStream := nil;
strTemp := '';
HOutRead := INVALID_HANDLE_VALUE;
HOutWrite := INVALID_HANDLE_VALUE;
try
Win32Check(CreatePipe(HOutRead, HOutWrite, @sa, 0)); FillChar(StartInfo, SizeOf(StartInfo), 0);
StartInfo.cb := SizeOf(StartInfo);
StartInfo.wShowWindow := SW_HIDE;
StartInfo.dwFlags := STARTF_USESTDHANDLES + STARTF_USESHOWWINDOW;
StartInfo.hStdError := HOutWrite;
StartInfo.hStdInput := GetStdHandle(STD_INPUT_HANDLE);
StartInfo.hStdOutput := HOutWrite; InStream := THandleStream.Create(HOutRead); if Dir <> '' then
PDir := PChar(Dir)
else
PDir := nil;
Win32Check(CreateProcess(nil, //lpApplicationName: PChar
PChar(CmdLine), //lpCommandLine: PChar
nil, //lpProcessAttributes: PSecurityAttributes
nil, //lpThreadAttributes: PSecurityAttributes
True, //bInheritHandles: BOOL
NORMAL_PRIORITY_CLASS, //CREATE_NEW_CONSOLE,
nil,
PDir,
StartInfo,
ProceInfo)); while WaitForSingleObject(ProceInfo.hProcess, 100) = WAIT_TIMEOUT do
begin
ReadLinesFromPipe(False);
Application.ProcessMessages;
//if Application.Terminated then break;
end;
ReadLinesFromPipe(True); GetExitCodeProcess(ProceInfo.hProcess, dwExitCode); CloseHandle(ProceInfo.hProcess);
CloseHandle(ProceInfo.hThread); Result := True;
finally
if InStream <> nil then InStream.Free;
if HOutRead <> INVALID_HANDLE_VALUE then CloseHandle(HOutRead);
if HOutWrite <> INVALID_HANDLE_VALUE then CloseHandle(HOutWrite);
end;
except
;
end;
end;function WinExecWithPipe(const CmdLine, Dir: string; var Output: string;
var dwExitCode: Cardinal): Boolean;
var
slOutput: TStringList;
begin
slOutput := TStringList.Create;
try
Result := WinExecWithPipe(CmdLine, Dir, slOutput, dwExitCode);
Output := slOutput.Text;
finally
slOutput.Free;
end;
end;
后面加 '>' 可以输出到 文件
unit CnCommon;
* 软件名称:开发包基础库
* 单元名称:公共运行基础库单元
* 单元作者:CnPack开发组
* 备 注:该单元定义了组件包的基础类库
* 开发平台:PWin98SE + Delphi 5.0
* 兼容测试:PWin9X/2000/XP + Delphi 5/6
* 本 地 化:该单元中的字符串均符合本地化处理方式
* 单元标识:$Id: CnCommon.pas,v 1.39 2006/08/12 08:37:48 passion Exp $
@ECHO OFF
DFC.EXE get /isfrozen
IF Errorlevel 5 GOTO Error5
IF Errorlevel 4 GOTO Error4
IF Errorlevel 3 GOTO Error3
IF Errorlevel 2 GOTO Error2
IF Errorlevel 1 GOTO Error1
IF Errorlevel 0 GOTO Error0:Error5
Echo Errorlevel 5
Goto END:Error4
Echo Errorlevel 4
Goto END:Error3
Echo Errorlevel 3
Goto END:Error2
Echo Errorlevel 2
Goto END:Error1
Echo Errorlevel 1
Goto END:Error0
Echo Errorlevel 0
Goto END:ENDActions can be placed between the ECHO Errorlevel # statement and the Goto END statement for each of the detected error levels. To use this Batch file to automatically Thaw a Frozen workstation, the following section of the Batch file would have to changed:
:Error1
Echo Errorlevel 1
DFC.EXE password /BOOTTHAWED
EchoGoto END
这个DFC.exe是这样用的
反复调用的话 追加 最后分析