Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Code to tell if service is running
Message
De
12/06/2007 13:34:52
Jay Johengen
Altamahaw-Ossipee, Caroline du Nord, États-Unis
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Titre:
Code to tell if service is running
Divers
Thread ID:
01232347
Message ID:
01232347
Vues:
59
I don't know if this is considered API, but it seemed like the best place...

Got this code from somewhere and I'm wondering why it never finds a Service. I've changed this line to a number of different running programs, but it never see that they are running:
lcServiceName = "NetWaiting"
I'm sure it's just my lack of understanding in how it supposed to work. Thanks!
CLOSE ALL
CLEAR ALL

* 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 = "NetWaiting"
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	
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform