0

How to get the Sqlserver Installation Path Programatically.

If we go for the Registry Then Registry Hives May be Different from one OS to other OS

Like w2k3 to w3k8 and VISTA and W2k8 R2 like that..

But i did Using Registry as follows But I gave Some Hard Code Key vAlues If Hives are same then no problem if Different The Problem rises....

    CRegKey cregkey;
DWORD result;
const char subkey[]="SOFTWARE\\Microsoft\\Microsoft SQL Server\\100";
const char keyval[] = "VerSpecificRootDir";
char path[ 2048 ];
result = cregkey.Open(HKEY_LOCAL_MACHINE,subkey);
    if (ERROR_SUCCESS == result)
    {
        DWORD dwCount = sizeof( path );
        result = cregkey.QueryStringValue(keyval, path, &dwCount);
          if (ERROR_SUCCESS == result) 
           {              
                cout<<" The SQLSERVER Pathis "<<path<<endl;

           }
   }                

1 Answer 1

1

I suppose that hive for Instance independent settings (i.e. shared tools that do not depend on how many instances of SQL Server you run) should be HKEY_LOCAL_MACHINE\SOFTWARE\Microsft\Microsoft SQL Server(version number). If you cannot find tools for HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\100 version (which match SQL Server 2008), perhaps you can check 90 version (SQL 2005) HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\90 ?

Have you ever seen that on some version of Windows this hive is different?


Here is also an article that explain how to get Instance-aware registry keys MSDN: File Locations for Default and Named Instances of SQL Server In our installation script we use values from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.1\Setup, for example. where MSSQL.1 is an instance name, and instance names can be found in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names

Also I saw several articles that recommend reading from HKEY_LOCAL_MACHINE\Software\Microsoft\MSSQLServer\Setup I will not work on Windows XP, but it works on Win 2003 Srv See sql-server-how-to-select-the-installation-path

So you have no way probably but to implement more complex logic - first check HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Setup if not exists, check HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.1\Setup... But this is what you will need for instance-aware folders, like Binn, Data, Backup...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.