简体   繁体   English

如何知道Windows XP或7中是否已安装MSSql Server?

[英]How to know MSSql Server is installed or not in windows XP or 7?

Before going to install MSSQLSERVER, I want to know whether MSSQLSERVER is already installed in the system or not. 在安装MSSQLSERVER之前,我想知道系统中是否已经安装了MSSQLSERVER。 This should be done programatically in C++ or mfc. 这应该在C ++或mfc中以编程方式完成。

If the MSSQLServer is already installed in the windows then Is there any possible way to get the MSSql Credentials of that server? 如果Windows中已经安装了MSSQLServer,那么是否有任何可能的方法来获取该服务器的MSSql凭据?

If So, Please Explain the way to achieve this? 如果是,请说明实现此目的的方法?

UPDATE 更新

I tried to install sqlserver 2005 and sql server 2008 in my system but both the servers are installed. 我尝试在系统中安装sqlserver 2005和sql server 2008,但是两个服务器均已安装。 I checked the registry path but It contains SOFTWARE\\Microsoft\\Microsoft SQL Server\\90 for MSSQLServer 2005 and SOFTWARE\\Microsoft\\Microsoft SQL Server\\100 for MSSqlServer 2008 .Before installing my MSSQLServer How can I check whether any of the MSSql Server version is installed or not? 我检查了注册表路径,但它包含用于MSSQLServer 2005 SOFTWARE\\Microsoft\\Microsoft SQL Server\\90和用于MSSqlServer 2008 SOFTWARE\\Microsoft\\Microsoft SQL Server\\100在安装我的MSSQLServer之前,如何检查是否有任何MSSql Server版本是是否安装?

EDIT 编辑

Till Now I silent installed the SQLSERVER programmatically in c++. 直到现在,我以编程方式在c ++中静默安装了SQLSERVER。

I Posted the code below: 我在下面发布了代码:

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;
  • You cannot get the server's credentials, except of brute force 除了蛮力外,您无法获取服务器的凭据

BUT

If you're a local administrator - you can start sql server from the command line with startup key -f and try to play with it - it is not guaranteed, but you can try. 如果您是本地管理员,则可以使用启动键-f从命令行启动sql server并尝试使用它-不能保证,但是您可以尝试。

  • I have a code which checks the some defaults for sql server instance, so it can be easily adopted to your needs and c++/ 我有一个代码可以检查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('\\\\'); } } } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM