怎样判断winexec调用的命令已经执行完成了?

greating 2003-12-02 09:38:37
我使用winexec(pchar(...),sw_hide)执行一个DOS命令,如何知道这个命令已经执行完成了?
...全文
278 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
greating 2003-12-09
  • 打赏
  • 举报
回复
xiangwangz兄的方法不可行,因为RETURN返回的值在程序开始时,而我是要知道程序什么时候结束,当然不行。
angelface 2003-12-07
  • 打赏
  • 举报
回复
XUEXI...
selfboss 2003-12-05
  • 打赏
  • 举报
回复
GZ
xiangwangz 2003-12-05
  • 打赏
  • 举报
回复
我倒是觉得楼主的问题可以解决:
//对于 WinExec
If the function succeeds, the return value is greater than 31.
If the function fails, the return value is one of the following error values:

Value Meaning
0 The system is out of memory or resources.
ERROR_BAD_FORMAT The .EXE file is invalid (non-Win32 .EXE or error in .EXE image).
ERROR_FILE_NOT_FOUND The specified file was not found.

procedure TForm1.Button1Click(Sender: TObject);
var ReTurn:Integer;
begin
ReTurn:=winexec(pchar('command.com /C '+'net view '+' >'+'c:\xinxi.txt'),sw_hide);
if ReTurn>31 then
begin
if not fileexists('c:\xinxi.txt') then
sleep(100)
else
memo1.Lines.LoadFromFile('c:\xinxi.txt');
end;
end;//既然你都能把结果给得到了,还你能判断妈 /?
greating 2003-12-05
  • 打赏
  • 举报
回复
我试了ly_liuyang函数,不能满足需要,主要是我执行的是NETSH命令,无法如何该函数运行时都没有办法隐藏cmd对话框。
我想直接判断netsh.exe是否在进程中是否可以,如何判断,请教。
如果进程中存在,如何等待直到进程执行完,再执行下一条命令?
jerrymousenet2 2003-12-04
  • 打赏
  • 举报
回复
function WinExecAndWait(strFileName: string; uCmdShow: UINT): DWORD;
var
cAppName: array [0..512] of char;
cCurDir: array [0..255] of char;
strWorkDir: string;
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
begin
StrPCopy(cAppName, strFileName);
GetDir(0, strWorkDir);
StrPCopy(cCurDir, strWorkDir);
FillChar(StartupInfo, Sizeof(StartupInfo), #0);
StartupInfo.cb := SizeOf(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := uCmdShow;
if not CreateProcess(nil, cAppName, nil, nil, true, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS,
nil, nil, StartupInfo, ProcessInfo) then
Result := INFINITE
else
begin
WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
GetExitCodeProcess(ProcessInfo.hProcess, Result);
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
end;
end;
d0347 2003-12-04
  • 打赏
  • 举报
回复
Up
ly_liuyang 2003-12-03
  • 打赏
  • 举报
回复
WinExec是不能的,用下面的Code了

function TExecForm.Exec(FileName: string; Visibility: integer): integer;
var
zappname:array [0..512] of char;
zcurdir:array [0..255] of char;
workdir:string;
startupinfo:tstartupinfo;
processinfo:tprocessinformation;
exitcode:cardinal;
begin
strpcopy(zappname,filename);
getdir(0,workdir);
strpcopy(zcurdir,workdir);
fillchar(startupinfo,sizeof(startupinfo),#0);
startupinfo.cb:=sizeof(startupinfo);
startupinfo.wShowWindow:=visibility;
if not createprocess(nil,zappname,nil,nil,false,create_new_console or Normal_priority_class,
nil,nil,startupinfo,processinfo) then result:=-1
else begin
waitforsingleobject(processinfo.hProcess,infinite);
getexitcodeprocess(processinfo.hProcess,exitcode);
result:=exitcode;
end;
end;

procedure TExecForm.ExecuteClick(Sender: TObject);
var h:thandle;
begin
exec(exename.Text,0);
showmessage('Ruturn');
end;
nzh517 2003-12-03
  • 打赏
  • 举报
回复
用这个函数好象有些难办,你试试用别的函数调用执行其它程序如:CreateProcess
sailer_shi 2003-12-03
  • 打赏
  • 举报
回复
执行完winexec后判断最上面的窗体的handle的名称是不是你想要得应用程序的handle的名称
Behard 2003-12-03
  • 打赏
  • 举报
回复
char *buff = new char[256] ;
StrCopy ( buff, "Project1.exe" ) ;
SHELLEXECUTEINFO ExeInfo;
// Animate1->Active=true;
ZeroMemory(&ExeInfo,sizeof( SHELLEXECUTEINFO));
ExeInfo.cbSize = sizeof( SHELLEXECUTEINFO);
ExeInfo.lpFile = buff;
ExeInfo.fMask = SEE_MASK_NOCLOSEPROCESS ;
ExeInfo.nShow = SW_MAXIMIZE;//SW_HIDE;
ShellExecuteEx(&ExeInfo);
delete []buff ;
this->Hide();
WaitForSingleObject(ExeInfo.hProcess,INFINITE);
this->Show();
API之网络函数1. API之网络函数 WNetAddConnection 创建同一个网络资源的永久性连接 WNetAddConnection2 创建同一个网络资源的连接 WNetAddConnection3 创建同一个网络资源的连接 WNetCancelConnection 结束一个网络连接 WNetCancelConnection2 结束一个网络连接 WNetCloseEnum 结束一次枚举操作 WNetConnectionDialog 启动一个标准对话框,以便建立同网络资源的连接 WNetDisconnectDialog 启动一个标准对话框,以便断开同网络资源的连接 WNetEnumResource 枚举网络资源 WNetGetConnection 获取本地或已连接的一个资源的网络名称 WNetGetLastError 获取网络错误的扩展错误信息 WNetGetUniversalName 获取网络中一个文件的远程名称以及/或者UNC(统一命名规范)名称 WNetGetUser 获取一个网络资源用以连接的名字 WNetOpenEnum 启动对网络资源进行枚举的过程 2. API之消息函数 BroadcastSystemMessage 将一条系统消息广播给系统中所有的顶级窗口 GetMessagePos 取得消息队列中上一条消息处理完毕时的鼠标指针屏幕位置 GetMessageTime 取得消息队列中上一条消息处理完毕时的时间 PostMessage 将一条消息投递到指定窗口的消息队列 PostThreadMessage 将一条消息投递给应用程序 RegisterWindowMessage 获取分配给一个字串标识符的消息编号 ReplyMessage 答复一个消息 SendMessage 调用一个窗口的窗口函数,将一条消息发给那个窗口 SendMessageCallback 将一条消息发给窗口 SendMessageTimeout 向窗口发送一条消息 SendNotifyMessage 向窗口发送一条消息 3. API之文件处理函数 CloseHandle 关闭一个内核对象。其中包括文件、文件映射、进程、线程、安全和同步对象等 CompareFileTime 对比两个文件的时间 CopyFile 复制文件 CreateDirectory 创建一个新目录 CreateFile 打开和创建文件、管道、邮槽、通信服务、设备以及控制台 CreateFileMapping 创建一个新的文件映射对象 DeleteFile 删除指定文件 DeviceIoControl 对设备执行指定的操作 DosDateTimeToFileTime 将DOS日期和时间值转换成一个 win32 FILETIME 值 FileTimeToDosDateTime 将一个 win32 FILETIME 值转换成DOS日期和时间值 FileTimeToLocalFileTime 将一个FILETIME结构转换成本地时间 FileTimeToSystemTime 根据一个FILETIME结构的内容,装载一个SYSTEMTIME结构 FindClose 关闭由FindFirstFile函数创建的一个搜索句柄 FindFirstFile 根据文件名查找文件 FindNextFile 根据调用FindFirstFile函数时指定的一个文件名查找下一个文件 FlushFileBuffers 针对指定的文件句柄,刷新内部文件缓冲区 FlushViewOfFile 将写入文件映射缓冲区的所有数据都刷新到磁盘 GetBinaryType 判断文件是否可以执行 GetCompressedFileSize 判断一个压缩文件在磁盘上实际占据的字节数 GetCurrentDirectory 在一个缓冲区中装载当前目录 GetDiskFreeSpace 获取与一个磁盘的组织有关的信息,以及了解剩余空间的容量 GetDiskFreeSpaceEx 获取与一个磁盘的组织以及剩余空间容量有关的信息 GetDriveType 判断一个磁盘驱动器的类型 GetExpandedName 取得一个压缩文件的全名 GetFileAttributes 判断指定文件的属性 GetFileInformationByHandle 这个函数提供了获取文件信息的一种机制 GetFileSize 判断文件长度 GetFileTime 取得指定文件的时间信息 GetFileType 在给出文件句柄的前提下,判断文件类型 GetFileVersionInfo 从支持版本标记的一个模块里获取文件版本信息

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧