5

I've got a PowerShell script that creates shortcuts to network locations at login. Unfortunately, it's using an old low-res icon. It's not a big deal by any means, but I'd like to use the updated icons in later versions of Windows.

Here's the relevant portion of the function that creates the shortcut:

# 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)

As you can see, it's currently using Icon #275 in the SHELL32.DLL library. In Windows 7, the "proper" icon would be Icon #143 in imageres.dll. Is there any way to get the icon details from the OS like getting a reference to a Special folder in the Explorer namespace?

4

1 回答 1

6

我的网上邻居有 CLSID208d2c60-3aea-1069-a2d7-08002b30309d

知道了这一点,您可以在以下位置读取默认注册表值HKEY_CLASSES_ROOT\CLSID\{208D2C60-3AEA-1069-A2D7-08002B30309D}\DefaultIcon

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

于 2012-12-12T12:55:51.483 回答