Opening Windows Explorer with the ShellExecute API in Delphi
To launch applications such as Notepad, you can use the ShellExecute API:
ShellExecute(Handle, 'open', 'notepad.exe', nil, nil, SW_SHOW);
The following example opens the C:\Windows directory in Windows Explorer.
uses ShellAPI; procedure TForm1.Button1Click(Sender: TObject); begin ShellExecute(Handle, 'open', 'explorer.exe', 'c:\Windows', nil, SW_SHOW); end;
The next example opens Windows Explorer with the C:\Windows directory, and highlights the file win.ini.
uses ShellAPI; procedure TForm1.Button2Click(Sender: TObject); begin ShellExecute(Handle, 'open', 'explorer.exe', '/select,c:\Windows\win.ini', nil, SW_SHOW); end;
The following example opens Windows Explorer with the C:\Windows directory, and highlights the system32 folder.
uses ShellAPI; procedure TForm1.Button2Click(Sender: TObject); begin ShellExecute(Handle, 'open', 'explorer.exe', '/select,c:\Windows\system32', nil, SW_SHOW); end;
