第一问结果 不知道VISTA是否能支持unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComObj, ShlObj;type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}function GetDisplayName(ShellFolder: IShellFolder; PIDL: PItemIDList; ForParsing: Boolean): string; var StrRet: _STRRET; p: PChar; nFlags: Integer; begin Result := ''; if ForParsing then nFlags := SHGDN_FORPARSING else nFlags := SHGDN_NORMAL; ShellFolder.GetDisplayNameOf(PIDL, nFlags, StrRet); case StrRet.uType of STRRET_CSTR: SetString(Result, StrRet.cStr, lStrLen(StrRet.cStr)); STRRET_OFFSET: begin P := @PIDL.mkid.abID[StrRet.uOffset - SizeOf(PIDL.mkid.cb)]; SetString(Result, P, PIDL.mkid.cb - StrRet.uOffset); end; STRRET_WSTR: Result := StrRet.pOleStr; end; end; procedure ShowLocalAreaConnection(hOwner: HWND);const Flags = SHCONTF_FOLDERS or SHCONTF_NONFOLDERS or SHCONTF_INCLUDEHIDDEN;var psf: IShellFolder; pidl: PItemIDList; pedl: IEnumIDList; dwNum: LongWord; pcm: IContextMenu; ici: _CMINVOKECOMMANDINFO; begin SHGetDesktopFolder(psf); SHGetSpecialFolderLocation(hOwner, CSIDL_CONTROLS, pidl); psf.BindToObject(pidl, nil, IID_IShellFolder, Pointer(psf)); psf.EnumObjects(hOwner, Flags, pedl); while pedl.Next(1, pidl, dwNum) = S_OK do begin if GetDisplayName(psf, pidl, False) = '网络连接' then begin psf.BindToObject(pidl, nil, IID_IShellFolder, Pointer(psf)); psf.EnumObjects(hOwner, Flags, pedl); while pedl.Next(1, pidl, dwNum) = S_OK do begin ShowMessage(GetDisplayName(psf, pidl, False)); if Trim(GetDisplayName(psf, pidl, False)) = Trim('本地连接 2') then begin psf.GetUIObjectOf(hOwner, 1, pidl, IID_IContextMenu, nil, pcm); FillChar(ici, SizeOf(_CMINVOKECOMMANDINFO), #0); with ici do begin cbSize := SizeOf(_CMINVOKECOMMANDINFO); hwnd := hOwner; lpVerb := MakeIntResource(8); //lpVerb := MakeIntResource(1); //lpVerb := MakeIntResource(1); nShow := SW_SHOWNORMAL; end; pcm.InvokeCommand(ici); Break; end; end; Break; end; end; end;procedure TForm1.Button1Click(Sender: TObject);begin ShowLocalAreaConnection(Self.Handle);end;end.