2017-10-19 76 views
0

我一直在試圖製作bat腳本或PowerShell腳本,將.tif和.tiff文件的關聯文件更改爲Modi中的MSP程序。PowerShell腳本更改tiff和tiff文件的關聯

我目前糟糕的代碼看起來是這樣的,它不會與微軟MSP程序正確打開文件

assoc .tif=TIFImage.Document 
ftype TIFImage.Document="C:\Program Files (x86)\Common Files\microsoft shared\MODI\12.0\MSPVIEW.exe" "%1" 

assoc .tiff=TIFImage.Document 
ftype TIFImage.Document="C:\Program Files (x86)\Common Files\microsoft shared\MODI\12.0\MSPVIEW.exe" "%1" 

回答

0

assocftype是CMD內置命令,而不是外部程序,所以你需要運行他們通過cmd /c如果你想從PowerShell使用它們。此外,PowerShell在分析參數到ftype命令時會做些時髦的事情,所以您需要「魔法參數」(--%)來阻止它這樣做。

cmd /c assoc .tif=TIFImage.Document 
cmd /c assoc .tiff=TIFImage.Document 
cmd /c --% ftype TIFImage.Document="C:\Pro...IEW.exe" "%1" 
+0

是否有與此代碼等價的powershell? – user1378803

+0

你是什麼意思「等效的PowerShell」? *是您在PowerShell中運行的代碼。 –

+0

我的意思是隻使用ps ...上面的代碼調用cmd ...有沒有辦法在ps中做到這一點? – user1378803