这是我在installshield中检测sqlserver是否安装的脚本,主要的判据是MSSQLSERVER服务是否安装win9x可能不适用 :(
//声明api函数
prototype HWND ADVAPI32.OpenSCManagerA(LPSTR,LPSTR,INT);
prototype HWND ADVAPI32.OpenServiceA(HWND,STRING,INT);
prototype HWND ADVAPI32.QueryServiceStatus(HWND,pointer);
prototype HWND ADVAPI32.StartServiceA (HWND,INT,pointer);
prototype BOOL ADVAPI32.ControlService(HWND,INT,pointer);
prototype BOOL ADVAPI32.CloseServiceHandle(HWND);
function INT ScanMssql() //检测sqlserver,以后考虑加上版本判断
HWND SC_MH,SC_SH;
SERVICE_STATUS S_Status;
begin
SC_MH=OpenSCManagerA(NULL,NULL,983103);
if SC_MH=0 then
return 4;
// 4: 安装异常,不能初始化service mananger
endif;
SC_SH=OpenServiceA(SC_MH,"MSSQLSERVER",983551);
if SC_SH=0 then
return 0;
//0: 没有安装sqlserver
else
QueryServiceStatus(SC_SH,&S_Status);
if S_Status.dwCurrentState=1 then
//MessageBox("MSSQLSERVER IS STOP",0);
if StartServiceA(SC_SH,0,NULL)=0 then
return 3;
//启动服务不正常
else
return 2;
//正常启动
endif;
else
return 1;
endif;
endif;
CloseServiceHandle(SC_SH);
CloseServiceHandle(SC_MH);
end;