簡體   English   中英

如何將圖標與自定義應用程序關聯(已注冊Powershell腳本)

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM