8

プロトコル リンクを処理する小さなプロジェクトがありtel:ます。これは、Visual Studio 2013 Community Edition を使用して開発しているデスクトップ アプリケーションです。

以前は、簡単なレジストリ変更でハンドラーを登録していました。

Microsoft.Win32.Registry.SetValue(registryKey, string.Empty, registryValue, Microsoft.Win32.RegistryValueKind.String);
Microsoft.Win32.Registry.SetValue(registryKey, "URL Protocol", String.Empty, Microsoft.Win32.RegistryValueKind.String);

registryKey = @"HKEY_CLASSES_ROOT\tel\shell\open\command";
registryValue = "\"" + AppDomain.CurrentDomain.BaseDirectory + "TelProtocolHandler.exe\" \"%1\"";
Microsoft.Win32.Registry.SetValue(registryKey, string.Empty, registryValue, Microsoft.Win32.RegistryValueKind.String);

ただし、これは Windows 8 では機能しないようです。レジストリ キーには目的の値がありますが、リンクは別のアプリケーションによって処理されます。私のツールは、プロトコル ハンドラーの選択にも表示されません。

ここに画像の説明を入力

ウォークスルー: Windows 8 カスタム プロトコル アクティベーションの使用 を見てきましたが、記載されている情報をアプリケーションに関連付けることができません。.appxmanifestこの記事では、私のプロジェクトにないファイルについて言及しており、新しいアイテムとして追加することはできません。

4

1 に答える 1

11

質問をした後、Windows 8 でプロトコル ハンドラーを登録することに遭遇しました。

他にも問題はありましたが、そこで投票された上位の回答により、正しい軌道に乗ることができました。結局、これは私が最終的に得たものです:

// Register as the default handler for the tel: protocol.
const string protocolValue = "TEL:Telephone Invocation";
Registry.SetValue(
    @"HKEY_CLASSES_ROOT\tel",
    string.Empty,
    protocolValue,
    RegistryValueKind.String );
Registry.SetValue(
    @"HKEY_CLASSES_ROOT\tel",
    "URL Protocol",
    String.Empty,
    RegistryValueKind.String );

const string binaryName = "tel.exe";
string command = string.Format( "\"{0}{1}\" \"%1\"", AppDomain.CurrentDomain.BaseDirectory, binaryName );
Registry.SetValue( @"HKEY_CLASSES_ROOT\tel\shell\open\command", string.Empty, command, RegistryValueKind.String );

// For Windows 8+, register as a choosable protocol handler.

// Version detection from https://stackoverflow.com/a/17796139/259953
Version win8Version = new Version( 6, 2, 9200, 0 );
if( Environment.OSVersion.Platform == PlatformID.Win32NT &&
    Environment.OSVersion.Version >= win8Version ) {
    Registry.SetValue(
        @"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\TelProtocolHandler",
        string.Empty,
        protocolValue,
        RegistryValueKind.String );
    Registry.SetValue(
        @"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\TelProtocolHandler\shell\open\command",
        string.Empty,
        command,
        RegistryValueKind.String );

    Registry.SetValue(
        @"HKEY_LOCAL_MACHINE\SOFTWARE\TelProtocolHandler\Capabilities\URLAssociations",
        "tel",
        "TelProtocolHandler",
        RegistryValueKind.String );
    Registry.SetValue(
        @"HKEY_LOCAL_MACHINE\SOFTWARE\RegisteredApplications",
        "TelProtocolHandler",
        @"SOFTWARE\TelProtocolHandler\Capabilities",
        RegistryValueKind.String );
}

TelProtocolHandlerは私のアプリケーションの名前であり、ハンドラーの名前に置き換えてください。

他の質問で受け入れられた回答もApplicationDescriptionレジストリにあります。チェックした他の登録済みハンドラーのいずれにも同じキーが見つからなかったため、除外して問題を検出できませんでした。

もう 1 つの重要な問題は、ハンドラーをセットアップするアプリケーションが 32 ビットの場合、これらすべてが機能しないことでした。Wow6432Node でエントリが作成されると、特定のプロトコルのデフォルトとしてハンドラーを選択できませんでした。私のアプリケーションは AnyCPU としてコンパイルされていたので、これを理解するのにしばらく時間がかかりました。私が最初に見逃したのは、プロジェクトのプロパティにあるこの小さなフラグでした:

ここに画像の説明を入力

于 2014-12-03T09:25:46.910 に答える