ShellExecute Function
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Platforms: Win 32s, Win 95/98, Win NT
ShellExecute uses the shell to open or print a file or run a program. Under Win 95/98, this function will also open a My Computer or Explorer window to a given directory. If an executable program is specified, Windows will run that program. If a document file is specified, Windows will open or print it using the associated program (whatever it happens to be). If successful, the function returns a handle to the instance of the opened program or (in the case of printing) a handle to the invoked DDE server application. If unsuccessful, the function returns either 0 (meaning out of memory or resources) or one of the following error code flags:
- ERROR_FILE_NOT_FOUND = 2
- The specified file could not be found.
- ERROR_PATH_NOT_FOUND = 3
- The specified directory could not be found.
- ERROR_BAD_FORMAT = 11
- The specified executable file (.EXE) was somehow invalid.
- SE_ERR_ACCESSDENIED = 5
- Win 95/98 only: Windows denied access to the specified file.
- SE_ERR_ASSOCINCOMPLETE = 27
- The filename association is either incomplete or invalid.
- SE_ERR_DDEBUSY = 30
- The DDE action could not run because other DDE actions are in process.
- SE_ERR_DDEFAIL = 29
- The DDE transaction failed.
- SE_ERR_DDETIMEOUT = 28
- The DDE transaction was not completed because the request timed out.
- SE_ERR_DLLNOTFOUND = 32
- Win 95/98 only: The specified DLL file was not found.
- SE_ERR_FNF = 2
- Same as ERROR_FILE_NOT_FOUND.
- SE_ERR_NOASSOC = 31
- There is no program associated with the specified type of file.
- SE_ERR_OOM = 8
- Win 95/98 only: Windows has insufficient memory to perform the operation.
- SE_ERR_PNF = 3
- Same as ERROR_PATH_NOT_FOUND.
- SE_ERR_SHARE = 26
- A sharing violation occured.
- hwnd
- The handle of the window calling the function.
- lpOperation
- The operation to perform on lpFile. "open" means open the file or run the program (or directory in Win 95/98). "print" means print the document. In Win 95/98, "explore" means open the directory in an Explorer window. The default is "open".
- lpFile
- The file to perform the operation on.
- lpParameters
- Any command-line parameters to pass to an opened application.
- lpDirectory
- The working directory for the operation.
- nShowCmd
- One of the following flags specifying how to display any window that the function opens:
- SW_HIDE = 0
- Hide the opened window.
- SW_MAXIMIZE = 3
- Maximize the opened window.
- SW_MINIMIZE = 6
- Minimize the opened window.
- SW_RESTORE = 9
- Restore the opened window (not maximized nor minimized).
- SW_SHOW = 5
- Show the opened window.
- SW_SHOWMAXIMIZED = 3
- Show the opened window maximized.
- SW_SHOWMINIMIZED = 2
- Show the opened window minimized.
- SW_SHOWMINNOACTIVE = 7
- Show the opened window minimized but do not activate the it.
- SW_SHOWNA = 8
- Show the opened window in its current state but do not activate it.
- SW_SHOWNOACTIVATE = 4
- Show the opened window in its most recent size and position but do not activate it.
- SW_SHOWNORMAL = 1
- Show the opened window and activate it (as usual).
Example:
' Perform the following tasks:
' 1. Run the program "C:\MyProg\startup.exe" with command line "-fast" maximized
' 2. Open the document "C:\Project\nucleus.doc" (with its associated program) restored
' 3. Print the document "C:\Project\picture.bmp" normally (!?)
Dim hStartup As Long ' handle to instance of startup.exe
Dim hNucleus As Long ' handle to instance of opened nucleus.doc
Dim hPicture As Long ' handle to DDE process printing picture.bmp
' 1. Run the program:
hStartup = ShellExecute(Form1.hWnd, "open", "C:\MyProg\startup.exe", "-fast", "C:\MyProg\", SW_SHOWMAXIMIZED)
' 2. Open the document:
hNucleus = ShellExecute(Form1.hWnd, "open", "C:\Project\nucleus.doc", "", "C:\Project\", SW_RESTORE)
' 3. Print the document:
hPicture = ShellExecute(Form1.hWnd, "print", "C:\Project\picture.bmp", "", "C:\Project\", SW_SHOWNORMAL)
Category: Shell
Back to the index.
Go to Paul Kuliniewicz's Home Page.
E-mail: rogue953@hotmail.com
This page is at http://skyscraper.fortunecity.com/transmission/45/api/s/shellexecute.html