C # Read the registry and dynamically run the program

Source: Internet
Author: User

Call method:
1 CallRegistry. call_CurrentUser_Fun (subitem: "SOFTWARE \ XXXNode \", propertyname: "propertyXXX", param: "-mc D: \ xxx \ Book \ xxx.pdf ");
Static class:

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}

 

Author: Lightrain

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.