I have VBScript custom actions to control the installation of my COM+/MTS components. These obviously fail if the service itself is not installed on the target machine.
What is the best way to determine that the MTS or COM+ service is running?
Many Thanks,
Martin Overton
This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
MTS/COM plus services installed?
Started by
moverton
, Apr 11 2002 10:54
1 reply to this topic
Posted 03 May 2002 - 09:45
function CheckForMSDTC(hMSI)
NUMBER nResult;
begin
nResult = _IsServiceAvailable("MSDTC");
if (nResult = 0) then
MsiSetProperty(hMSI, "MSDTC", "TRUE");
else
MsiSetProperty(hMSI, "MSDTC", "FALSE");
endif;
end;
function CheckForWWW(hMSI)
NUMBER nResult;
begin
nResult = _IsServiceAvailable("W3SVC");
if (nResult = 0) then
MsiSetProperty(hMSI, "WWW", "TRUE");
else
MsiSetProperty(hMSI, "WWW", "FALSE");
endif;
end;
function _InitServiceConnections(szServiceName)
NUMBER nReturn, nResult;
begin
// Initialize global variables
schService = NULL;
schSCManager = NULL;
ptrMcName = NULL; // use local machine
ptrDBName = NULL; // open services active database
// Locals
nReturn = 0;
nResult = 0;
// Load ADVAPI32.DLL, which is necessary for Service Manager-
// related functions.
if (UseDLL("AdvAPI32.dll") < 0) then
#ifdef _NTS_DEBUG
MessageBox ("Couldn't load AdvAPI32.dll.", SEVERE);
#endif
nReturn = -1;
endif;
// First establish the connection with the Service Manager
if (nReturn = 0) then
schSCManager = OpenSCManagerA(ptrMcName, ptrDBName, SC_MANAGER_ALL_ACCESS);
if (schSCManager = NULL) then
nResult = GetLastError();
#ifdef _NTS_DEBUG
SprintfBox(INFORMATION, "OpenSCManagerA Error",
"Error connecting to Service Manager.\n\n" +
"Error number = %ld.", nResult);
#endif
nReturn = -1;
endif;
endif;
if (szServiceName != "") then
pszSStartName = AddressString(szServiceName); //FIX IS3
if (nReturn = 0) then
// Now open the service.
schService = OpenServiceA(schSCManager, pszSStartName, SERVICE_ALL_ACCESS); //FIX IS3
if (schService = NULL) then
nResult = GetLastError();
#ifdef _NTS_DEBUG
SprintfBox(INFORMATION, "OpenService Error",
"Error opening service.\n\n"+
"Error number = %ld.", nResult);
#endif
nReturn = -1;
endif;
endif;
endif;
return nReturn;
end;
/////////////////////////////////////////////////////////////
// FUNCTION: _CloseServiceConnections()
//
// DESCRIPTION: Closes connections to services and manager
//
// OUTPUT: 0 If function is successful in connecting
// -1 If function fails to connect
/////////////////////////////////////////////////////////////
function _CloseServiceConnections()
NUMBER nResult;
begin
// Close connection to Service Manager
if (schSCManager != NULL) then
nResult = CloseServiceHandle(schSCManager);
endif;
// Close handle of the service installed
if (schService != NULL) then
nResult = CloseServiceHandle(schService);
endif;
// Deinitialize global variables, just in case
schService = NULL;
schSCManager = NULL;
ptrMcName = NULL; // use local machine
ptrDBName = NULL; // open services active database
UnUseDLL("AdvAPI32.dll");
return nResult;
end;
/////////////////////////////////////////////////////////////
// FUNCTION: _IsServiceAvailable(szServiceName)
//
// DESCRIPTION: Checks to see if a service is installed
//
// INPUT: szServiceName = service name to check for
//
// OUTPUT: 0 If service is available
// -1 If service is unavailable
/////////////////////////////////////////////////////////////
function _IsServiceAvailable(szServiceName)
NUMBER nvResult;
begin
nvResult = _InitServiceConnections(szServiceName);
_CloseServiceConnections();
return nvResult;
end;
#endif // _NTSERVICE_RUL_
prototype NUMBER AdvAPI32.OpenSCManagerA(POINTER, POINTER, NUMBER);
prototype NUMBER Advapi32.OpenServiceA(NUMBER, POINTER, NUMBER);
NUMBER nResult;
begin
nResult = _IsServiceAvailable("MSDTC");
if (nResult = 0) then
MsiSetProperty(hMSI, "MSDTC", "TRUE");
else
MsiSetProperty(hMSI, "MSDTC", "FALSE");
endif;
end;
function CheckForWWW(hMSI)
NUMBER nResult;
begin
nResult = _IsServiceAvailable("W3SVC");
if (nResult = 0) then
MsiSetProperty(hMSI, "WWW", "TRUE");
else
MsiSetProperty(hMSI, "WWW", "FALSE");
endif;
end;
function _InitServiceConnections(szServiceName)
NUMBER nReturn, nResult;
begin
// Initialize global variables
schService = NULL;
schSCManager = NULL;
ptrMcName = NULL; // use local machine
ptrDBName = NULL; // open services active database
// Locals
nReturn = 0;
nResult = 0;
// Load ADVAPI32.DLL, which is necessary for Service Manager-
// related functions.
if (UseDLL("AdvAPI32.dll") < 0) then
#ifdef _NTS_DEBUG
MessageBox ("Couldn't load AdvAPI32.dll.", SEVERE);
#endif
nReturn = -1;
endif;
// First establish the connection with the Service Manager
if (nReturn = 0) then
schSCManager = OpenSCManagerA(ptrMcName, ptrDBName, SC_MANAGER_ALL_ACCESS);
if (schSCManager = NULL) then
nResult = GetLastError();
#ifdef _NTS_DEBUG
SprintfBox(INFORMATION, "OpenSCManagerA Error",
"Error connecting to Service Manager.\n\n" +
"Error number = %ld.", nResult);
#endif
nReturn = -1;
endif;
endif;
if (szServiceName != "") then
pszSStartName = AddressString(szServiceName); //FIX IS3
if (nReturn = 0) then
// Now open the service.
schService = OpenServiceA(schSCManager, pszSStartName, SERVICE_ALL_ACCESS); //FIX IS3
if (schService = NULL) then
nResult = GetLastError();
#ifdef _NTS_DEBUG
SprintfBox(INFORMATION, "OpenService Error",
"Error opening service.\n\n"+
"Error number = %ld.", nResult);
#endif
nReturn = -1;
endif;
endif;
endif;
return nReturn;
end;
/////////////////////////////////////////////////////////////
// FUNCTION: _CloseServiceConnections()
//
// DESCRIPTION: Closes connections to services and manager
//
// OUTPUT: 0 If function is successful in connecting
// -1 If function fails to connect
/////////////////////////////////////////////////////////////
function _CloseServiceConnections()
NUMBER nResult;
begin
// Close connection to Service Manager
if (schSCManager != NULL) then
nResult = CloseServiceHandle(schSCManager);
endif;
// Close handle of the service installed
if (schService != NULL) then
nResult = CloseServiceHandle(schService);
endif;
// Deinitialize global variables, just in case
schService = NULL;
schSCManager = NULL;
ptrMcName = NULL; // use local machine
ptrDBName = NULL; // open services active database
UnUseDLL("AdvAPI32.dll");
return nResult;
end;
/////////////////////////////////////////////////////////////
// FUNCTION: _IsServiceAvailable(szServiceName)
//
// DESCRIPTION: Checks to see if a service is installed
//
// INPUT: szServiceName = service name to check for
//
// OUTPUT: 0 If service is available
// -1 If service is unavailable
/////////////////////////////////////////////////////////////
function _IsServiceAvailable(szServiceName)
NUMBER nvResult;
begin
nvResult = _InitServiceConnections(szServiceName);
_CloseServiceConnections();
return nvResult;
end;
#endif // _NTSERVICE_RUL_
prototype NUMBER AdvAPI32.OpenSCManagerA(POINTER, POINTER, NUMBER);
prototype NUMBER Advapi32.OpenServiceA(NUMBER, POINTER, NUMBER);
Gunavelu