C# 读取注册表,动态运行程序.

没有什么好说的,直接上代码了.

调用方法:

CallRegistry.Call_CurrentUser_Fun(subitem: "SOFTWARE\\XXXNode\\", propertyname: "propertyXXX", param: " -mc D:\\xxx\\Book\\xxx.pdf");

静态类:

public static class CallRegistry
    {
        public static int Call_CurrentUser_Fun(string subitem, string propertyname, string param)
        {

            RegistryKey key = Registry.CurrentUser;
            RegistryKey appitem = key.OpenSubKey(subitem, false);

            if (null == appitem)
            {
                return -1;
            }
            string appPath = appitem.GetValue(propertyname).ToString();
            if (String.IsNullOrEmpty(appPath))
            {
                return -2;
            }
            ProcessStartInfo psi = new ProcessStartInfo(appPath);
            psi.UseShellExecute = false;
            Process process = new Process();

            if (!String.IsNullOrEmpty(param))
            {
                psi.Arguments = param;
            }
            process.StartInfo = psi;
            bool result = process.Start();
            return result ? 1 : 0;
        }

        public static int Call_CurrentUser_Fun(string subitem, string propertyname, string[] args)
        {
            StringBuilder param = new StringBuilder();
            if (args != null)
            {
                foreach (string tmpParam in args)
                {
                    param.Append(tmpParam).Append(" ");
                }
            }
            return Call_CurrentUser_Fun(subitem, propertyname, param.ToString());
        }
    }

你可能感兴趣的:(C#,process,regedit,读取注册表,动态运行程序)