[英]How to associate icon with custom application(registered with a powershell script)
我使用cygwin版本的gvim在Windows中编辑文件,为此,我创建了一个bat脚本,该脚本打开了cygwin版本的gvim的文件(通过将路径转换为cygwin格式)。 我还编写了一个小的powershell脚本,以便将该bat脚本注册到Windows资源管理器,以便可以使用“打开方式”上下文菜单关联文件扩展名。 这是脚本:
$ErrorActionPreference = "Stop"
$classes="hkcu:\software\classes"
$appid="cygwin.gvim"
$apps="$classes\applications"
$cmd='...SOMEDIRECTORY...\edit-gvim.bat'
$friendlyname='gVim (Cygwin)'
$icon='...ANOTHERDIRECTORY...\vim.ico'
$filetypes=@(".txt", ".ps1", ".sh", ".py", ".cs", ".cpp", ".c", ".rb",
".zsh", ".bash", ".vbox", ".xml", ".yml", ".yaml", ".bat")
if (test-path "$apps\$appid") {
# cleanup
remove-item -recurse "$apps\$appid"
}
# register open commands to know filetypes
new-item -path "$apps\$appid\shell\open\command" -value "$cmd `"%1`"" -force
# add a context menu item(edit with gVim) to every file in windows explorer
new-item -path "$classes\*\shell\Edit with $friendlyname\command" -value "$cmd `"%1`"" -force
# friendly name for the 'open with' dialog
new-itemproperty -path "$apps\$appid\shell\open" -name 'FriendlyAppName' -value $friendlyname
# register the icon
# FIXME this has no effect
new-item -path "$apps\$appid\DefaultIcon" -value $icon -type expandstring
# register supported file extensions
new-item -path "$apps\$appid\SupportedTypes"
foreach ($ext in $filetypes) {
new-itemproperty -path "$apps\$appid\SupportedTypes" -name $ext -PropertyType string -value ''
}
除“ FIXME”注释下方的行外,其他所有操作均正常,该行显然无效。 我没有看到与gvim相关的应用程序提供的图标,而是看到了Windows默认图标,用于未知文件类型。 我在这里想念什么?
这是我用来编写此脚本的一些资源:
我可能会犯一个错误,但据我了解DefaultIcon
的语法是:
"Full path to a file,ordinal"
当您要指向EXE或DLL中的资源时,这很有用
C:\Program Files (x86)\PowerGUI\ScriptEditor.exe,1
但是,如果要指向图标文件,则必须保留相同的语法:
[HKEY_CLASSES_ROOT\AcroExch.acrobatsecuritysettings.1\DefaultIcon]
@="C:\\Windows\\Installer\\{AC76BA86-7AD7-1036-7B44-A95000000001}\\PDFFile_8.ico,0"
因此,就您而言,我会尝试:
$icon='...ANOTHERDIRECTORY...\vim.ico,0'
要么
$icon='...ANOTHERDIRECTORY...\\vim.ico,0'
已编辑
不要忘记重启explroer.exe来查看新图标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.