如何实现在运行输入框中执行语句的效果 开始—运行—输入cmd—回车。然后在窗口中输入如下命令:regsvr32 "c:\winnt\system32\a.dll"想通过DELPHI代码实现 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 winexec('regsvr32 c:\winnt\system32\a.dll',sw_show); //unit CnCommon;{* |<PRE>================================================================================* 软件名称:开发包基础库* 单元名称:公共运行基础库单元* 单元作者:CnPack开发组* 备 注:该单元定义了组件包的基础类库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 }// 用管道方式在 Dir 目录执行 CmdLine,Output 返回输出信息,// dwExitCode 返回退出码。如果成功返回 Truefunction 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; delphi中怎么上传附件啊 Delphi调用gd库演示 按钮控件的问题(超简单) 改变GroupBoxRates.Controls[i]顺序问题 问一个小问题,在线等,马上给分 Web Service页里找不到WSDL Importer怎么办? 本人想开发一个程序,支持网上升级功能 有和java通用的des加密吗? 菜单问题,求求帮忙,在线等,帮帮忙! 用query查询,如何只显示刚刚才创建的那条记录,铁定给分 谁有多媒体控件 设置固定长度字符串,没有字符的都填充为空格,怎么实现啊?
{* |<PRE>
================================================================================
* 软件名称:开发包基础库
* 单元名称:公共运行基础库单元
* 单元作者:CnPack开发组
* 备 注:该单元定义了组件包的基础类库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 }
// 用管道方式在 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;