4

I need to find whether SQL Server Management Studio is installed on a system or not. I need this specially when an instance of SQL Server Express is installed on a system by installing Visual Studio but with no Management Studio installed on the system.

For more information, I can find all instances of SQL Server installed on a system but I need to understand that is Management Studio also installed on system or not.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Shima.Y
  • 373
  • 4
  • 9
  • 18
  • 1
    Is it must to do Programmatically? If yes, mention the reason for it. – DhavalR Jan 16 '16 at 06:03
  • 1
    yes it must be pragmatically because I wanna to understand this at the beginning of my application setup on my user's machine – Shima.Y Jan 16 '16 at 06:06
  • 2
    Check this link. http://stackoverflow.com/questions/908850/get-installed-applications-in-a-system – DhavalR Jan 16 '16 at 06:09
  • 1
    thanx , but what is the name of SSMS in registry ? – Shima.Y Jan 16 '16 at 06:35
  • 1
    SQL 2005 SSMS stores its settings at `HKEY_CURRENT_USER\Software\Microsoft\Microsoft SQL Server\90\Tools\Shell` SQL 2008 SSMS stores its settings at `HKEY_CURRENT_USER\Software\Microsoft\Microsoft SQL Server\100\Tools\Shell` – DhavalR Jan 16 '16 at 06:39
  • The question is unclear because of the ending question mark. You want to know if you need to understand if SSMS is installed? o_O – Paolo Jan 16 '16 at 06:43
  • What will you do if it's not? If the answer is "install it", you may as well just kick that off anyway. The installer will exit quite quickly if it is in fact already installed. – Damien_The_Unbeliever Jan 16 '16 at 06:45
  • it is duplicate in : http://stackoverflow.com/questions/2443001/check-if-sql-server-is-installed-on-a-machine-through-c-sharp – Ahmed Galal Jan 17 '16 at 07:28

2 Answers2

3

You can check its registry key and see if it returns null:

private RegistryKey _regSql = Registry.LocalMachine.OpenSubKey
            (@"HKLM\Software\Classes\Applications\sqlwb.exe", false);

if (_regSql == null) //If it's null then  SQL Server management is not installed
{
   //Do something
}

Also the are two more registry locations you can check:

HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\SSMSEE
SOFTWARE\Microsoft\Microsoft SQL Server\90\Tools\ClientSetup

Edit

According to this documents, while using the address SOFTWARE\Microsoft\Microsoft SQL Server\90\Tools\ClientSetup change the the number part (90) based on the versions you want to check:

90   | SQL Server 2008
100  | SQL Server 2008 R2
110  | SQL Server 2012
120  | SQL Server 2014 
130  | SQL Server 2016
140  | SQL Server 2017
Ondrej Janacek
  • 12,486
  • 14
  • 59
  • 93
Ghasem
  • 14,455
  • 21
  • 138
  • 171
  • I have SQL server management studio installed on my machine, I checked it by 90 , it returned null , but I checked it with 100 and it returned value not null, is it ok ? I mean I must check with both 90 and 100 for each machine ? – Shima.Y Jan 16 '16 at 06:47
  • @Shima.Y Try the other two registry addresses first and see if they work as *Those are mentioned more in other documents* – Ghasem Jan 16 '16 at 06:49
  • I checked 3 addresses above in your answer but all of them returned null , but 100 returned not null value – Shima.Y Jan 16 '16 at 07:00
  • @Shima.Y Do you have `SQL Server 2008` installed on your machine? – Ghasem Jan 16 '16 at 07:08
1

you can use WMI as has been mentioned:

ManagementObjectSearcher mos = new ManagementObjectSearcher("SELECT * FROM Win32_Product");
foreach(ManagementObject mo in mos.Get())
{
       if(mo["Name"].ToString().Equals("Application Name")) //
       {
         return true;
       }
}
Niklas
  • 955
  • 15
  • 29
Tanmay Nehete
  • 2,138
  • 4
  • 31
  • 42
  • thanx but I dont know what should I write instead of "Application Name" for SSMS, can you help me ? – Shima.Y Jan 16 '16 at 06:36
  • to chk name start sql server then open task manager after goto its process and then u can able to see its name SSMS is Correct – Tanmay Nehete Jan 18 '16 at 05:26
  • for some reason after the debugger hits the foreach loop i get stuck and nothing happens,it turns out this has huge performance issues,at least for me on a mega machine for the operation (good CPU and tons of ram), Though maybe I'm doing something wrong... – Niklas Aug 24 '16 at 04:21