實現原理:判斷是否存在,是通過尋找註冊表是否含有相應標識來判斷的。
注意:XP與WIN7系統註冊表儲存方式不一樣,32位與64位作業系統註冊表儲存方式也不一樣,需要分別判斷。在此只判斷32位作業系統的情況。
源碼:
////檢查是否有安裝Oracle
function NUMBER CheckOracleISExist()
STRING svOraclePath,nvValue;
NUMBER nKeyType,nvType, nvSize;
begin
// defaut regedit root
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
//oralce regedit path
if(RegDBGetKeyValueEx("SOFTWARE\\ORACLE\\ALL_HOMES","DEFAULT_HOME",nvType,nvValue,nvSize) = 0) then
return 0;
endif;
return -1;
end;
// SQL Server 2000, SQL Server 2005, SQL Server 2008,
// SQL Server 2005 Express,SQL Server 2008 Express
//檢查是否有安裝SQL Server
function NUMBER CheckSQLServer()
STRING nvValue;
NUMBER nvType, nvSize;
begin
//return -1;
// defaut regedit root
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
// SQL Server 2000
if(RegDBGetKeyValueEx("SOFTWARE\\Microsoft\\Microsoft SQL Server","InstalledInstances",nvType,nvValue,nvSize) = 0) then
return 0;
endif;
//SQL Server 2005 Version
if(RegDBGetKeyValueEx("SOFTWARE\\Microsoft\\Microsoft SQL Server 2005 Redist\\BOL\\2052\\CurrentVersion","Version",nvType,nvValue,nvSize) = 0) then
return 0;
endif;
//SQL Server 2008 Express
//if(RegDBGetKeyValueEx("SOFTWARE\\Microsoft\\Microsoft SQL Server 2008 Redist\\SQLNCLI10\\2052\\CurrentVersion","Version",nvType,nvValue,nvSize) = 0) then
// return 0;
//endif;
// Express
if(RegDBGetKeyValueEx("SOFTWARE\\Microsoft\\Microsoft SQL Server\SQLEXPRESS\setup","SQLPath",nvType,nvValue,nvSize) = 0) then
return 0;
endif;
return -1;
end;