PC Review


Reply
Thread Tools Rate Thread

Re: SQL Server or MSDE Check before installtion

 
 
Jeff Henkels
Guest
Posts: n/a
 
      17th May 2004
Sorry it's taken so long, but here's the code for a C++ based custom action
to detect SQL:

UINT __stdcall DetectSQLInstall(MSIHANDLE hInstall)
{
// Detect local machine installs of SQL Server or MSDE, using either the
SQL7 or 2K engines.
// Set SQLVERSION MSI property appropriately
HKEY hk, hkInst, hkVer;
TCHAR szText[512];
LPTSTR lpInst, lpInstances;
DWORD dwSize = 0, dwType;

// Look for SQL2K engine first
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,
_T("Software\\Microsoft\\Microsoft SQL Server"), KEY_READ, &hk))
{
// At least one instance of the SQL2K engine has been installed.
Check through all installed instances
// (there can be up to 16) for one that has a valid version registry
entry.

dwSize = 0;
dwType = REG_MULTI_SZ;
if (ERROR_SUCCESS == RegQueryValueEx(hk, _T("InstalledInstances"),
NULL, &dwType, NULL, &dwSize))
{
lpInstances = new TCHAR[dwSize + 2];
if (ERROR_SUCCESS == RegQueryValueEx(hk,
_T("InstalledInstances"), NULL, &dwType, (LPBYTE)lpInstances, &dwSize))
{
lpInst = lpInstances;
while (lpInst && _tcslen(lpInst))
{
// Open the registry subkey for the current instance
_stprintf(szText, _T("%s\\MSSQLServer"), lpInst);
if ((ERROR_SUCCESS == RegOpenKeyEx(hk, szText, KEY_READ,
&hkInst)) &&
(ERROR_SUCCESS == RegOpenKeyEx(hkInst,
_T("CurrentVersion"), KEY_READ, &hkVer)))
{
// and check its version
dwSize = sizeof(szText) / sizeof(TCHAR);
dwType = REG_SZ;
if (ERROR_SUCCESS == RegQueryValueEx(hkInst,
_T("CurrentVersion"), NULL, &dwType, szText, &dwSize))
{
// Found an install of SQL 2K engine, szText
contains its version, so copy it to
// MSI property & bail
MsiSetProperty(hInstall, _T("SQLVERSION"),
szText);
RegCloseKey(hkVer);
RegCloseKey(hkInst);
RegCloseKey(hk);
delete[] lpInstances;
return 0;
}
RegCloseKey(hkVer);
RegCloseKey(hkInst);
}
lpInst += _tcslen(lpInst) + 1;
}
}
delete[] lpInstances;
}
RegCloseKey(hk);
}

// Look for SQL7
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,
_T("Software\\Microsoft\\MSSQLServer\\MSSQLServer"), KEY_READ, &hk))
{
// Only one instance of the SQL7 engine is possible, so we just have
to get the version string from the registry.
if (ERROR_SUCCESS == RegOpenKeyEx(hk, _T("CurrentVersion"),
KEY_READ, &hkVer))
{
dwSize = sizeof(szText) / sizeof(TCHAR);
dwType = REG_SZ;
if (ERROR_SUCCESS == RegQueryValueEx(hkVer,
_T("CurrentVersion"), NULL, &dwType, (LPBYTE)szText, &dwSize))
{
// Got the version info, so set property & leave
MsiSetProperty(hInstall, _T("SQLVERSION"), szText);
RegCloseKey(hkVer);
RegCloseKey(hk);
return 0;
}
RegCloseKey(hkVer);
}
RegCloseKey(hk);
}
// No SQL install found, clear SQLVERSION property
MsiSetProperty(hInstall, _T("SQLVERSION"), NULL);
return 0;
}

"Jeff Henkels" <(E-Mail Removed)> wrote in message news:...
> It's not quite as simple as checking for IE/IIS; there are some registry
> entries you need to read, and an API call or two. It's fairly easy to do

as
> a custom action -- I've done it in the past. Unfortunately, I don't have
> the code handy at the moment (it's on a home PC and I'm at the office);

I'll
> try to dig it up later this evening.
>
> "Piyush" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi All,
> > Is it possible to find out whether SQL server/MSDE are installed on a
> > machine using some properties (like we can do it for IE or IIS) ?
> >
> > Thanks,
> > Piyush
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stored Procedure in SQL Server vs MSDE 2005 SQL Server =?Utf-8?B?ZGJndXJ1MzE2?= Microsoft Access External Data 2 29th Jun 2007 07:41 PM
Check user's password of MSDE ad Microsoft C# .NET 4 13th Feb 2005 12:46 AM
SQL Server CE and MSDE? dmeckley Microsoft Dot NET Compact Framework 1 25th May 2004 06:40 PM
SQL Server or MSDE Check before installtion Piyush Microsoft Windows 2000 MSI 2 11th May 2004 08:04 AM
Re-creating an SQL server database to another MSDE server NWx Microsoft ASP .NET 3 4th Mar 2004 05:44 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:59 PM.