RegOpenKeyEx() private method

private RegOpenKeyEx ( uint hKey, string lpSubKey, uint ulOptions, int samDesired, int &phkResult ) : int
hKey uint
lpSubKey string
ulOptions uint
samDesired int
phkResult int
return int
コード例 #1
0
ファイル: GetLocalInstances.cs プロジェクト: jryder/Resume
        private static IEnumerable <string> LocalInstances(uint flag)
        {
            // Get local instances for us
            var mssqlKey = UIntPtr.Zero;

            try
            {
                Win32.RegOpenKeyEx(Win32.HKEY_LOCAL_MACHINE, @"Software\Microsoft\Microsoft SQL Server", 0, Win32.KEY_QUERY_VALUE | flag, out mssqlKey);

                if (mssqlKey == UIntPtr.Zero)
                {
                    return(new List <string>());
                }

                var instances = Win32.RegQueryValue(mssqlKey, "InstalledInstances") as string[];
                if (instances == null)
                {
                    return(new List <string>());
                }

                return(new List <string>(instances));
            }
            finally
            {
                if (mssqlKey != UIntPtr.Zero)
                {
                    Win32.RegCloseKey(mssqlKey);
                }
            }
        }
コード例 #2
0
ファイル: css_config.cs プロジェクト: wtf3505-git/cs-script
    static public string RegGetValueExp(uint key, string subKey, string valName)
    {
        //this method is required in order to rtreive REG_EXPAND_SZ registry value
        const int KEY_READ = 0x00000001;
        int       hkey     = 0;

        try
        {
            if (0 == Win32.RegOpenKeyEx(key, subKey, 0, KEY_READ, out hkey))
            {
                StringBuilder sb       = new StringBuilder(1024 * 10);
                int           lpcbData = sb.Capacity;
                uint          lpType;
                if (0 == RegQueryValueEx(hkey, valName, 0, out lpType, sb, ref lpcbData))
                {
                    return(sb.ToString());
                }
            }
        }
        finally
        {
            if (0 != hkey)
            {
                RegCloseKey(hkey);
            }
        }
        return(null);
    }