質問をした後、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 としてコンパイルされていたので、これを理解するのにしばらく時間がかかりました。私が最初に見逃したのは、プロジェクトのプロパティにあるこの小さなフラグでした:
