2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
23 Change History (most recent first):
26 Revision 1.3 2005/07/07 19:18:29 shersche
27 Fix error in previous checkin, change SystemServiceIsDisabled() to IsSystemServiceDisabled()
29 Revision 1.2 2005/06/30 17:55:35 shersche
30 <rdar://problem/4096913> Implement ISSystemServiceDisabled(). This is used to determine how long we should wait to connect to the system service.
32 Revision 1.1 2004/06/18 03:55:11 rpantos
33 Move DLL up to main level; additional integration from Scott.
35 Revision 1.1 2004/02/21 04:16:50 bradley
36 DLL wrapper for DNS-SD API.
41 #include <DebugServices.h>
43 BOOL APIENTRY
DllMain( HANDLE inModule
, DWORD inReason
, LPVOID inReserved
)
50 case DLL_PROCESS_ATTACH
:
51 case DLL_THREAD_ATTACH
:
52 case DLL_THREAD_DETACH
:
53 case DLL_PROCESS_DETACH
:
61 IsSystemServiceDisabled()
63 ENUM_SERVICE_STATUS
* lpService
= NULL
;
67 DWORD bytesNeeded
= 0;
69 DWORD resumeHandle
= 0;
76 sc
= OpenSCManager( NULL
, NULL
, SC_MANAGER_ENUMERATE_SERVICE
);
77 err
= translate_errno( sc
, GetLastError(), kUnknownErr
);
78 require_noerr( err
, exit
);
80 srvType
= SERVICE_WIN32
;
81 srvState
= SERVICE_STATE_ALL
;
85 // Call EnumServicesStatus using the handle returned by OpenSCManager
87 ok
= EnumServicesStatus ( sc
, srvType
, srvState
, lpService
, dwBytes
, &bytesNeeded
, &srvCount
, &resumeHandle
);
89 if ( ok
|| ( GetLastError() != ERROR_MORE_DATA
) )
99 dwBytes
= bytesNeeded
;
101 lpService
= ( ENUM_SERVICE_STATUS
* ) malloc( dwBytes
);
102 require_action( lpService
, exit
, ret
= FALSE
);
105 err
= translate_errno( ok
, GetLastError(), kUnknownErr
);
106 require_noerr( err
, exit
);
108 for ( i
= 0; i
< srvCount
; i
++ )
110 if ( strcmp( lpService
[i
].lpServiceName
, "Bonjour Service" ) == 0 )
112 if ( ( lpService
[i
].ServiceStatus
.dwCurrentState
== SERVICE_PAUSED
) || ( lpService
[i
].ServiceStatus
.dwCurrentState
== SERVICE_STOPPED
) )
130 CloseServiceHandle ( sc
);