程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C#讀取注冊表,動態運行程序

C#讀取注冊表,動態運行程序

編輯:C#入門知識

調用方法:
1 CallRegistry.Call_CurrentUser_Fun(subitem: "SOFTWARE\\XXXNode\\", propertyname: "propertyXXX", param: " -mc D:\\xxx\\Book\\xxx.pdf");
靜態類:

01 public static class CallRegistry
02     {
03         public static int Call_CurrentUser_Fun(string subitem, string propertyname, stringparam)
04         {
05 
06             RegistryKey key = Registry.CurrentUser;
07             RegistryKey appitem = key.OpenSubKey(subitem, false);
08 
09             if (null == appitem)
10             {
11                 return -1;
12             }
13             string appPath = appitem.GetValue(propertyname).ToString();
14             if (String.IsNullOrEmpty(appPath))
15             {
16                 return -2;
17             }
18             ProcessStartInfo psi = new ProcessStartInfo(appPath);
19             psi.UseShellExecute = false;
20             Process process = new Process();
21 
22             if (!String.IsNullOrEmpty(param))
23             {
24                 psi.Arguments = param;
25             }
26             process.StartInfo = psi;
27             bool result = process.Start();
28             return result ? 1 : 0;
29         }
30 
31         public static int Call_CurrentUser_Fun(string subitem, string propertyname, string[] args)
32         {
33             StringBuilder param = new StringBuilder();
34             if (args != null)
35             {
36                 foreach (string tmpParam in args)
37                 {
38                     param.Append(tmpParam).Append(" ");
39                 }   www.2cto.com
40             }
41             return Call_CurrentUser_Fun(subitem, propertyname, param.ToString());
42         }
43     }

 

作者:Lightrain

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved