markus / KCOM_Helper / KCOM_Helper.cs @ master
이력 | 보기 | 이력해설 | 다운로드 (1.31 KB)
1 |
using Microsoft.Win32; |
---|---|
2 |
using System; |
3 |
using System.Data.Entity; |
4 |
using System.Linq; |
5 |
using System.Collections.Generic; |
6 |
|
7 |
namespace KCOM |
8 |
{ |
9 |
public class KCOM_Helper |
10 |
{ |
11 |
const string UriScheme = "sample"; |
12 |
const string FriendlyName = "Sample Protocol"; |
13 |
public static bool RegisteringURIScheme() |
14 |
{ |
15 |
try |
16 |
{ |
17 |
using (var key = Registry.CurrentUser.CreateSubKey("SOFTWARE\\Classes\\" + UriScheme)) |
18 |
{ |
19 |
string applicationLocation = System.Reflection.Assembly.GetExecutingAssembly().Location.Replace("KCOM_Helper.dll", "KCOM.exe"); |
20 |
|
21 |
key.SetValue("", "URL:" + FriendlyName); |
22 |
key.SetValue("URL Protocol", ""); |
23 |
|
24 |
using (var defaultIcon = key.CreateSubKey("DefaultIcon")) |
25 |
{ |
26 |
defaultIcon.SetValue("", applicationLocation + ",1"); |
27 |
} |
28 |
|
29 |
using (var commandKey = key.CreateSubKey(@"shell\open\command")) |
30 |
{ |
31 |
commandKey.SetValue("", "\"" + applicationLocation + "\" \"%1\""); |
32 |
} |
33 |
} |
34 |
return true; |
35 |
} |
36 |
catch (Exception ex) |
37 |
{ |
38 |
return false; |
39 |
} |
40 |
} |
41 |
} |
42 |
} |