Read a Registry Key

前端 未结 5 2127
傲寒
傲寒 2020-12-03 01:44

I have a web application which is importing DLLs from the bin folder.

const string dllpath = \"Utility.dll\";

    [DllImport(dllpath)]

Now

5条回答
  •  忘掉有多难
    2020-12-03 02:01

    You can use this:

    /// 
    /// To read a registry key.
    /// input: KeyName (string)
    /// output: value (string) 
    /// 
    public string Read(string KeyName)
    {
        // Opening the registry key
        RegistryKey rk = baseRegistryKey ;
        // Open a subKey as read-only
        RegistryKey sk1 = rk.OpenSubKey(subKey);
        // If the RegistrySubKey doesn't exist -> (null)
        if ( sk1 == null )
        {
            return null;
        }
        else
        {
            try 
            {
                // If the RegistryKey exists I get its value
                // or null is returned.
                return (string)sk1.GetValue(KeyName.ToUpper());
            }
            catch (Exception e)
            {
                // AAAAAAAAAAARGH, an error!
                ShowErrorMessage(e, "Reading registry " + KeyName.ToUpper());
                return null;
            }
        }
    }
    

    For more information visit this web site .

提交回复
热议问题