public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
            {
                if (_standardValues == null)
                {
                    string[] dataSources = null;

                    if (HelpUtils.IsWow64())
                    {
                        List <String> dataSourceList = new List <String>();
                        // Read 64 registry key of SQL Server Instances Names.
                        dataSourceList.AddRange(HelpUtils.GetValueNamesWow64("SOFTWARE\\Microsoft\\Microsoft SQL Server\\Instance Names\\SQL", NativeMethods.KEY_WOW64_64KEY | NativeMethods.KEY_QUERY_VALUE));
                        // Read 32 registry key of SQL Server Instances Names.
                        dataSourceList.AddRange(HelpUtils.GetValueNamesWow64("SOFTWARE\\Microsoft\\Microsoft SQL Server\\Instance Names\\SQL", NativeMethods.KEY_WOW64_32KEY | NativeMethods.KEY_QUERY_VALUE));
                        dataSources = dataSourceList.ToArray();
                    }
                    else
                    {
                        // Look in the registry for all local SQL Server instances
                        Win32.RegistryKey key = Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Microsoft SQL Server\\Instance Names\\SQL");
                        if (key != null)
                        {
                            using (key)
                            {
                                dataSources = key.GetValueNames();
                            }                             // key is Disposed here
                        }
                    }

                    if (dataSources != null)
                    {
                        for (int i = 0; i < dataSources.Length; i++)
                        {
                            if (String.Equals(dataSources[i], "MSSQLSERVER", StringComparison.OrdinalIgnoreCase))
                            {
                                dataSources[i] = ".";
                            }
                            else
                            {
                                dataSources[i] = ".\\" + dataSources[i];
                            }
                        }
                        _standardValues = new StandardValuesCollection(dataSources);
                    }
                    else
                    {
                        _standardValues = new StandardValuesCollection(new string[0]);
                    }
                }
                return(_standardValues);
            }
Esempio n. 2
0
        private static string ReadRegistryString(Win32.RegistryKey key, string path, string registryValue)
        {
            RegistryKey subKey = key.OpenSubKey(path, false);

            if (subKey != null)
            {
                object oValue = subKey.GetValue(registryValue);
                if (oValue != null && subKey.GetValueKind(registryValue) == RegistryValueKind.String)
                {
                    return((string)oValue);
                }
            }

            return(null);
        }
        /// <summary>
        /// Gets the Location of devenv.exe based on the RegistryRoot for the current package type
        /// </summary>
        private string getVSInstallDir(RegistrationContext context)
        {
            DefaultRegistryRootAttribute regRootAttr = (DefaultRegistryRootAttribute)TypeDescriptor.GetAttributes(context.ComponentType)[typeof(DefaultRegistryRootAttribute)];

            if (regRootAttr == null)
            {
                throw new NotSupportedException("could not find DefaultRegitryRootAttribute on " + context.ComponentType.ToString());
            }

            Win32.RegistryKey key = Win32.Registry.LocalMachine.OpenSubKey(regRootAttr.Root);
            //We are using HKCU in the case that the HKLM Experimental hive doesn't exist
            if (key == null || key.GetValue("InstallDir") == null)
            {
                key = Win32.Registry.CurrentUser.OpenSubKey(regRootAttr.Root + @"\Configuration");
            }
            string vsInstallDir = (string)key.GetValue("InstallDir");

            key.Close();
            return(vsInstallDir);
        }
Esempio n. 4
0
        public static void InitSLApi()
        {
            // check if already initialized
            if (true == m_bSLApiInit)
            {
                return;
            }

            // we must check if debug pack is installed

            Win32.RegistryKey netFrameworkKey = null;
            IntPtr            procAddr        = IntPtr.Zero;

            try
            {
                netFrameworkKey = Win32.Registry.LocalMachine.OpenSubKey(
                    m_strNetFramework,
                    false);

                if (null == netFrameworkKey)
                {
                    throw new System.Exception("Unable to open the .NET Registry key: HKLM\\" + m_strNetFramework);
                }

                m_strDbgPackShimPath = (string)netFrameworkKey.GetValue(
                    m_strValDbgPackShimPath,
                    null,
                    RegistryValueOptions.DoNotExpandEnvironmentNames);

                if (null == m_strDbgPackShimPath)
                {
                    throw new System.Exception("Unable to open up the DbgPackShimPath registry key: HKLM\\" + m_strNetFramework + "\\" + m_strDbgPackShimPath);
                }

                // now initializing all the func ptrs
                m_hndModuleMscoree = LoadLib(m_strDbgPackShimPath);

                procAddr = GetProcAddr(m_hndModuleMscoree, "CreateDebuggingInterfaceFromVersion");
                if (IntPtr.Zero == procAddr)
                {
                    throw new Exception("Failed to get address of dbgshim!CreateDebuggingInterfaceFromVersion");
                }
                else
                {
                    m_CreateDebuggingInterfaceFromVersion = (delgCreateDebuggingInterfaceFromVersion)Marshal.GetDelegateForFunctionPointer(
                        procAddr,
                        typeof(delgCreateDebuggingInterfaceFromVersion));
                }

                try
                {
                    procAddr = GetProcAddr(m_hndModuleMscoree, "CreateDebuggingInterfaceFromVersionEx");
                }
                catch (Win32Exception)
                {
                    procAddr = IntPtr.Zero;
                }
                if (IntPtr.Zero == procAddr)
                {
                    m_CreateDebuggingInterfaceFromVersionEx = null;
                    Console.WriteLine("This Silverlight/CoreCLR version doesn't have CDIFVex");
                }
                else
                {
                    m_CreateDebuggingInterfaceFromVersionEx = (delgCreateDebuggingInterfaceFromVersionEx)Marshal.GetDelegateForFunctionPointer(
                        procAddr,
                        typeof(delgCreateDebuggingInterfaceFromVersionEx));
                }

                procAddr = GetProcAddr(m_hndModuleMscoree, "CreateVersionStringFromModule");
                if (IntPtr.Zero == procAddr)
                {
                    throw new Exception("Failed to get address of dbgshim!CreateVersionStringFromModule");
                }
                else
                {
                    m_CreateVersionStringFromModule = (delgCreateVersionStringFromModule)Marshal.GetDelegateForFunctionPointer(
                        procAddr,
                        typeof(delgCreateVersionStringFromModule));
                }

                procAddr = GetProcAddr(m_hndModuleMscoree, "EnumerateCLRs");
                if (IntPtr.Zero == procAddr)
                {
                    throw new Exception("Failed to get address of dbgshim!EnumerateCLRs");
                }
                else
                {
                    m_EnumerateCLRs = (delgEnumerateCLRs)Marshal.GetDelegateForFunctionPointer(
                        procAddr,
                        typeof(delgEnumerateCLRs));
                }

                procAddr = GetProcAddr(m_hndModuleMscoree, "CloseCLREnumeration");
                if (IntPtr.Zero == procAddr)
                {
                    throw new Exception("Failed to get address of dbgshim!CloseCLREnumeration");
                }
                else
                {
                    m_CloseCLREnumeration = (delgCloseCLREnumeration)Marshal.GetDelegateForFunctionPointer(
                        procAddr,
                        typeof(delgCloseCLREnumeration));
                }

                procAddr = GetProcAddr(m_hndModuleMscoree, "GetStartupNotificationEvent");
                if (IntPtr.Zero == procAddr)
                {
                    throw new Exception("Failed to get address of dbgshim!GetStartupNotificationEvent");
                }
                else
                {
                    m_GetStartupNotificationEvent = (delgGetStartupNotificationEvent)Marshal.GetDelegateForFunctionPointer(
                        procAddr,
                        typeof(delgGetStartupNotificationEvent));
                }

                // We are done initializing
                m_bSLApiInit = true;
            }


            finally
            {
                if (null != netFrameworkKey)
                {
                    netFrameworkKey.Close();
                }

                // we will keep the cached handle to loaded mscoree.dll
                // around for a while..........
            }
        }