在安装MSSQLSERVER之前,我想知道系统中是否已经安装了MSSQLSERVER。这应该在 C++ 或 mfc 中以编程方式完成。
如果 Windows 中已经安装了 MSSQLServer,那么是否有任何可能的方法来获取该服务器的 MSSql 凭据?
如果是,请解释实现这一点的方法?
更新
我尝试在我的系统中安装 sqlserver 2005 和 sql server 2008,但两个服务器都已安装。我检查了注册表路径,但它包含 SOFTWARE\Microsoft\Microsoft SQL Server\90
for MSSQLServer 2005
和 SOFTWARE\Microsoft\Microsoft SQL Server\100
对于 MSSqlServer 2008
。在安装我的 MSSQLServer 之前 我如何检查是否安装了任何 MSSql Server 版本?
编辑
直到现在,我都在 C++ 中以编程方式静默安装了 SQLSERVER。
我发布了下面的代码:
SHELLEXECUTEINFO ShExecInfo;
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = NULL;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = L"D:\\Softies\\SQLEXPR.EXE";
ShExecInfo.lpParameters = L"/qn addlocal=all InstanceName=SQLEXPRESS DisableNetworkProtocols=0 SECURITYMODE=SQL SAPWD=root SQLAUTOSTART=1 SQLBROWSERAUTOSTART=1 ENABLERANU=0";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_MAXIMIZE;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
int nResult=0;
nResult = (int )ShExecInfo.hInstApp;
if( nResult >32)
cout<<"EXE executed successfully"<<endl;
else
cout<<"Reason for failure is" <<nResult<<endl;
return 0;
最佳答案
- 您无法获取服务器的凭据,暴力破解除外
但是
如果您是本地管理员 - 您可以使用启动键 -f 从命令行启动 sql server 并尝试使用它 - 不能保证,但您可以尝试。
我有一个代码可以检查 sql server 实例的一些默认值,因此它可以很容易地适应您的需要和 c++/
private void GetSqlDefaultInfo(string ServerName, string InstanceName) { InstanceName = string.IsNullOrEmpty(InstanceName) ? "MSSQLSERVER" : InstanceName; if (string.IsNullOrEmpty(ServerName)) ServerName = Environment.MachineName; using (var registryKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, ServerName)) { object sqlInstance; using (var subKey = registryKey.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL")) sqlInstance = subKey.GetValue(InstanceName); if (sqlInstance != null && !string.IsNullOrEmpty(sqlInstance.ToString())) { var sqlPathKey = string.Format(@"SOFTWARE\Microsoft\Microsoft SQL Server\{0}\MSSQLServer", sqlInstance); object defaultData, defaultLog, backupDirectory, sqlPath; using (var subKey = registryKey.OpenSubKey(sqlPathKey)) { defaultData = subKey.GetValue("DefaultData"); defaultLog = subKey.GetValue("DefaultLog"); backupDirectory = subKey.GetValue("BackupDirectory"); } sqlPathKey = string.Format(@"SOFTWARE\Microsoft\Microsoft SQL Server\{0}\Setup", sqlInstance); using (var subKey = registryKey.OpenSubKey(sqlPathKey)) sqlPath = subKey.GetValue("SQLDataRoot"); DataFilePath = defaultData != null ? defaultData.ToString() : Path.Combine(sqlPath.ToString(), "Data").TrimEnd('\\'); LogFilePath = defaultLog != null ? defaultLog.ToString() : Path.Combine(sqlPath.ToString(), "Data").TrimEnd('\\'); FTSIndexFilePath = DataFilePath; ContentFilePath = DataFilePath; BackupFilePath = backupDirectory != null ? backupDirectory.ToString() : Path.Combine(sqlPath.ToString(), "Backup").TrimEnd('\\'); } } }
关于c++ - 如何知道Windows XP 或7 中是否安装了MSSql Server?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8697261/