首页  编辑  

打开网上邻居、回收站等特殊文件夹

Tags: /超级猛料/Stream.File.流、文件和目录/目录/   Date Created:

有一个变态的方法:

首先创建一个ShortCut,然后运行这个ShortCut即可。

procedure RunNetHood;

var

anobj:IUnknown;

shlink:IShellLink;

pFile:IPersistFile;

pidl:pItemIDList;

begin

anobj:=CreateComObject(CLSID_SHELLLINK);

SHGetSpecialFolderLocation( application.Handle , CSIDL_NETWORK, pidl);

shlink:=anobj as IShellLink;

pFile:=anobj as IPersistFile;

shlink.SetIDList(pidl);

shlink.SetShowCmd(sw_show);

pFile.Save('C:\nethood.lnk',false);

ShellExecute(0,'open','C:\nethood.lnk',nil,nil,sw_show);

DeleteFile('C:\Nethood.lnk');

end;

请参看打开回收站的方法,那个方法比较好!

*******************************************

下面是一个比较好的方法:

请参看函数OpenSpecialFolder,其中,FolderID可以为

CSIDL_BITBUCKET        

CSIDL_CONTROLS        

CSIDL_DESKTOP        

CSIDL_DESKTOPDIRECTORY        

.........

uses

 ActiveX , ShlObj , ShellApi ;

procedure OpenSpecialFolder ( FolderID : integer ; AHandle : HWND = 0 );

  procedure FreePidl ( pidl : PItemIDList );

  var

   allocator       : IMalloc ;

  begin

    if Succeeded ( shlobj . SHGetMalloc ( allocator )) then

    begin

     allocator . Free ( pidl );

{$IFDEF VER90}

     allocator . Release ;

{$ENDIF}

    end ;

  end ;

var

 exInfo             : TShellExecuteInfo ;

begin

  // initialize all fields to 0

 FillChar ( exInfo , SizeOf ( exInfo ), 0 );

  with exInfo do

  begin

   cbSize := SizeOf ( exInfo ); // required!

   fMask := SEE_MASK_FLAG_DDEWAIT or SEE_MASK_IDLIST ;

   Wnd := AHandle ;

   nShow := SW_SHOWNORMAL ;

   lpVerb := 'open' ;

   ShGetSpecialFolderLocation ( AHandle , FolderID , PItemIDLIst ( lpIDList ));

  end ;

 ShellExecuteEx (@ exInfo );

 FreePIDL ( exinfo . lpIDList );

end ;

procedure TForm1 . Button1Click ( Sender : TObject );

begin

 OpenSpecialFolder ( CSIDL_STARTUP );

end ;