2012-11-26 99 views
12

我在嘗試註冊我的應用程序,該程序將處理鏈接的打開,例如,http://stackoverflow.com。我需要爲Windows 8明確地執行此操作,而且我可以在早期版本的Windows中執行此操作。根據MSDN這在Win8中發生了變化。在Windows 8中註冊協議處理程序

我已經瀏覽了MSDN上的MSDN(msdn.microsoft.com/en-us/library/cc144154.aspx)頁面上的默認程序頁面。它提供了一個處理文件類型的很好的演練,但對協議的細節很簡單。 Registering an Application to a URL Protocol只涉及設置新協議所涉及的步驟,而不涉及如何向現有協議正確添加新處理程序。

我也嘗試了其他SO帖子中列出的註冊表設置。

還有一件事,該應用程序不是Metro/Windows應用商店應用程序,因此在清單中添加條目對我無效。

回答

-4

LaunchUriAsync(URI)

啓動與指定URI的URI方案名稱相關聯的默認的應用程序。 在這種情況下,您可以允許用戶指定。

http://msdn.microsoft.com/library/windows/apps/Hh701476

// Create the URI to launch from a string. 
    var uri = new Uri(uriToLaunch); 

    // Calulcate the position for the Open With dialog. 
    // An alternative to using the point is to set the rect of the UI element that triggered the launch. 
    Point openWithPosition = GetOpenWithPosition(LaunchUriOpenWithButton); 

    // Next, configure the Open With dialog. 
    // Here is where you choose the program. 
    var options = new Windows.System.LauncherOptions(); 
    options.DisplayApplicationPicker = true; 
    options.UI.InvocationPoint = openWithPosition; 
    options.UI.PreferredPlacement = Windows.UI.Popups.Placement.Below; 

    // Launch the URI. 
    bool success = await Windows.System.Launcher.LaunchUriAsync(uri, options); 
    if (success) 
    { 
     // URI launched: uri.AbsoluteUri 
    } 
    else 
    { 
     // URI launch failed. uri.AbsoluteUri 

    } 
+5

這個細節如何通過URI啓動。我想要做的是註冊我的應用程序,當另一個應用程序啓動這樣的URI時啓動。 – Josh

11

你在正確的軌道與默認程序的網頁上 - 事實上,這是我對這個職位的參考。

下適應自己的例子:

首先,你需要一個在ProgIDHKLM\SOFTWARE\Classes是決定如何處理提供給它的任何輸入(您可能已經存在):

HKLM\SOFTWARE\Classes 
    MyApp.ProtocolHandler //this is the ProgID, subkeys are its properties 
     (Default) = My Protocol //name of any type passed to this 
     DefaultIcon 
      (Default) = %ProgramFiles%\MyApp\MyApp.exe, 0 //for example 
     shell 
      open 
       command 
       (Default) = %ProgramFiles%\MyApp\MyApp.exe %1 //for example 

然後填寫註冊表用Capabilities鍵內DefaultProgram信息:

HKLM\SOFTWARE\MyApp 
    Capabilities 
     ApplicationDescription 
      URLAssociations 
       myprotocol = MyApp.ProtocolHandler //Associated with your ProgID 

最後,註冊您的應用程序的能力w ^第i個DefaultPrograms:

HKLM\SOFTWARE 
     RegisteredApplications 
     MyApplication = HKLM\SOFTWARE\MyApp\Capabilities 

現在所有 「myprotocol:」 鏈接應觸發%ProgramFiles%\MyApp\MyApp.exe %1

+0

即時通訊這個概念很新。你能告訴我如何運行上面的代碼? – jammy

+0

這不是代碼。你需要閱讀訪問Windows註冊表。代碼片段是註冊表中的鍵和值。 –

+0

如果你不知道,如果你的協議規定,您還需要添加這樣的: '[HKEY_CLASSES_ROOT \ myprotocol] (默認值)= 「URL:myprotocol」 「URL協議」= 「」' – Daniel

3

邊注,因爲這是谷歌搜索這類問題的時候發現了一個頂端回答: 確保在shell命令路徑開放是正確的路徑您的應用程序。 我花了整整一天的調試問題,似乎隻影響Windows和Windows 10上的Chrome和Edge。他們從未觸發協議處理程序,而Firefox的。 問題是什麼? .bat文件的路徑混合使用 \和/斜線。 在路徑中只使用正確的\斜槓& Chrome突然能夠提取請求。

+0

謝謝!一般來說,像這樣的東西應該保存以備評論。 – Arithmomaniac

+0

這應該是對接受答案的評論,因爲這不是答案本身。 – MrTux

相關問題