我正在寻找一种在 WiX 中确定是否安装了 SQLLocalDB 的方法。我怎样才能做到这一点?- 我可以检查注册表项吗?- 如果是,哪个键?
问问题
7385 次
2 回答
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>
那会给你版本。
于 2013-03-18T21:32:50.153 回答
2
从注册表检查可能不会一直有效,因为如果用户卸载 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;
}
于 2017-05-06T18:30:40.370 回答