调用“1394 连接”、“无线网络连接”、“拨号连接”的属性,把程序里的 '本地连接' 改个名就行了。
uses ComObj, ShlObj;
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;
//hOwner:主窗口句柄;
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
if GetDisplayName(psf, pidl, False) = '本地连接' 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);
nShow := SW_SHOWNORMAL;
end;
pcm.InvokeCommand(ici);
Break;
end;
end;
Break;
end;
end;
end;