Mega Code Archive
How to open special folders
Title: How to open special folders?
Question: How to open special folders like "My Computer", "Network Neighborhood", "Recycle Bin" ....... in your program?
Answer:
Wondered how to open special folders like My Computer, Network Neighbourhood, Recycle Bin, Control Panel, Dial-up Networking, Printers, Scheduler folders in your program. Here is a method to open such folders.
The following procedure is a ready to use procedure, simply call this procedure in your program with the correct index. Index representation is as follows.
0 - My Computer
1 - Network Neighborhood
2 - Control Panel
3 - Dialup Networking
4 - Recycle Bin
5 - Printers
6 - Scheduled Tasks
//FOLLOW CODE
procedure TForm1.SpecialFolderClick(SplFoldIndex: integer);
//Blocked function
function GetWinDir: String;
var
Buffer: array[0..MAX_PATH] of Char;
begin
GetWindowsDirectory(Buffer, SizeOf(Buffer));
SetString(Result, Buffer, StrLen(Buffer));
end;
var
Arg: String;
begin
case SplFoldIndex of
// My Computer
0: Arg := ' ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}';
// Network Neighborhood
1: Arg := ' ::{208D2C60-3AEA-1069-A2D7-08002B30309D}';
// Control Panel
2: Arg := ' ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{21EC2020-3AEA-1069-A2DD-8002B30309D}';
// Dial-up Networking
3: Arg := ' ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{992CFFA0-F557-101A-88EC-00DD010CCC48}';
// Recycle Bin
4: Arg := ' ::{645FF040-5081-101B-9F08-00AA002F954E}';
// Printers
5: Arg := ' ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{2227A280-3AEA-1069-A2DE-08002B30309D}';
// Scheduled Tasks
6: Arg := ' ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{D6277990-4C6A-11CF-8D87-00AA0060F5BF}';
end; //case
ShellExecute(Application.Handle, 'Open', PChar(GetWinDir + '\explorer.exe'), PChar(Arg), nil, SW_SHOW);
end;
The GetWinDir is a blocked function. This function returns the windows directory. This information is needed for the exact path of the windows explorer. Windows explorer opens the special folders if correct class ids for the special folders are provided as parameters.
This code has been tested in delphi 2.0.
Works fine in all versions.