Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to choose the right "network place" icon?

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?

like image 319
bshacklett Avatar asked Nov 05 '12 21:11

bshacklett


1 Answers

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

Knowing this, you can read the default registry value at HKEY_CLASSES_ROOT\CLSID\{208D2C60-3AEA-1069-A2D7-08002B30309D}\DefaultIcon

The result will be i.e %SystemRoot%\system32\imageres.dll,-25

like image 63
GENiEBEN Avatar answered Nov 14 '22 14:11

GENiEBEN