ShellExecute () usage and difference with system ()

Source: Internet
Author: User

ShellExecute functionshell32.dll ShellExecute
Pre. clscode {font-size: 110% ;}
Pre. clssyntax {font-size: 100% ;}
TD Div. clsbeta {display: none ;}

A: link {color: # 0000ff; text-Decoration: underline ;}
A: visited {color: # 0000ff; text-Decoration: underline ;}
A: hover {color: # 3366ff; text-Decoration: underline ;}
Mshelp/: link {
Color: # 0000ff;
Text-Decoration: underline;
Cursor: hand;
Hovercolor: # 3366ff;
Filterstring :;}

ShellExecute Function

Extracted from msdn:

Performs an operation on a specified file.

Syntax

HINSTANCE ShellExecute(      



    HWND hwnd


,
    LPCTSTR lpOperation


,
    LPCTSTR lpFile


,
    LPCTSTR lpParameters


,
    LPCTSTR lpDirectory


,
    INT nShowCmd



);

Parameters

Hwnd

[In] a handle to the owner window used for displaying a user interface (UI)
Or error messages. This value can be null if the operation is not associated
With a window.
Lpoperation

[In] a pointer to a null-terminated string, referred to in this case as
Verb

, That specifies the action to be placed med. The set of available
Verbs depends on the particle file or folder. Generally, the actions available
From an object's slow cut menu are available verbs. The following verbs are
Commonly used.

Edit

Launches an editor and opens the document for editing. If Lpfile

Is
Not a document file, the function will fail.

Explore

Explores a folder specified Lpfile

.

Find

Initiates a search beginning in the directory specified
Lpdirectory

.

Open

Opens the item specified by Lpfile

Parameter. The item can be
File or folder.

Print

Prints the file specified Lpfile

. IfLpfile

Is not
Document file, the function fails.

Null

In systems prior to Microsoft Windows 2000, the default verb is used if it is
Valid and available in the registry. If not, the "open" verb is used.

In Windows 2000 and later, the default verb is used if available. If not,
"Open" verb is used. If neither verb is available, the system uses the first
Verb listed in the registry.

Lpfile

[In] a pointer to a null-terminated string that specifies the file or object
On which to execute the specified verb. to specify a shell namespace object,
Pass the fully qualified parse name. Note that not all verbs are supported on
All objects. For example, not all document types support the "print" verb. If
Relative Path is used for Lpdirectory

Parameter do not use a relative
PathLpfile

.

Lpparameters

[In] If Lpfile

Specifies an executable file, this parameter is
Pointer to a null-terminated string that specifies the parameters to be passed
To the application. The format of this string is determined by the verb that is
To be invoked. IfLpfile

Specifies a document file,Lpparameters

Shocould be null.

Lpdirectory

[In] a pointer to a null-terminated string that specifies the default
(Working) directory for the action. If this value is null, the current working
Directory is used. If a relative path is provided Lpfile

, Do not use
Relative PathLpdirectory

.

Nshowcmd

[In] the flags that specify how an application is to be displayed when it is
Opened. If Lpfile

Specifies a document file, the flag is simply passed
The associated application. It is up to the application to decide how to handle
It.

Sw_hide

Hides the window and activates another window.
Sw_maximize

Maximizes the specified window.
Sw_minimize

Minimizes the specified window and activates the next top-level window in
The Z-order.
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 shocould
Specify this flag when restoring a minimized window.
Sw_show

Activates the window and displays it in its current size and position.
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 shocould call
Showwindow
This flag to set the initial show state of its main window.
Sw_showmaximized

Activates the window and displays it as a maximized window.
Sw_showminimized

Activates the window and displays it as a minimized window.
Sw_showminnoactive

Displays the window as a minimized window. The active window remains active.
Sw_showna

Displays the window in its current state. The active window remains active.
Sw_shownoactivate

Displays a window in its most recent size and position. The active window
Remains active.
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 shocould
Specify this flag when displaying the window for the first
Time.

Return Value

Returns a value greater than 32 If successful, or an error value that is less
Than or equal to 32 otherwise. The following table lists the error values.
Return Value is cast as an hinstance for backward compatibility with 16-bit
Windows applications. It is not a true hinstance, however. The only thing that
Can be done with the returned hinstance is to cast it toInt

And
Compare it with the value 32 or one of the error codes below.

0 The operating system is out of memory or resources.
Error_file_not_found The specified file was not found.
Error_path_not_found The specified path was not found.
Error_bad_format The. exe file is invalid (non-Microsoft Win32. EXE or error in. exe
Image ).
Se_err_accessdenied The operating system denied access to the specified file.
Se_err_associncomplete The file name association is incomplete or invalid.
Se_err_ddebusy The Dynamic Data Exchange (DDE) Transaction cocould not be completed because
Other DDE transactions were being processed.
Se_err_ddefail The DDE transaction failed.
Se_err_ddetimeout The DDE transaction cocould not be completed because the request timed
Out.
Se_err_dllnotfound The specified DLL was not found.
Se_err_fnf The specified file was not found.
Se_err_noassoc There is no application associated with the given file name extension. This
Error will also be returned if you attempt to print a file that is not
Printable.
Se_err_oom There was not enough memory to complete the operation.
Se_err_pnf The specified path was not found.
Se_err_share A sharing violation occurred.

Remarks

This method allows you to execute any commands in a folder's slow cut menu or
Stored in the registry.

To open a folder, use either of the following CALS:

ShellExecute


(handle, NULL, <fully_qualified_path_to_folder>, NULL, NULL, SW_SHOWNORMAL);

Or

ShellExecute


(handle, "open", <fully_qualified_path_to_folder>, NULL, NULL, SW_SHOWNORMAL);

To construct e a folder, use the following call:

ShellExecute


(handle, "explore", <fully_qualified_path_to_folder>, NULL, NULL, SW_SHOWNORMAL);

 

To launch the shell's find utility for a directory, use the following call.

ShellExecute


(handle, "find", <fully_qualified_path_to_folder>, NULL, NULL, 0);

 

IfLpoperation

Is null, the function opens the file specified
Lpfile

. IfLpoperation

Is "open" or "lead E", the function
Attempts to open or release e the folder.

To obtain information about the application that is launched as a result
CallingShellExecute

, Use shellexecuteex.

Note

TheLaunch folder windows in a separate
Process

Setting in Folder Options affectsShellExecute

. If that
Option is disabled (the default setting ),ShellExecute

Uses an open
Explorer window rather than launch a new one. If no Explorer window is open,
ShellExecute

Launches a new one.

Windows 95/98/me

:ShellExecute

Is supported by the Microsoft
Layer for Unicode. To use this, you must add certain files to your application,
As outlined in Microsoft layer for Unicode on
Windows ME/98/95 systems.

Function Information

Minimum dll version Shell32.dll

Version
3.51

Or later

Custom implementation No
Header Shellapi. h

Import library Shell32.lib

Minimum Operating Systems Windows NT 3.1, Windows 95
Unicode Implemented as ANSI and Unicode versions.

 

Some translations are as follows:

 


For a specified file
(Folder
) To perform an operation.
(Open, edit, print, and so on)
).

Function prototype:

HINSTANCE ShellExecute( HWND hwnd
,
                    
    LPCTSTR lpOperation
,
                    
    LPCTSTR lpFile
,
                    
    LPCTSTR lpParameters
,
                    
    LPCTSTR lpDirectory
,
                    
    INT nShowCmd
);

Parameters
:

Hwnd

[In] indicates the subordinate
Window handle. If this operation is different from other
Window has no relationship. The value can be
Null.

Lpoperation

[In] a pointer to
Null-terminated string, referred to in this case asVerb
, That

String pointer, pointing
Null is the string of the Terminator. Specifies the operations performed on this file. The set of operations depends on the file type. For example, operations on files and folders are different. Generally, operations that can be performed in the context menu of a file or folder are supported. Common examples include:

Edit

Start the editing program to edit the file. If the object to be uploaded is not a file, the function fails.

 

Lpfile

The specified file name.



Lpparameters

Specified Parameter



Lpdirectory

Working path



Nshowcmd



The display mode of the window.



The system () function is a function in the C Language Runtime Library, used to execute system commands in the program. All commands that can be run in cmd mode can be used for system parameters.



Obviously, the use of shellexcute and system is different. System is used to execute the CMD command, while shellexcute only performs some actions on files and folders.








Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.