2013-03-18 92 views
2

我正在尋找一種方法來確定在WiX中是否安裝了SQLLocalDB。我怎樣才能做到這一點? - 我可以檢查註冊表項嗎? - 當是,哪個鍵?確定是否安裝了SqlLocalDB

+0

http://msdn.microsoft.com/en-us/library/hh215237.aspx – ErikEJ 2013-03-18 21:06:22

+0

就個人而言,我更喜歡測試與數據庫實例的連接,而不是將自己連接到特定的實例/版本。 – 2013-03-18 21:41:19

+0

@christopher畫家 - 我如何在WiX上做這個決定是否安裝LocalDB? – BennoDual 2013-03-18 22:33:00

回答

4

一個RegistrySearch應該這樣做:

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

這將讓你的版本。

+0

根據MSDN,AppSearch屬性必須是公共屬性。 http://msdn.microsoft.com/en-us/library/windows/desktop/aa367579%28v=vs.85%29.aspx和ICE52警告。 – 2013-03-18 21:39:10

+0

是的,在捆綁中的時間太多了。 :)修正。 – 2013-03-19 14:12:34

0

從註冊表中檢查可能無法一直工作,因爲如果用戶卸載localDb,則註冊表項可能仍然存在。

這裏是我使用來識別命令行中的LocalDB安裝的功能 -

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; 
    }