【发布时间】:2012-11-05 21:28:07
【问题描述】:
我有一个 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 库中的 Icon #275。在 Windows 7 中,“正确”图标是 imageres.dll 中的 Icon #143。有什么方法可以从操作系统获取图标详细信息,例如获取对资源管理器命名空间中特殊文件夹的引用?
【问题讨论】:
-
imageres.dll 中的图标 #143 不适合您?
-
如果脚本在 Windows XP 机器上运行,它会拉出错误的图标,因为不同版本的索引不同。
-
为什么不在创建链接之前测试操作系统名称并将编号更改为选择?
-
我希望不必依赖测试可能有许多我不知道的不同答案的东西。我查找了一份详尽的 Windows 版本号列表,但找不到。
标签: .net powershell environment windows-explorer