我正在寻找一种在WiX中确定是否安装了SQLLocalDB的方法。我怎样才能做到这一点? - 我可以查看注册表项吗? - 什么时候,哪个键?
答案 0 :(得分: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>
那会得到你的版本。
答案 1 :(得分:1)
从注册表中检查可能无法一直工作,因为如果用户卸载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;
}