全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:4361
推到 Plurk!
推到 Facebook!

CreateProcess 如何傳參數

答題得分者是:RaynorPao
degr
一般會員


發表:22
回覆:36
積分:21
註冊:2002-03-25

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-01-27 14:55:57 IP:61.221.xxx.xxx 未訂閱
我有使用CreateProcess 可以起動別的程式 可是無法傳參數呢 如果 再指定名稱,後面再加上參數時,就會無法啟動程式呢 目前試過 只有 winexec傳參數且執行外部程式 可以用呢 請問有人知道要怎樣用嗎 CreateProcess 傳參數且執行外部程式
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-01-27 15:05:34 IP:203.73.xxx.xxx 未訂閱
引言: 我有使用CreateProcess 可以起動別的程式 可是無法傳參數呢 如果 再指定名稱,後面再加上參數時,就會無法啟動程式呢 目前試過 只有 winexec傳參數且執行外部程式 可以用呢 請問有人知道要怎樣用嗎 CreateProcess 傳參數且執行外部程式
degr 你好: 請參考以下連結的說明(有 sample code)
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
soni
一般會員


發表:17
回覆:29
積分:9
註冊:2003-02-06

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-02-20 14:31:53 IP:61.219.xxx.xxx 未訂閱
引言: degr 你好: 請參考以下連結的說明(有 sample code) >< face="Verdana, Arial, Helvetica"> R大大你好: 小弟參考你所給的連結COPY上面的CODE下來使用 可是每當我ㄑ呼叫外部程式的時候主程式就會毫 無反應當我把主程式關閉時我所呼叫的外部程式 卻再這時候開始執行小弟重複過好幾次都是一樣 的結果可否請大大為小弟解解迷惑 感激不盡 CODE如下: procedure TCheckLicense.CallNewProcess(NewAppName: String); var StartInfo : TStartupInfo; ProcInfo : TProcessInformation; CreateOK : Boolean; begin FillChar(StartInfo,SizeOf(TStartupInfo),#0); FillChar(ProcInfo,SizeOf(TProcessInformation),#0); StartInfo.cb := SizeOf(TStartupInfo); CreateOK := CreateProcess(PChar(NewAppName),nil, nil, nil,False, CREATE_NEW_PROCESS_GROUP NORMAL_PRIORITY_CLASS, nil, nil, StartInfo, ProcInfo); if CreateOK then WaitForSingleObject(ProcInfo.hProcess, INFINITE); end; 小弟所使用的開發環境為: DELPHI4 UPDATE 4.02 WINXP VERSION 2002 另外想請問大大如果使用ShellExecuteInfo這ㄍ方法 又應該如何傳參數值ㄋ 發表人 -
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-02-20 16:05:10 IP:203.73.xxx.xxx 未訂閱
引言: R大大你好: 小弟參考你所給的連結COPY上面的CODE下來使用 可是每當我ㄑ呼叫外部程式的時候主程式就會毫 無反應當我把主程式關閉時我所呼叫的外部程式 卻再這時候開始執行小弟重複過好幾次都是一樣 的結果可否請大大為小弟解解迷惑 感激不盡 CODE如下: procedure TCheckLicense.CallNewProcess(NewAppName: String); var StartInfo : TStartupInfo; ProcInfo : TProcessInformation; CreateOK : Boolean; begin FillChar(StartInfo,SizeOf(TStartupInfo),#0); FillChar(ProcInfo,SizeOf(TProcessInformation),#0); StartInfo.cb := SizeOf(TStartupInfo); CreateOK := CreateProcess(PChar(NewAppName),nil, nil, nil,False, CREATE_NEW_PROCESS_GROUP NORMAL_PRIORITY_CLASS, nil, nil, StartInfo, ProcInfo); if CreateOK then WaitForSingleObject(ProcInfo.hProcess, INFINITE); end; 小弟所使用的開發環境為: DELPHI4 UPDATE 4.02 WINXP VERSION 2002 另外想請問大大如果使用ShellExecuteInfo這ㄍ方法 又應該如何傳參數值ㄋ < face="Verdana, Arial, Helvetica"> soni 你好: (1)我已經試過了~~我的環境是沒有問題的(D5, Win2000) (2)如果還是不行,建議使用 ShellExecute http://delphi.ktop.com.tw/topic.php?TOPIC_ID=18130 備註: sorry~~我剛剛是在同事的機器上測試的 我再 check 一次,是 D6, Win2000 -- Enjoy Researching & Developing -- 發表人 - RaynorPao 於 2003/02/20 16:30:26
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
懷舊的人
高階會員


發表:28
回覆:152
積分:141
註冊:2003-01-08

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-02-20 16:22:26 IP:152.104.xxx.xxx 未訂閱
引言: //說明 The CreateProcess function creates a new process and its primary thread. The new process executes the specified executable file. BOOL CreateProcess( LPCTSTR lpApplicationName, // pointer to name of executable module LPTSTR lpCommandLine, // pointer to command line string LPSECURITY_ATTRIBUTES lpProcessAttributes, // pointer to process security attributes LPSECURITY_ATTRIBUTES lpThreadAttributes, // pointer to thread security attributes BOOL bInheritHandles, // handle inheritance flag DWORD dwCreationFlags, // creation flags LPVOID lpEnvironment, // pointer to new environment block LPCTSTR lpCurrentDirectory, // pointer to current directory name LPSTARTUPINFO lpStartupInfo, // pointer to STARTUPINFO LPPROCESS_INFORMATION lpProcessInformation // pointer to PROCESS_INFORMATION ); Parameters lpApplicationName Pointer to a null-terminated string that specifies the module to execute. The string can specify the full path and filename of the module to execute. The string can specify a partial name. In that case, the function uses the current drive and current directory to complete the specification. The lpApplicationName parameter can be NULL. In that case, the module name must be the first white space-delimited token in the lpCommandLine string. The specified module can be a Win32-based application. It can be some other type of module (for example, MS-DOS or OS/2) if the appropriate subsystem is available on the local computer. Windows NT: If the executable module is a 16-bit application, lpApplicationName should be NULL, and the string pointed to by lpCommandLine should specify the executable module. A 16-bit application is one that executes as a VDM or WOW process. lpCommandLine Pointer to a null-terminated string that specifies the command line to execute. The lpCommandLine parameter can be NULL. In that case, the function uses the string pointed to by lpApplicationName as the command line. If both lpApplicationName and lpCommandLine are non-NULL, *lpApplicationName specifies the module to execute, and *lpCommandLine specifies the command line. The new process can use GetCommandLine to retrieve the entire command line. C runtime processes can use the argc and argv arguments. If lpApplicationName is NULL, the first white space-delimited token of the command line specifies the module name. If the filename does not contain an extension, .EXE is assumed. If the filename ends in a period (.) with no extension, or the filename contains a path, .EXE is not appended. If the filename does not contain a directory path, Windows searches for the executable file in the following sequence: 1. The directory from which the application loaded. 2. The current directory for the parent process. 3. Windows 95: The Windows system directory. Use the GetSystemDirectory function to get the path of this directory. Windows NT: The 32-bit Windows system directory. Use the GetSystemDirectory function to get the path of this directory. The name of this directory is SYSTEM32. 4. Windows NT: The 16-bit Windows system directory. There is no Win32 function that obtains the path of this directory, but it is searched. The name of this directory is SYSTEM. 5. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory. 6. The directories that are listed in the PATH environment variable. If the process to be created is an MS-DOS - based or Windows-based application, lpCommandLine should be a full command line in which the first element is the application name. Because this also works well for Win32-based applications, it is the most robust way to set lpCommandLine. lpProcessAttributes Pointer to a SECURITY_ATTRIBUTES structure that determines whether the returned handle can be inherited by child processes. If lpProcessAttributes is NULL, the handle cannot be inherited. Windows NT: The lpSecurityDescriptor member of the structure specifies a security descriptor for the new process. If lpProcessAttributes is NULL, the process gets a default security descriptor. Windows 95: The lpSecurityDescriptor member of the structure is ignored. // 範例 procedure TForm1.Button1Click(Sender: TObject); var B: Boolean; SI: TStartUpInfo; // holds startup information PI: TProcessInformation; // holds process information VerInfo: TOSVersionInfo; begin // get windows version VerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo); GetVersionEx(VerInfo); {initialize the startup information} FillChar(SI, SizeOf(TStartupInfo), 0); with SI do begin cb := SizeOf(TStartupInfo); dwFlags := STARTF_USESHOWWINDOW; wShowWindow := SW_SHOW; end; // 請注意 CreateProcess 會因為 windows 版本寫法會有所不同 目前是 win2000 if VerInfo.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS then B := CreateProcess(Nil,PCAHR('C:\WINDOWS\SYSTEM\CALC.EXE'),Nil, Nil, False, NORMAL_PRIORITY_CLASS, Nil, Nil, SI, PI) else // Win2000 會執行這一行 B := CreateProcess(PCHAR('C:\WINNT\SYSTEM32\CALC.EXE'),Nil,Nil, Nil, False, NORMAL_PRIORITY_CLASS, Nil, Nil, SI, PI); // WaitForSingleObject(PI.hProcess, 0); // WaitForInputIdle(PI.hProcess, INFINATE); // 會等候輸入完畢 ....... // 請參閱 Delphi Help (Delphi 6.0 , 7.0) ( ? Delphi 5.0 ) C:\Program File\Common Files\Borland Shared\MSHelp\Win32SDK.HLP
soni
一般會員


發表:17
回覆:29
積分:9
註冊:2003-02-06

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-02-20 16:57:09 IP:61.219.xxx.xxx 未訂閱
to 列為大大 小弟剛試ㄌ一下 如果我只是呼叫一般的應用程式如小算盤,記事本等 不論是R大大獲懷舊大大ㄉ程式 都沒有任何問題 但是一但呼叫一ㄍ安裝程式就會出現上述ㄉ現象 請問列為先進 這是什麼問題所造成ㄋ 備註:我所呼叫ㄉ安裝程式是由DELPHI4所附ㄉINSTALLSHELL包裝ㄉ 小弟試著使用如ShellExecute的方法如下: ShellExecute(Application.Handle, PChar('Open'), PChar(ExtractFilePath(Application.EXEName) 'salsystem\setup.exe'), PChar(''), nil, SW_NORMAL); 安裝程式可以呼叫出來執行到一半卻會出現如下的錯誤訊息: Setup is unable to decompress and copy all of the programfiles needed to proceed with the installation. Contact your sofrware vandor. Error 112. 請前輩們幫小弟解解迷津 感激萬分 發表人 - soni 於 2003/02/20 17:26:21
系統時間:2024-04-28 0:39:42
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!