CreateProcess创建进程时,是否支持 长字符 命令(200分)

  • 主题发起人 主题发起人 520zhuhaibo
  • 开始时间 开始时间
5

520zhuhaibo

Unregistered / Unconfirmed
GUEST, unregistred user!
Procedure ShellExecute_Windows(ASign: Integer; Const ACmdStr: String);<br>Var<br>&nbsp; AppName: Array[0..512] Of char;<br>&nbsp; wCmdStr: String;<br>&nbsp; StartupInfo: TStartupInfo;<br>&nbsp; ProcessInfo: TProcessInformation;<br>Begin<br>&nbsp; wCmdStr := Trim(ACmdStr);<br>&nbsp; If wCmdStr &lt;&gt; '' Then<br>&nbsp; Begin<br>&nbsp; &nbsp; StrPCopy(AppName,wCmdStr);<br><br>&nbsp; &nbsp; {建立进程并等待其结束}<br>&nbsp; &nbsp; Fillchar(StartupInfo, Sizeof(StartupInfo), #0);<br><br>&nbsp; &nbsp; With StartupInfo Do<br>&nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; cb := sizeof(StartupInfo);<br>&nbsp; &nbsp; &nbsp; dwFlags := StartF_UsesTDHandles Or STARTF_USESHOWWINDOW;<br>&nbsp; &nbsp; &nbsp; lptitle := Nil;<br>&nbsp; &nbsp; &nbsp; wShowWindow := SW_SHOWNORMAL;<br>&nbsp; &nbsp; End;<br><br>&nbsp; &nbsp; If CreateProcess(Nil,<br>&nbsp; &nbsp; &nbsp; AppName, { pointer to command line string }<br>&nbsp; &nbsp; &nbsp; Nil, { pointer to process security attributes }<br>&nbsp; &nbsp; &nbsp; Nil, { pointer to thread security attributes }<br>&nbsp; &nbsp; &nbsp; False, { handle inheritance flag }<br>&nbsp; &nbsp; &nbsp; CREATE_NEW_CONSOLE Or NORMAL_PRIORITY_CLASS, { creation flags }<br>&nbsp; &nbsp; &nbsp; Nil, { pointer to new environment block }<br>&nbsp; &nbsp; &nbsp; Nil, { pointer to current directory name }<br>&nbsp; &nbsp; &nbsp; StartupInfo, { pointer to STARTUPINFO }<br>&nbsp; &nbsp; &nbsp; ProcessInfo) Then<br>&nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; With ProcessInfo Do<br>&nbsp; &nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; &nbsp; If ASign = 0 Then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WaitForSingleObject(hProcess, INFINITE);<br>&nbsp; &nbsp; &nbsp; &nbsp; CloseHandle(hThread);<br>&nbsp; &nbsp; &nbsp; &nbsp; CloseHandle(hProcess);<br>&nbsp; &nbsp; &nbsp; End;<br>&nbsp; &nbsp; End;<br>&nbsp; End<br>&nbsp; Else<br>&nbsp; &nbsp; ExitWindowsEx(ASign, 0);<br>End;<br><br>调试时:<br>1、当ACmdStr为'D:/SOUND_CODE/系统注册/*.exe'就会报错<br>2、当ACmdStr为'D:/SOUND_CODE/*.exe'就正常<br>请各们大侠帮帮小弟了,在线!<br>QQ:66082594
 
試試第二個參數為:PChar(wCmdStr)會怎麼樣。
 
我原本就是那样,但没用呀!
 
你要實現什麼?
 
当当ACmdStr为'D:/SOUND_CODE/系统注册/*.exe',甚至更长也不会报错呀
 
試試:<br>Procedure ShellExecute_Windows(ASign: Integer; Const ACmdStr: String);<br>Var<br>&nbsp; AppName: Array[0..512] Of char;<br>&nbsp; wCmdStr: String;<br>&nbsp; StartupInfo: TStartupInfo;<br>&nbsp; ProcessInfo: TProcessInformation;<br>Begin<br>&nbsp; wCmdStr := Trim(ACmdStr);<br>&nbsp; If wCmdStr &lt;&gt; '' Then<br>&nbsp; Begin<br>&nbsp; &nbsp; StrPCopy(AppName,wCmdStr);<br><br>&nbsp; &nbsp; {建立进程并等待其结束}<br>&nbsp; &nbsp; Fillchar(StartupInfo, Sizeof(StartupInfo), #0);<br><br>&nbsp; &nbsp; With StartupInfo Do<br>&nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; cb := sizeof(StartupInfo);<br>&nbsp; &nbsp; &nbsp; dwFlags := StartF_UsesTDHandles Or STARTF_USESHOWWINDOW;<br>&nbsp; &nbsp; &nbsp; lptitle := Nil;<br>&nbsp; &nbsp; &nbsp; wShowWindow := SW_SHOWNORMAL;<br>&nbsp; &nbsp; End;<br><br>&nbsp; &nbsp; If CreateProcess(AppName, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// &lt;---<br>&nbsp; &nbsp; &nbsp; Nil, { pointer to command line string } &nbsp;// &lt;---<br>&nbsp; &nbsp; &nbsp; Nil, { pointer to process security attributes }<br>&nbsp; &nbsp; &nbsp; Nil, { pointer to thread security attributes }<br>&nbsp; &nbsp; &nbsp; False, { handle inheritance flag }<br>&nbsp; &nbsp; &nbsp; CREATE_NEW_CONSOLE Or NORMAL_PRIORITY_CLASS, { creation flags }<br>&nbsp; &nbsp; &nbsp; Nil, { pointer to new environment block }<br>&nbsp; &nbsp; &nbsp; Nil, { pointer to current directory name }<br>&nbsp; &nbsp; &nbsp; StartupInfo, { pointer to STARTUPINFO }<br>&nbsp; &nbsp; &nbsp; ProcessInfo) Then<br>&nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; With ProcessInfo Do<br>&nbsp; &nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; &nbsp; If ASign = 0 Then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WaitForSingleObject(hProcess, INFINITE);<br>&nbsp; &nbsp; &nbsp; &nbsp; CloseHandle(hThread);<br>&nbsp; &nbsp; &nbsp; &nbsp; CloseHandle(hProcess);<br>&nbsp; &nbsp; &nbsp; End;<br>&nbsp; &nbsp; End;<br>&nbsp; End<br>&nbsp; Else<br>&nbsp; &nbsp; ExitWindowsEx(ASign, 0);<br>End;<br>
 
行是行了,可是如果注册OCX<br>ACmdStr:='regsvr32.exe ' + SystemVar + '/vgctrl40.ocx'<br>就不行了,请指教
 
当然支持<br>我的捆绑机在某些情况下会 调用CreateProcess 并等待其一一结束 <br>当然,文件名会夹杂中文或其他符号 &nbsp;[:D]
 
&nbsp;注意 , 给参数直接 pchar(字符串:string) 即可。<br>如果想给参数 而不是简单的exe路径 应该给第二个参数pchar(字符串:string) ,第一个空着。<br>============<br>&nbsp; &nbsp; LPCTSTR lpApplicationName, // pointer to name of executable module <br>&nbsp; &nbsp; LPTSTR lpCommandLine, // pointer to command line string
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=2616942
 
lpCommandLine用於存放執行文件運行參數的,你試試:<br>Procedure ShellExecute_Windows(ASign: Integer; Const ACmdStr, AParamStr: string); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// &lt;--- NEW<br>Var<br>&nbsp; AppName: Array[0..512] Of char;<br>&nbsp; wCmdStr: String;<br>&nbsp; StartupInfo: TStartupInfo;<br>&nbsp; ProcessInfo: TProcessInformation;<br>Begin<br>&nbsp; wCmdStr := Trim(ACmdStr);<br>&nbsp; If wCmdStr &lt;&gt; '' Then<br>&nbsp; Begin<br>&nbsp; &nbsp; StrPCopy(AppName,wCmdStr);<br><br>&nbsp; &nbsp; {建立进程并等待其结束}<br>&nbsp; &nbsp; Fillchar(StartupInfo, Sizeof(StartupInfo), #0);<br><br>&nbsp; &nbsp; With StartupInfo Do<br>&nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; cb := sizeof(StartupInfo);<br>&nbsp; &nbsp; &nbsp; dwFlags := StartF_UsesTDHandles Or STARTF_USESHOWWINDOW;<br>&nbsp; &nbsp; &nbsp; lptitle := Nil;<br>&nbsp; &nbsp; &nbsp; wShowWindow := SW_SHOWNORMAL;<br>&nbsp; &nbsp; End;<br><br>&nbsp; &nbsp; If CreateProcess(AppName, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &lt;---<br>&nbsp; &nbsp; &nbsp; PChar(AParamStr), { pointer to command line string } &nbsp;// &lt;---NEW<br>&nbsp; &nbsp; &nbsp; Nil, { pointer to process security attributes }<br>&nbsp; &nbsp; &nbsp; Nil, { pointer to thread security attributes }<br>&nbsp; &nbsp; &nbsp; False, { handle inheritance flag }<br>&nbsp; &nbsp; &nbsp; CREATE_NEW_CONSOLE Or NORMAL_PRIORITY_CLASS, { creation flags }<br>&nbsp; &nbsp; &nbsp; Nil, { pointer to new environment block }<br>&nbsp; &nbsp; &nbsp; Nil, { pointer to current directory name }<br>&nbsp; &nbsp; &nbsp; StartupInfo, { pointer to STARTUPINFO }<br>&nbsp; &nbsp; &nbsp; ProcessInfo) Then<br>&nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; With ProcessInfo Do<br>&nbsp; &nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; &nbsp; If ASign = 0 Then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WaitForSingleObject(hProcess, INFINITE);<br>&nbsp; &nbsp; &nbsp; &nbsp; CloseHandle(hThread);<br>&nbsp; &nbsp; &nbsp; &nbsp; CloseHandle(hProcess);<br>&nbsp; &nbsp; &nbsp; End;<br>&nbsp; &nbsp; End;<br>&nbsp; End<br>&nbsp; Else<br>&nbsp; &nbsp; ExitWindowsEx(ASign, 0);<br>End;<br>&nbsp; <br>
 
还想请教一下JamesBond_L:<br>SetCurrentDir是否返值有度限制呢?<br>
 
有度限制?什麼意思?
 
后退
顶部