一个小问题,有两个老兄给我解答了,可我用了后好象还是不对吗,是我用错了吧? (0分)

  • 主题发起人 主题发起人 阿波
  • 开始时间 开始时间

阿波

Unregistered / Unconfirmed
GUEST, unregistred user!
我想在程序执行到某一步的时个运行某目录下的EXE文件,有两位仁兄帮我解答了一下。<br>可能是我理解的不对,还是无法实现。请那个老兄再帮我看看,多谢了。<br>我想运行的那个EXE文件在:E:/111/222.EXE;<br>首先,我在上面的USES下面加入:<br>USES:<br>SHELLAPI;<br>然后在某语句后面写入:shellexecute(getdesktopwindow,'open','e:/111/222.exe',nil,nil,0);<br>然后我运行,运行过程中没有错误提示。可后来发现并没有执行那个222。EXE文件。<br>然后我将上句重新写为:WINEXEC(‘E:/111/222.EXE');<br>然后运行,可语法检查说‘WINEXEC’不是有效的实际参数。请那位老兄帮我看看我那理解的不对呀。<br>谢谢了。
 
第一个问题:<br>The ShellExecute function opens or prints a specified file. The file can be an executable file or a document file. See ShellExecuteEx also. <br>HINSTANCE ShellExecute(<br>&nbsp; &nbsp; HWND hwnd, // handle to parent window<br>&nbsp; &nbsp; LPCTSTR lpOperation, // pointer to string that specifies operation to perform<br>&nbsp; &nbsp; LPCTSTR lpFile, // pointer to filename or folder name string<br>&nbsp; &nbsp; LPCTSTR lpParameters, // pointer to string that specifies executable-file parameters <br>&nbsp; &nbsp; LPCTSTR lpDirectory, // pointer to string that specifies default directory<br>&nbsp; &nbsp; INT nShowCmd // whether file is shown when opened<br>&nbsp; &nbsp;); <br><br>nShowCmd's Value:<br>SW_HIDE Hides the window and activates another window.<br>SW_MAXIMIZE Maximizes the specified window.<br>SW_MINIMIZE Minimizes the specified window and activates the next top-level window in the Z order.<br>SW_RESTORE Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when restoring a minimized window.<br>SW_SHOW Activates the window and displays it in its current size and position. <br>SW_SHOWDEFAULT Sets the show state based on the SW_ flag specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application. An application should call ShowWindow with this flag to set the initial show state of its main window.<br>SW_SHOWMAXIMIZED Activates the window and displays it as a maximized window.<br>SW_SHOWMINIMIZED Activates the window and displays it as a minimized window.<br>SW_SHOWMINNOACTIVE Displays the window as a minimized window. The active window remains active.<br>SW_SHOWNA Displays the window in its current state. The active window remains active.<br>SW_SHOWNOACTIVATE Displays a window in its most recent size and position. The active window remains active.<br>SW_SHOWNORMAL Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when displaying the window for the first time.<br><br>If lpFile specifies a document file, nShowCmd should be zero. <br><br>Return Values<br>&nbsp;If the function succeeds, the return value is the instance handle of the application that was run, or the handle of a dynamic data exchange (DDE) server application.<br>&nbsp;If the function fails, the return value is an error value that is less than or equal to 32. The following table lists these error values:<br>&nbsp;0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; The operating system is out of memory or resources.<br>&nbsp;ERROR_FILE_NOT_FOUND &nbsp; &nbsp;The specified file was not found.<br>&nbsp;ERROR_PATH_NOT_FOUND &nbsp; &nbsp;The specified path was not found.<br>&nbsp;ERROR_BAD_FORMAT &nbsp; &nbsp;The .EXE file is invalid (non-Win32 .EXE or error in .EXE image).<br>&nbsp;SE_ERR_ACCESSDENIED &nbsp; &nbsp;The operating system denied access to the specified file. <br>&nbsp;SE_ERR_ASSOCINCOMPLETE &nbsp;The filename association is incomplete or invalid.<br>&nbsp;SE_ERR_DDEBUSY &nbsp; &nbsp;The DDE transaction could not be completed because other DDE transactions were being processed.<br>&nbsp;SE_ERR_DDEFAIL &nbsp; &nbsp;The DDE transaction failed.<br>&nbsp;SE_ERR_DDETIMEOUT &nbsp; &nbsp;The DDE transaction could not be completed because the request timed out.<br>&nbsp;SE_ERR_DLLNOTFOUND &nbsp; &nbsp;The specified dynamic-link library was not found. <br>&nbsp;SE_ERR_FNF &nbsp; &nbsp;The specified file was not found. <br>&nbsp;SE_ERR_NOASSOC &nbsp; &nbsp;There is no application associated with the given filename extension. <br>&nbsp;SE_ERR_OOM &nbsp; &nbsp;There was not enough memory to complete the operation.<br>&nbsp;SE_ERR_PNF &nbsp; &nbsp;The specified path was not found.<br>&nbsp;SE_ERR_SHARE &nbsp; &nbsp;A sharing violation occurred.<br><br>Remarks<br>The file specified by the lpFile parameter can be a document file or an executable file. If the file is a document file, the ShellExecute function opens or prints it, depending on the value of the lpOperation parameter. If the file is an executable file, the ShellExecute function opens it, even if lpOperation specifies printing. <br>You can use ShellExecute to open or explore a shell folder. <br>To open a folder, use either of the following calls:<br>ShellExecute(handle, NULL, path_to_folder, NULL, NULL, SW_SHOWNORMAL);<br>or<br>ShellExecute(handle, "open", path_to_folder, NULL, NULL, SW_SHOWNORMAL);<br><br>To explore a folder, use the following call:<br>ShellExecute(handle, "explore", path_to_folder, NULL, NULL, SW_SHOWNORMAL);<br><br>If lpOperation is NULL, the function opens the file specified by lpFile. If lpOperation is "open" or "explore", the function will force an open window or explorer.<br>
 
在引用ShellAPI后,使用下面的两句均能启动可执行文件。<br>&nbsp; Shellexecute(Handle,nil,'e:/down/ep2setup.exe',nil,nil,SW_NORMAL);<br>&nbsp; Winexec('E:/down/ep2setup.exe',0);<br>
 
第二个问题:<br>The WinExec function runs the specified application. <br>This function is provided for compatibility with earlier versions of Windows. For Win32-based applications, use the CreateProcess function. <br>UINT WinExec(<br>&nbsp; &nbsp; LPCSTR lpCmdLine, // address of command line <br>&nbsp; &nbsp; UINT uCmdShow // window style for new application <br>&nbsp; &nbsp;); <br>Parameters<br>&nbsp;lpCmdLine<br>&nbsp;Points to a null-terminated character string that contains the command line (filename plus optional parameters) for the application to be executed. If the name of the executable file in the lpCmdLine parameter does not contain a directory path, Windows searches for the executable file in this sequence: <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1. The directory from which the application loaded. <br> 2. The current directory. <br> 3. The Windows system directory. The GetSystemDirectory function retrieves the path of this directory. <br> 4. The Windows directory. The GetWindowsDirectory function retrieves the path of this directory. <br> 5. The directories listed in the PATH environment variable. <br>uCmdShow<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Specifies how a Windows-based application window is to be shown and is used to supply the wShowWindow member of the STARTUPINFO parameter to the CreateProcess function. For a list of the acceptable values, see the description of the nCmdShow parameter of the ShowWindow function. For a non-Windows - based application, the PIF file, if any, for the application determines the window state. <br><br>Return Values<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;If the function succeeds, the return value is greater than 31.<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;If the function fails, the return value is one of the following error values: <br><br>Value Meaning<br>&nbsp;0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; The system is out of memory or resources.<br>&nbsp;ERROR_BAD_FORMAT The .EXE file is invalid (non-Win32 .EXE or error in .EXE image).<br>&nbsp;ERROR_FILE_NOT_FOUND The specified file was not found.<br>&nbsp;ERROR_PATH_NOT_FOUND The specified path was not found.<br><br>Remarks<br>&nbsp;Win32-based applications should use the CreateProcess function rather than this function. The WinExec function exists in Win32 to provide compatibility with earlier versions of Windows. For more information about how the WinExec function is implemented, see the Remarks section of the LoadModule function.<br>&nbsp;In Win32, the WinExec function returns when the started process calls the GetMessage function or a time-out limit is reached. To avoid waiting for the time out delay, call the GetMessage function as soon as possible in any process started by a call to WinExec. <br><br>See Also<br>&nbsp;CreateProcess, GetMessage, GetSystemDirectory, GetWindowsDirectory, LoadModule, ShowWindow
 
最后的提示:<br>&nbsp; &nbsp; 在Delphi的帮助 WIN32 SDK 中可以找到以上完美的英文描述。<br>&nbsp; &nbsp; 多看看吧。
 
可以用CreateProcess完成同样的功能。
 
<br>&nbsp; 可以啊~
 
接受答案了.
 
后退
顶部