Q: How can I use code to control the resource browser and locate the specified file?
A: Use ShellExecute with explorer.
ShellExecute (application. Handle, 'open', pchar ('explorer '), pchar ('/select, "d: \ SS \ EE \ test.txt" '), nil, sw_showdefault)
The following is a detailed explanation.
1、assumer.exe
Few-known parameters are added to the favorites in windows. They believe that they are no stranger to "“explorer.exe! In general, the "Start> Run" command can open "My Documents" in "Resource Manager ". In fact, assumer.exe also has many little-known parameters. Command Format
Explorer [/n] [/E] [[,/root], [path] [[,/select], [path filename]
Parameter description
/N indicates opening a new window in "My Computer" mode, which usually opens the root directory of the Windows Installation partition.
/E Indicates opening a new window in the "Resource Manager" mode. The root directory of the Windows Installation partition is usually opened.
/Root, [path] indicates opening the specified folder,/root indicates displaying only the files (folders) under the specified folder, but not other disk partitions and folders; [path] indicates the specified path.
If you only use the [path] parameter without the/Root parameter, you can display the content in other disk partitions and folders. In addition, you can specify the network shared folder in [path.
/Select, [path filename] indicates opening the specified folder and selecting the specified file. [path filename] indicates the specified path and file name.
If the/select parameter is not added, the system opens the file with the relevant program. If [path filename] is not followed by the file name, the parent directory of the folder is opened and the folder is selected.
2. ShellExecute
ShellExecute (
Hwnd: hwnd; {specify the parent window handle}
Operation: pchar; {specified action, such as open and print}
Filename: pchar; {specify the file or program to open}
Parameters: pchar; {specify parameters for the program to be opened; if the file is opened, it should be nil}
Directory: pchar; {default directory}
Showcmd: INTEGER {open option}
): Hinst; {the application handle is returned if the execution succeeds. If the value is <= 32, the execution error is returned}
// Possible errors returned include:
= 0 {insufficient memory}
Error_file_not_found = 2; {file name error}
Error_path_not_found = 3; {path name error}
Error_bad_format = 11; {the EXE file is invalid}
Se_err_share = 26; {share error}
Se_err_associncomplete = 27; {the file name is incomplete or invalid}
Se_err_ddetimeout = 28; {timeout}
Se_err_ddefail = 29; {DDE Transaction Failed}
Se_err_ddebusy = 30; {another DDE transaction is being processed and this DDE transaction cannot be completed}
Se_err_noassoc = 31; {No associated application}
// Showcmd parameter value options:
Sw_hide = 0; {hide}
Sw_shownormal = 1; {display with the nearest size and position, activate}
Sw_normal = 1; {same as sw_shownormal}
Sw_showminimized = 2; {minimize, activate}
Sw_showmaximized = 3; {maximize, activate}
Sw_maximize = 3; {same as sw_showmaximized}
Sw_shownoactivate = 4; {display with the nearest size and position, not activated}
Sw_show = 5; {same as sw_shownormal}
Sw_minimize = 6; {minimized, not activated}
Sw_showminnoactive = 7; {same as sw_minimize}
Sw_showna = 8; {same as sw_shownoactivate}
Sw_restore = 9; {same as sw_shownormal}
Sw_showdefault = 10; {same as sw_shownormal}
Sw_max = 10; {same as sw_shownormal}
--------------------------------------------------------------------------------
// Example to illustrate more issues (don't forget uses shellapi ;):
{For example, open a file in Notepad}
Begin
ShellExecute (handle, 'open', 'notepad.exe ', 'c: \ windows \ schedlgu. txt', nil, sw_shownormal );
End;
--------------------------------------------------------------------------------
{The first parameter is used as the parent window of the error Prompt window. It cannot be nil or 0 (desktop window )}
Begin
ShellExecute (0, 'open', 'notepad.exe ', 'c: \ windows \ schedlgu. txt', nil, sw_shownormal );
End;
--------------------------------------------------------------------------------
{If the second parameter is nil, the default value is open}
Begin
ShellExecute (0, nil, 'notepad.exe ', 'c: \ windows \ schedlgu. txt', nil, sw_shownormal );
End;
--------------------------------------------------------------------------------
{File path can be placed in parameter 5}
Begin
ShellExecute (0, nil, 'notepad.exe ', 'schedlgu. txt', 'c: \ Windows', sw_shownormal );
End;
--------------------------------------------------------------------------------
{Specify parameter 3 as the file to be opened. The file will be opened using the corresponding default program. Number of times parameter 4 should be nil}
Begin
ShellExecute (0, nil, 'schedlgu. txt ', nil, 'c: \ Windows', sw_shownormal );
End;
--------------------------------------------------------------------------------
{If the file is in the program directory/current directory/system32/Windows/PATH environment variable, parameter 5 can also be nil}
Begin
ShellExecute (0, nil, 'schedlgu. txt ', nil, nil, sw_shownormal );
End;
--------------------------------------------------------------------------------
{If parameter 3 is a file, run parameter 2 to print it}
Begin
ShellExecute (0, 'print ', 'schedlgu. txt', nil, nil, 1 );
End;
--------------------------------------------------------------------------------
{Open web page with IE}
Begin
ShellExecute (handle, 'open', 'ipluse. EXE ', 'about: blank', nil, sw_shownormal );
End;
--------------------------------------------------------------------------------
{Open a webpage with Firefox}
Begin
ShellExecute (handle, 'open', 'firefox.exe ', 'about: blank', nil, sw_shownormal );
End;
--------------------------------------------------------------------------------
{Open the webpage with the default browser}
Begin
ShellExecute (handle, 'open', 'assumer.exe ', 'about: blank', nil, sw_shownormal );
End;
--------------------------------------------------------------------------------
{Use the default browser to open the webpage}
Begin
ShellExecute (0, nil, 'HTTP: // del.cnblogs.com ', nil, nil, 1 );
End;