网页唤醒winform程序

以VSDebug.exe为例,完整程序路径D:\软件代码\代码调试\VSDebug\VSDebug\bin\Debug\VSDebug.exe
实际只需要VSDebug这个程序集产品名称就足够了,可以通过Form.ProductName来获取,
然后直接代入到程序方法中就可以直接使用了
 1         private void MDIForm_Load(object sender, EventArgs e)
 2         {
 3             GetRegistData(this.ProductName);
 4         }
 5 
 6         /// <summary>
 7         /// 写入注册表以使用网页唤醒程序
 8         /// </summary>
 9         public static void GetRegistData(string name)
10         {
11             /**搜索到注册表根目录**/
12             RegistryKey hkml = Registry.ClassesRoot;
13             /**搜索到注册表根目录下的name文件夹**/
14             RegistryKey software = hkml.OpenSubKey(name, true);
15             if (software == null)
16             {
17                 /**注册表未注册,添加注册表**/
18                 Enroll(name);
19             }
20         }
21 
22         /// <summary>
23         /// 写入注册表
24         /// </summary>
25         public static void Enroll(string name)
26         {
27             /**获取新的 Process 组件并将其与当前活动的进程关联的主模块的完整路径,包含文件名(进程名)。**/
28             string str = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
29             RegistryKey regWrite = Registry.ClassesRoot.CreateSubKey(name);
30 
31             regWrite.SetValue(name.ToLower(), @"URL:" + str);
32             regWrite.SetValue("URL Protocol", "URL Protocol");//不行可以删来看看
33             regWrite.Close();
34 
35             regWrite = Registry.ClassesRoot.CreateSubKey(name + @"\shell");
36             regWrite.Close();
37             regWrite = Registry.ClassesRoot.CreateSubKey(name + @"\shell\open");
38             regWrite.Close();
39             regWrite = Registry.ClassesRoot.OpenSubKey(name + @"\shell\open", true);
40             RegistryKey aimdir = regWrite.CreateSubKey("command");
41             /**获取程序运行地址**/
42             string BaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
43             string AppPath = Path.Combine(BaseDirectory, name + ".exe");
44 
45             aimdir.SetValue(@"", "\"" + str + "\" \" %1\"");
46             regWrite.Close();
47             aimdir.Close();
48         }

 


因为注册表注册的时候是要管理员权限的,所以下面是获取管理员权限的一直办法。

 

 

 

 注册完之后,你就可以用唤醒的名字去浏览器输入VSDebug://,然后回车就出现一个要打开VSDebug程序的弹窗了。

 

 

 

 

原文路径:https://www.cnblogs.com/lianglingui/archive/2022/11/28/16812362.html

posted @ 2022-11-29 10:50  感冒药啊  阅读(110)  评论(0)    收藏  举报