if checkradiobox1.Checked=true then //删除驱动备份文件
begin
ShellExecute(0, nil, 'CMD', '/c del C:\WINDOWS\Driver Cache\i386\*.* /q /f /a:r /a:s /a:h /a:a', nil, SW_Hide);
labe1.caption:='已经成功删除';
end;
........
比如说上面的DOS命令,我还有很多如果一点执行的话他会一下子开很多的CMD进程.去执行这些命令,即使他还没有删除完文件,labe1.caption:='已经成功删除';这个代码也会显示的
.而的想法是让他把命令彻底的运行完毕之后在去运行labe1.caption:='已经成功删除';段代码请问如何能实现,还有说用WinExec函数的我想让大帮我解释一下到底该怎么办
12 个解决方案
#1
winexec('mingling.bat',sw_show); 将你的DOS命令全部放在.bat文件里就可以了。
#2
UP樓上的......
#3
您的意思是我写一个程序,然后在编辑一个*.BAT文件 然后程序调用这个文件吗. 然后一共就是两个文件了是不是 . 但是我想用一个程序来实现 不想在多写个批处理,怎么办呢
#4
其实也无所谓 你把DOS命令行直接放进winexec里也可以了
#5
function WinExecAndWait32(FileName:String; Visibility : integer):integer;
var
zAppName:array[0..512] of char;
zCurDir:array[0..255] of char;
WorkDir:String;
StartupInfo:TStartupInfo;
ProcessInfo:TProcessInformation;
//MyResult:DWORD;
hStdIn:THandle; // standard input handle
//inputBuffer:INPUT_RECORD; //buffer to hold a single console input record
irMacroBuf:INPUT_RECORD; // array of input events
dwBytesWritten : DWORD;
begin
SetConsoleTitle('s');
StrPCopy(zAppName,FileName);
//form1.Caption := zappname;
GetDir(0,WorkDir);
StrPCopy(zCurDir,WorkDir);
FillChar(StartupInfo,Sizeof(StartupInfo),#0);
StartupInfo.cb := Sizeof(StartupInfo);
hStdIn:= StartupInfo.hStdInput;
StartupInfo.hStdInput:= hStdIn;
StartupInfo.lpTitle:=@zAppName;
StartupInfo.dwFlags := StartupInfo.dwFlags or STARTF_USESTDHANDLES;
//WriteConsoleInput(hStdIn,irMacroBuf,1,dwBytesWritten);
StartupInfo.dwFlags := StartupInfo.dwFlags or 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
WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
Result:=1;
end;
end;
var
zAppName:array[0..512] of char;
zCurDir:array[0..255] of char;
WorkDir:String;
StartupInfo:TStartupInfo;
ProcessInfo:TProcessInformation;
//MyResult:DWORD;
hStdIn:THandle; // standard input handle
//inputBuffer:INPUT_RECORD; //buffer to hold a single console input record
irMacroBuf:INPUT_RECORD; // array of input events
dwBytesWritten : DWORD;
begin
SetConsoleTitle('s');
StrPCopy(zAppName,FileName);
//form1.Caption := zappname;
GetDir(0,WorkDir);
StrPCopy(zCurDir,WorkDir);
FillChar(StartupInfo,Sizeof(StartupInfo),#0);
StartupInfo.cb := Sizeof(StartupInfo);
hStdIn:= StartupInfo.hStdInput;
StartupInfo.hStdInput:= hStdIn;
StartupInfo.lpTitle:=@zAppName;
StartupInfo.dwFlags := StartupInfo.dwFlags or STARTF_USESTDHANDLES;
//WriteConsoleInput(hStdIn,irMacroBuf,1,dwBytesWritten);
StartupInfo.dwFlags := StartupInfo.dwFlags or 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
WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
Result:=1;
end;
end;
#6
winexec('ping www.163.com -t',SW_SHOW);
caption:='ok';
我这样 执行还没完呢..下面的'ok'就出来了
质疑楼上的
caption:='ok';
我这样 执行还没完呢..下面的'ok'就出来了
质疑楼上的
#7
应该是楼上的楼上
#8
ShellExecute(handle, 'Open', PCHar(sWorkPath+'delfile.bat'), '', '', SW_hide);
你的delfile.bat文件
@echo off
c:
cd\
cd C:\WINDOWS\Driver Cache\i386
del *.*
你的delfile.bat文件
@echo off
c:
cd\
cd C:\WINDOWS\Driver Cache\i386
del *.*
#9
您的意思是我写一个程序,然后在编辑一个*.BAT文件 然后程序调用这个文件吗. 然后一共就是两个文件了是不是 . 但是我想用一个程序来实现 不想在多写个批处理,怎么办呢
----------------------------------------------
你就在程序里写一*BAT文件,然后再用winexec('mingling.bat',sw_show);
*BAT文件的格式如楼上所写的
----------------------------------------------
你就在程序里写一*BAT文件,然后再用winexec('mingling.bat',sw_show);
*BAT文件的格式如楼上所写的
#10
bat执行输出一个log文件,程序不停检查log文件,发现log文件输出完成,则cmd执行完毕,删掉log文件,这样程序继续执行下面的语句
-_-!
-_-!
#11
up.......
#12
方法1\好像记得shellexecute是个函数,后面有返回值的.可用这个返回值来做判断是否成功
2\在shellexecute前加try..finally..语句
3\用sendmessage来做
2\在shellexecute前加try..finally..语句
3\用sendmessage来做
#1
winexec('mingling.bat',sw_show); 将你的DOS命令全部放在.bat文件里就可以了。
#2
UP樓上的......
#3
您的意思是我写一个程序,然后在编辑一个*.BAT文件 然后程序调用这个文件吗. 然后一共就是两个文件了是不是 . 但是我想用一个程序来实现 不想在多写个批处理,怎么办呢
#4
其实也无所谓 你把DOS命令行直接放进winexec里也可以了
#5
function WinExecAndWait32(FileName:String; Visibility : integer):integer;
var
zAppName:array[0..512] of char;
zCurDir:array[0..255] of char;
WorkDir:String;
StartupInfo:TStartupInfo;
ProcessInfo:TProcessInformation;
//MyResult:DWORD;
hStdIn:THandle; // standard input handle
//inputBuffer:INPUT_RECORD; //buffer to hold a single console input record
irMacroBuf:INPUT_RECORD; // array of input events
dwBytesWritten : DWORD;
begin
SetConsoleTitle('s');
StrPCopy(zAppName,FileName);
//form1.Caption := zappname;
GetDir(0,WorkDir);
StrPCopy(zCurDir,WorkDir);
FillChar(StartupInfo,Sizeof(StartupInfo),#0);
StartupInfo.cb := Sizeof(StartupInfo);
hStdIn:= StartupInfo.hStdInput;
StartupInfo.hStdInput:= hStdIn;
StartupInfo.lpTitle:=@zAppName;
StartupInfo.dwFlags := StartupInfo.dwFlags or STARTF_USESTDHANDLES;
//WriteConsoleInput(hStdIn,irMacroBuf,1,dwBytesWritten);
StartupInfo.dwFlags := StartupInfo.dwFlags or 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
WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
Result:=1;
end;
end;
var
zAppName:array[0..512] of char;
zCurDir:array[0..255] of char;
WorkDir:String;
StartupInfo:TStartupInfo;
ProcessInfo:TProcessInformation;
//MyResult:DWORD;
hStdIn:THandle; // standard input handle
//inputBuffer:INPUT_RECORD; //buffer to hold a single console input record
irMacroBuf:INPUT_RECORD; // array of input events
dwBytesWritten : DWORD;
begin
SetConsoleTitle('s');
StrPCopy(zAppName,FileName);
//form1.Caption := zappname;
GetDir(0,WorkDir);
StrPCopy(zCurDir,WorkDir);
FillChar(StartupInfo,Sizeof(StartupInfo),#0);
StartupInfo.cb := Sizeof(StartupInfo);
hStdIn:= StartupInfo.hStdInput;
StartupInfo.hStdInput:= hStdIn;
StartupInfo.lpTitle:=@zAppName;
StartupInfo.dwFlags := StartupInfo.dwFlags or STARTF_USESTDHANDLES;
//WriteConsoleInput(hStdIn,irMacroBuf,1,dwBytesWritten);
StartupInfo.dwFlags := StartupInfo.dwFlags or 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
WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
Result:=1;
end;
end;
#6
winexec('ping www.163.com -t',SW_SHOW);
caption:='ok';
我这样 执行还没完呢..下面的'ok'就出来了
质疑楼上的
caption:='ok';
我这样 执行还没完呢..下面的'ok'就出来了
质疑楼上的
#7
应该是楼上的楼上
#8
ShellExecute(handle, 'Open', PCHar(sWorkPath+'delfile.bat'), '', '', SW_hide);
你的delfile.bat文件
@echo off
c:
cd\
cd C:\WINDOWS\Driver Cache\i386
del *.*
你的delfile.bat文件
@echo off
c:
cd\
cd C:\WINDOWS\Driver Cache\i386
del *.*
#9
您的意思是我写一个程序,然后在编辑一个*.BAT文件 然后程序调用这个文件吗. 然后一共就是两个文件了是不是 . 但是我想用一个程序来实现 不想在多写个批处理,怎么办呢
----------------------------------------------
你就在程序里写一*BAT文件,然后再用winexec('mingling.bat',sw_show);
*BAT文件的格式如楼上所写的
----------------------------------------------
你就在程序里写一*BAT文件,然后再用winexec('mingling.bat',sw_show);
*BAT文件的格式如楼上所写的
#10
bat执行输出一个log文件,程序不停检查log文件,发现log文件输出完成,则cmd执行完毕,删掉log文件,这样程序继续执行下面的语句
-_-!
-_-!
#11
up.......
#12
方法1\好像记得shellexecute是个函数,后面有返回值的.可用这个返回值来做判断是否成功
2\在shellexecute前加try..finally..语句
3\用sendmessage来做
2\在shellexecute前加try..finally..语句
3\用sendmessage来做