在PowerShell中從網絡共享驅動器訪問的時候,我無法加載圖標可例外網絡共享ExtractAssociatedIcon使用PowerShell
$IconPath = $pwd.Path + "\Icons\InstallIcon-F.ico"
$HFForm.icon = [System.Drawing.Icon]::ExtractAssociatedIcon($IconPath)
我收到此錯誤:
Exception calling "ExtractAssociatedIcon" with "1" argument(s): "The given path's format is not supported."
$HFForm.icon = [System.Drawing.Icon]::ExtractAssociatedIcon <<<< ($IconPath)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
'System.Drawing.Icon.ExtractAssociatedIcon()'不應該像(\\服務器\路徑)UNC路徑的工作,但我得到一個不同的錯誤使用UNC路徑:'\ \ server \ path'對於'filePath'無效'「,但它可能只是一個不同的PowerShell版本的消息,你確定$ pwd.Path是一個有效的路徑嗎?它是UNC格式嗎? – PeterK
是的,我確定路徑是有效的,我檢查了相同的次數,如果我嘗試以不同的方式組合$ IconPath,我得到了「無效的」filePath'。「的異常。仍然是從網絡驅動器圖標沒有得到加載 – swatish
不幸的是,這是.NET框架中的'ExtractAssociatedIcon()'方法的限制。在http: //stackoverflow.com/questions/1842226/how-to-get-the-associated-icon-from-a-network-share-file建議您使用P/Invoke作爲解決方法直接與Windows Shell API進行交互。您可以使用內聯C#導入大部分示例代碼而無需進行更改(請參閱http://technet.microsoft.com/zh-cn/library/hh849914.aspx上的Add-Type和示例)。 – PeterK