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
> >
> >
>
>