Determine if SqlLocalDB is installed

守給你的承諾、 提交于 2020-01-04 04:11:22

问题


I am searching for a way to determine in WiX if SQLLocalDB is installed or not. How can I do this? - Can I check a registry-key? - When yes, which key?


回答1:


A RegistrySearch should do it:

<Property Id="LOCALDB">
   <RegistrySearch Id="SearchForLocalDB" Root="HKLM" 
                   Key="SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL11E.LOCALDB\MSSQLServer\CurrentVersion"
                   Name="CurrentVersion"
                   Type="raw" />
</Property>

That would get you the version.




回答2:


Checking from the registry may not work all the time becasue if user uninstall the localDb then registry entries may still exist.

Here is the function I am using to identify the localDB installation from command line -

    internal static bool IsLocalDBInstalled()
    {
        // Start the child process.
        Process p = new Process();
        // Redirect the output stream of the child process.
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardOutput = true;
        p.StartInfo.FileName = "cmd.exe";
        p.StartInfo.Arguments = "/C sqllocaldb info";
        p.StartInfo.CreateNoWindow = true;
        p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
        p.Start();
        // Do not wait for the child process to exit before
        // reading to the end of its redirected stream.
        // p.WaitForExit();
        // Read the output stream first and then wait.
        string sOutput = p.StandardOutput.ReadToEnd();
        p.WaitForExit();

        //If LocalDb is not installed then it will return that 'sqllocaldb' is not recognized as an internal or external command operable program or batch file.
        if (sOutput == null || sOutput.Trim().Length == 0 || sOutput.Contains("not recognized"))
            return false;
        if (sOutput.ToLower().Contains("mssqllocaldb")) //This is a defualt instance in local DB
            return true;
        return false;
    }


来源:https://stackoverflow.com/questions/15486554/determine-if-sqllocaldb-is-installed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!