CreateProcess 问题 ( 积分: 100 )

  • 主题发起人 主题发起人 zgj_gd
  • 开始时间 开始时间
Z

zgj_gd

Unregistered / Unconfirmed
GUEST, unregistred user!
使用CreateProcess 时,一般在什么情况下返回失败?<br>我现在用CreateProcess 来调用 一个批处理文件(用来拷贝文件),<br>在一个窗口中,用CreateProcess 来调用批处理文件时,返回成功。<br>但将这段单位拷贝到另一个窗口后,CreateProcess 来调用另一个批处理文件时,返回失败。<br>我的代码:<br>var<br> &nbsp; lb_inherit,lb_success,ll_success: Boolean;<br> &nbsp;ls_appname,ls_commandLine: pchar;<br> &nbsp;ll_flags: int64;<br> &nbsp;lstr_startupinfo: startupinfo;<br> &nbsp;lstr_processinformation: process_information;<br> &nbsp;ll_hprocess,ll_exitcode: longword;<br>//处理的代码<br> &nbsp; &nbsp;ll_Success := FALSE;<br> &nbsp; &nbsp;ls_appname := pchar(sBatFile); //sBatFile 为批处理文件名<br> &nbsp; &nbsp;ls_commandline := pchar(sBatFile);<br> &nbsp; &nbsp;lb_inherit := FALSE;<br> &nbsp; &nbsp;ll_flags := 134217728; // 不显示窗口<br><br> &nbsp; &nbsp;lb_success := CreateProcess(ls_appname,ls_commandline,nil,nil,lb_inherit,ll_flags,nil,nil,lstr_startupinfo,lstr_processinformation);<br><br> &nbsp; &nbsp;if lb_success then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp;ll_hprocess := lstr_processinformation.hprocess;<br><br> &nbsp; &nbsp;repeat<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;sleep(1000);<br> &nbsp; &nbsp;ll_success := GetExitCodeProcess(ll_hprocess,ll_exitcode);<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;until ((ll_exitcode &lt;&gt; 259) or (ll_success = FALSE));<br> &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp;if ((lb_success = FALSE) or (ll_success = FALSE)) then<br> &nbsp; &nbsp;begin<br> ShowMessage('文件拷贝失败,请通知管理员!');<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exit;<br> &nbsp; &nbsp;end;<br><br>大家有没有封装好的调用CreateProcess 的函数?
 
使用CreateProcess 时,一般在什么情况下返回失败?<br>我现在用CreateProcess 来调用 一个批处理文件(用来拷贝文件),<br>在一个窗口中,用CreateProcess 来调用批处理文件时,返回成功。<br>但将这段单位拷贝到另一个窗口后,CreateProcess 来调用另一个批处理文件时,返回失败。<br>我的代码:<br>var<br> &nbsp; lb_inherit,lb_success,ll_success: Boolean;<br> &nbsp;ls_appname,ls_commandLine: pchar;<br> &nbsp;ll_flags: int64;<br> &nbsp;lstr_startupinfo: startupinfo;<br> &nbsp;lstr_processinformation: process_information;<br> &nbsp;ll_hprocess,ll_exitcode: longword;<br>//处理的代码<br> &nbsp; &nbsp;ll_Success := FALSE;<br> &nbsp; &nbsp;ls_appname := pchar(sBatFile); //sBatFile 为批处理文件名<br> &nbsp; &nbsp;ls_commandline := pchar(sBatFile);<br> &nbsp; &nbsp;lb_inherit := FALSE;<br> &nbsp; &nbsp;ll_flags := 134217728; // 不显示窗口<br><br> &nbsp; &nbsp;lb_success := CreateProcess(ls_appname,ls_commandline,nil,nil,lb_inherit,ll_flags,nil,nil,lstr_startupinfo,lstr_processinformation);<br><br> &nbsp; &nbsp;if lb_success then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp;ll_hprocess := lstr_processinformation.hprocess;<br><br> &nbsp; &nbsp;repeat<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;sleep(1000);<br> &nbsp; &nbsp;ll_success := GetExitCodeProcess(ll_hprocess,ll_exitcode);<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;until ((ll_exitcode &lt;&gt; 259) or (ll_success = FALSE));<br> &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp;if ((lb_success = FALSE) or (ll_success = FALSE)) then<br> &nbsp; &nbsp;begin<br> ShowMessage('文件拷贝失败,请通知管理员!');<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exit;<br> &nbsp; &nbsp;end;<br><br>大家有没有封装好的调用CreateProcess 的函数?
 
把你这段代码封装成函数
 
其中缺少聲明或引入部份。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
747
import
I
后退
顶部