用於 Windows 8 中關聯應用程式的 PowerShell 腳本(可能使用 ftype / assoc)

用於 Windows 8 中關聯應用程式的 PowerShell 腳本(可能使用 ftype / assoc)

在 Windows XP / Vista / 7 中,透過使用 ftype 和 assoc 可以輕鬆地將項目從預設值重新關聯起來,如下所示。這在系統設定中可以節省大量時間,以確保所有關聯都符合使用者的要求,否則在新安裝中重新關聯每個分機將非常耗時。

在 Windows 8 中,這一切現在似乎都不起作用。例如,.pdf 檔案現在預設與 Microsoft 的 Metro 應用程式「Reader」關聯。在新的Windows 8 安裝中,必須手動將許多(10 種或數百種文件類型)重新關聯到標準桌面應用程式(例如.pdf 應與Adob​​e Reader 而不是Microsoft Reader 關聯)將是一件苦差事。以下是我如何在 Windows 7 中使用 cmd 腳本執行此操作的範例,但顯然隨著 PowerShell 的進步,它可能更適合在 Windows 8 中執行此操作(另外,我懷疑可能需要訪問 .NET 來更改這些 Metro關聯,而cmd 對於這項工作來說是一個糟糕的工具)。

我不認為 Metro 應用程式很糟糕(在平板電腦上它們是理想的),問題是與桌面應用程式相比,它們的功能非常有限,因此能夠快速重新關聯所有內容(腳本化)會很好到桌面應用程式(或者如果我在平板電腦上工作並希望在該用例中與Metro 應用程式關聯的所有內容,則相反)。

:: File assoc and ftype: RAR, ZIP, NFO, DIZ, CBR, CBZ, DJVU, etc
:: ####################
:: Note: at commandline, would type ftype txtNFO="%SystemRoot%\system32\NOTEPAD.EXE" "%1"
:: but in batch script have to double up the % characters, ftype txtNFO="%SystemRoot%\system32\NOTEPAD.EXE" "%%1"
:: plus note the " characters, have to be careful about these
if exist "C:\Program Files (x86)\7-Zip\7zFM.exe" ftype 7zFM="C:\Program Files (x86)\7-Zip\7zFM.exe" "%%1"
if exist "C:\Program Files\7-Zip\7zFM.exe" ftype 7zFM="C:\Program Files\7-Zip\7zFM.exe" "%%1"ftype txtNFO="%%SystemRoot%%\system32\NOTEPAD.EXE" "%%1"
ftype txtDIZ="%%SystemRoot%%\system32\NOTEPAD.EXE" "%%1"
ftype QuickPAR="D:\Toolkit\QuickPAR\QuickPAR.exe" "%%1"
ftype CDisplay="D:\Toolkit\CDisplay\CDisplay.exe" "%%1"
if exist "D:\Toolkit\Microsoft Reader\msreader.exe"         ftype MSReader="D:\Toolkit\Microsoft Reader\msreader.exe" "%%1"
if exist "D:\Toolkit\Mobipocket Reader\reader.exe"          ftype MobiPocket="D:\Toolkit\Mobipocket Reader\reader.exe" "%%1"
if exist "D:\Toolkit\Stanza\Stanza.exe"                     ftype Stanza="D:\Toolkit\Stanza\Stanza.exe" "%%1"
assoc .lit=MSReader
assoc .mobi=MobiPocket
assoc .prc=MobiPocket
assoc .azw=MobiPocket
assoc .epub=Stanza
assoc .par=QuickPAR
assoc .par2=QuickPAR
assoc .sfv=QuickPAR
assoc .md5=QuickPAR
assoc .7z=7zFM
assoc .rar=7zFM
assoc .zip=7zFM

相關內容