Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Monitoring a service
Message
De
20/08/2003 15:39:25
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00820682
Message ID:
00821969
Vues:
16
Thank you.



>>Hi all,
>>
>>How do I to monitoring a service (SQL Server).
>>I need to know every second if the service is running or not for take the action.
>>
>>
>>Thank's a lot.
>
>Mauricio,
>
>Below you'll find a sample code for checking SQL Server service status (or any other Windows Service). It'doesn't include any error checking. For more details see MSDN at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/service_functions.asp?frame=true
>
* Service Control Manager object specific access types
>#define SC_MANAGER_CONNECT             0x0001
>#define SC_MANAGER_CREATE_SERVICE      0x0002
>#define SC_MANAGER_ENUMERATE_SERVICE   0x0004
>#define SC_MANAGER_LOCK                0x0008
>#define SC_MANAGER_QUERY_LOCK_STATUS   0x0010
>#define SC_MANAGER_MODIFY_BOOT_CONFIG  0x0020
>
>* Service object specific access type
>#define SERVICE_QUERY_CONFIG           0x0001
>#define SERVICE_CHANGE_CONFIG          0x0002
>#define SERVICE_QUERY_STATUS           0x0004
>#define SERVICE_ENUMERATE_DEPENDENTS   0x0008
>#define SERVICE_START                  0x0010
>#define SERVICE_STOP                   0x0020
>#define SERVICE_PAUSE_CONTINUE         0x0040
>#define SERVICE_INTERROGATE            0x0080
>#define SERVICE_USER_DEFINED_CONTROL   0x0100
>
>* Service State -- for CurrentState
>#define SERVICE_STOPPED                0x00000001
>#define SERVICE_START_PENDING          0x00000002
>#define SERVICE_STOP_PENDING           0x00000003
>#define SERVICE_RUNNING                0x00000004
>#define SERVICE_CONTINUE_PENDING       0x00000005
>#define SERVICE_PAUSE_PENDING          0x00000006
>#define SERVICE_PAUSED                 0x00000007
>
>DECLARE Long OpenSCManager IN Advapi32 ;
>	  STRING lpMachineName, STRING lpDatabaseName, Long dwDesiredAccess
>DECLARE Long OpenService IN Advapi32 ;
>	  Long hSCManager, String lpServiceName, Long dwDesiredAccess
>DECLARE Long QueryServiceStatus IN Advapi32 ;
>	  Long hService, String @ lpServiceStatus
>DECLARE Long CloseServiceHandle  IN Advapi32 ;
>	  Long hSCObject
>
>lhSCManager = OpenSCManager(0, 0, SC_MANAGER_CONNECT + SC_MANAGER_ENUMERATE_SERVICE)
>IF lhSCManager = 0
>	* Error
>ENDIF
>lcServiceName = "MSSQLSERVER"
>lhSChandle = OpenService(lhSCManager, lcServiceName, SERVICE_QUERY_STATUS)
>IF lhSCManager = 0
>	* Error
>ENDIF
>lcQueryBuffer = REPLICATE(CHR(0), 4*7 )
>lnRetVal = QueryServiceStatus(lhSChandle, @lcQueryBuffer )
>IF lnRetVal = 0
>	* Error
>ENDIF
>* Close Handles
>CloseServiceHandle(lhSChandle)
>CloseServiceHandle(lhSCManager)
>lnServiceStatus = ASC(SUBSTR(lcQueryBuffer,5,1))
>IF lnServiceStatus <> SERVICE_RUNNING
>	* Service isn't running
>	? "Service isn't running"
>ENDIF	
>
Mauricio Mesa
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform