Click here to Skip to main content
15,922,696 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi everyone,

I have a proje with database and I have to create a setup file to run another computer. I try to setup but firstly, I need to know is there any MSSQLSERVER in computer. I searched some code about it and I found this code.
RegistryKey rk = Registry.LocalMachine.OpenSubKey("\\SOFTWARE\\Microsoft\\Microsoft SQL Server");
                String[] instances = (String[])rk.GetValue("InstalledInstances");




but everytime instances equal null everytime. but when I try to look myself on computer I find by hand. whats the wrong this code?


C#
RegistryKey rk = Registry.LocalMachine.OpenSubKey("\\SOFTWARE\\Microsoft\\Microsoft SQL Server");
                String[] instances = (String[])rk.GetValue("InstalledInstances");
               
                if (instances.Length > 0)
                {
                    foreach (String element in instances)
                    {

                        if (element == "MSSQLSERVER")
                        {
                            DialogResult res = MessageBox.Show("are u sure to setup this file?", "UYARI", MessageBoxButtons.YesNo);
                            if (res == DialogResult.Yes)
                            {
                                string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\SQLEXPR.EXE";
                                Process p = new Process();
                                p.StartInfo.FileName = path;
                                
                                p.StartInfo.Arguments = "/qb INSTANCENAME=\"SQLEXPRESS\" INSTALLSQLDIR=\"C:\\Program Files\\Microsoft SQL Server\" INSTALLSQLSHAREDDIR=\"C:\\Program Files\\Microsoft SQL Server\" INSTALLSQLDATADIR=\"C:\\Program Files\\Microsoft SQL Server\" ADDLOCAL=\"All\" SQLAUTOSTART=1 SQLBROWSERAUTOSTART=0 SQLBROWSERACCOUNT=\"NT AUTHORITY\\SYSTEM\" SQLACCOUNT=\"NT AUTHORITY\\SYSTEM\" SECURITYMODE=SQL SAPWD=\"\" SQLCOLLATION=\"SQL_Latin1_General_Cp1_CS_AS\" DISABLENETWORKPROTOCOLS=0 ERRORREPORTING=1 ENABLERANU=0";
                              
                                p.StartInfo.CreateNoWindow = true;
                              
                                p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                                p.Start();
                                
                                p.WaitForExit();
                                CreateDB();

                            }
                            else
                            {
                                
                                this.Close();
                            }
                        }
                    }
                }
Posted
Updated 21-Aug-11 6:29am
v2

Have you tried using SQL Management Objects[^] instead?
 
Share this answer
 
no i havent tried. what is it and how i can use it? this is a namespace?
 
Share this answer
 
Comments
[no name] 21-Aug-11 14:55pm    
Add a comment not an answer. Did you even look at the information in the link?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900