如何在我的程序中调用别的软件执行一个任务并在我的程序里把结果输出 如何在我的程序中调用别的软件执行一个任务并在我的程序里把结果输出(调用的软件对用户透明)(请写出原码)比如在win2000下调用任务管理器,并把其中的当前的进程输出的我的listview或是别的什么中 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //==============================================================================//运行DOS程序并返回它的输出*****************************************************//==============================================================================function GetDOSResult(const CommandLine: string; var ExitCode: DWORD): string; overload; procedure CheckResult(Bool: Boolean); begin if not Bool then raise Exception.Create(SysErrorMessage(GetLastError)); end;var ProceInfo: TProcessInformation; SecuAttr: TSecurityAttributes; StartInfo: TStartupInfo; HRead, HWrite: THandle; WriteStream: TStrings; inS: THandleStream; fSuccess: Boolean;begin Result := ''; FillChar(SecuAttr,sizeof(SecuAttr),0); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //设置允许继承,否则在NT和2000下无法取得输出结果******************************* //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SecuAttr.nLength := SizeOf(SecuAttr); SecuAttr.bInheritHandle := true; SecuAttr.lpSecurityDescriptor := nil; fSuccess := CreatePipe(HRead,HWrite,@SecuAttr,0); CheckResult(fSuccess); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FillChar(StartInfo,SizeOf(StartInfo),0); StartInfo.cb := SizeOf(StartInfo); StartInfo.wShowWindow := SW_HIDE; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //使用指定的句柄作为标准输入输出的文件句柄,使用指定的显示方式 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ StartInfo.dwFlags := STARTF_USESTDHANDLES+STARTF_USESHOWWINDOW; StartInfo.hStdError := HWrite; StartInfo.hStdInput := GetStdHandle(STD_INPUT_HANDLE);//HRead; StartInfo.hStdOutput := HWrite; fSuccess := CreateProcess(nil,PChar(CommandLine),nil,nil,true,CREATE_NEW_CONSOLE,nil,nil,StartInfo,ProceInfo); CheckResult(fSuccess); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ WaitForSingleObject(ProceInfo.hProcess,INFINITE); GetExitCodeProcess(ProceInfo.hProcess,ExitCode); inS := THandleStream.Create(HRead); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if inS.Size>0 then begin WriteStream := TStringList.Create; WriteStream.LoadFromStream(inS); Result := WriteStream.Text; WriteStream.Free; end; inS.Free; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CloseHandle(HRead); CloseHandle(HWrite);end;example:var ExitCode: DWORDbegin Memo.Lines.Clear; Memo.Text := GetDOSResult('ping.exe 192.168.1.11', ExitCode);end; delphi 网页提取数据 listview 里的checkboxes有没有叉叉? 请教一事务处理问题? 如何远程访问数据库 事务处理的问题 如何获得TPopupMenu的弹出对象! 有关DBGridEh中复选框的问题 求CDMA的资料,中文最好~~~~~~~~~ 100分求一个来电显示的代码,我用的是内猫,感谢, 如何使用delphi访问oracle中的海量数据? while循环是否可以求得循环次数吗? 用delphi自带的mediaplayer做的程序无法在别人的系统上运行?
//运行DOS程序并返回它的输出*****************************************************
//==============================================================================
function GetDOSResult(const CommandLine: string; var ExitCode: DWORD): string; overload;
procedure CheckResult(Bool: Boolean);
begin
if not Bool then raise Exception.Create(SysErrorMessage(GetLastError));
end;
var ProceInfo: TProcessInformation;
SecuAttr: TSecurityAttributes;
StartInfo: TStartupInfo;
HRead, HWrite: THandle;
WriteStream: TStrings;
inS: THandleStream;
fSuccess: Boolean;
begin
Result := '';
FillChar(SecuAttr,sizeof(SecuAttr),0);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//设置允许继承,否则在NT和2000下无法取得输出结果*******************************
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SecuAttr.nLength := SizeOf(SecuAttr);
SecuAttr.bInheritHandle := true;
SecuAttr.lpSecurityDescriptor := nil;
fSuccess := CreatePipe(HRead,HWrite,@SecuAttr,0);
CheckResult(fSuccess);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FillChar(StartInfo,SizeOf(StartInfo),0);
StartInfo.cb := SizeOf(StartInfo);
StartInfo.wShowWindow := SW_HIDE;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//使用指定的句柄作为标准输入输出的文件句柄,使用指定的显示方式
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
StartInfo.dwFlags := STARTF_USESTDHANDLES+STARTF_USESHOWWINDOW;
StartInfo.hStdError := HWrite;
StartInfo.hStdInput := GetStdHandle(STD_INPUT_HANDLE);//HRead;
StartInfo.hStdOutput := HWrite;
fSuccess := CreateProcess(nil,PChar(CommandLine),nil,nil,true,CREATE_NEW_CONSOLE,nil,nil,StartInfo,ProceInfo);
CheckResult(fSuccess);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
WaitForSingleObject(ProceInfo.hProcess,INFINITE);
GetExitCodeProcess(ProceInfo.hProcess,ExitCode);
inS := THandleStream.Create(HRead);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if inS.Size>0 then
begin
WriteStream := TStringList.Create;
WriteStream.LoadFromStream(inS);
Result := WriteStream.Text;
WriteStream.Free;
end;
inS.Free;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CloseHandle(HRead);
CloseHandle(HWrite);
end;
example:
var ExitCode: DWORD
begin
Memo.Lines.Clear;
Memo.Text := GetDOSResult('ping.exe 192.168.1.11', ExitCode);
end;