How to launch Windows' RegEdit with certain path?

前端 未结 13 1132
盖世英雄少女心
盖世英雄少女心 2020-12-08 04:15

How do I launch Windows\' RegEdit with certain path located, like \"HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\8.0\", so I don\'t have to do the clic

13条回答
  •  孤城傲影
    2020-12-08 04:35

    I thought this C# solution might help:

    By making use of an earlier suggestion, we can trick RegEdit into opening the key we want even though we can't pass the key as a parameter.

    In this example, a menu option of "Registry Settings" opens RegEdit to the node for the program that called it.

    Program's form:

        private void registrySettingsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string path = string.Format(@"Computer\HKEY_CURRENT_USER\Software\{0}\{1}\",
                                        Application.CompanyName, Application.ProductName);
    
            MyCommonFunctions.Registry.OpenToKey(path);
    
        }
    

    MyCommonFunctions.Registry

        /// Opens RegEdit to the provided key
        /// @"Computer\HKEY_CURRENT_USER\Software\MyCompanyName\MyProgramName\"
        /// 
        /// 
        public static void OpenToKey(string FullKeyPath)
        {
            RegistryKey rKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Applets\Regedit", true);
            rKey.SetValue("LastKey",FullKeyPath);
    
            Process.Start("regedit.exe");
        }
    

    Of course, you could put it all in one method of the form, but I like reusablity.

提交回复
热议问题