.net 如何选择正确的;“网络广场”;偶像

.net 如何选择正确的;“网络广场”;偶像,.net,powershell,environment,windows-explorer,.net,Powershell,Environment,Windows Explorer,我有一个PowerShell脚本,可以在登录时创建网络位置的快捷方式。不幸的是,它使用了一个旧的低分辨率图标。无论如何,这都不是什么大不了的事,但我想在以后的Windows版本中使用更新的图标 以下是创建快捷方式的函数的相关部分: # Create the shortcut file $shortcut = (New-Object -ComObject WScript.Shell).Createshortcut("$shortcutFolder\target.lnk") $shortcut.

我有一个PowerShell脚本,可以在登录时创建网络位置的快捷方式。不幸的是,它使用了一个旧的低分辨率图标。无论如何,这都不是什么大不了的事,但我想在以后的Windows版本中使用更新的图标

以下是创建快捷方式的函数的相关部分:

# Create the shortcut file

$shortcut = (New-Object -ComObject WScript.Shell).Createshortcut("$shortcutFolder\target.lnk")

$shortcut.TargetPath = $targetPath
if (
$shortcut.IconLocation = "%SystemRoot%\system32\SHELL32.DLL, 275"
$shortcut.Description = $targetPath
$shortcut.WorkingDirectory = $targetPath
$shortcut.Save()

# Set attributes on the files & folders
$desktopIni | Set-ItemProperty -Name Attributes -Value ([IO.FileAttributes]::System -bxor [IO.FileAttributes]::Hidden)
$shortcutFolder | Set-ItemProperty -Name Attributes -Value ([IO.FileAttributes]::ReadOnly)

如您所见,它目前正在使用SHELL32.DLL库中的图标#275。在Windows 7中,“正确”图标应该是imageres.dll中的图标#143。是否有任何方法可以从操作系统获取图标详细信息,例如获取对资源管理器命名空间中特殊文件夹的引用?

My Network Places具有CLSID
208d2c60-3aea-1069-a2d7-08002b30309d

知道了这一点,您可以在
HKEY\U CLASSES\U ROOT\CLSID\{208D2C60-3AEA-1069-A2D7-08002B30309D}\DefaultIcon


结果将是,即
%SystemRoot%\system32\imageres.dll,-25

Icon#imageres.dll中的143对您不合适?如果脚本在Windows XP机器上运行,它将调出错误的图标,由于不同版本的索引不同。为什么不在创建链接之前测试操作系统名称并将编号更改为choice?我希望不必依赖于测试可能有许多我不知道的不同答案的东西。我查找了一份详尽的Windows版本号列表,但找不到。