1/* -*- Mode: C; tab-width: 4 -*- 2 * 3 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18#include <windows.h> 19#include <DebugServices.h> 20#include <stdlib.h> 21 22BOOL APIENTRY DllMain( HANDLE inModule, DWORD inReason, LPVOID inReserved ) 23{ 24 (void) inModule; 25 (void) inReserved; 26 27 switch( inReason ) 28 { 29 case DLL_PROCESS_ATTACH: 30 case DLL_THREAD_ATTACH: 31 case DLL_THREAD_DETACH: 32 case DLL_PROCESS_DETACH: 33 break; 34 } 35 return( TRUE ); 36} 37 38 39BOOL 40IsSystemServiceDisabled() 41{ 42 ENUM_SERVICE_STATUS * lpService = NULL; 43 SC_HANDLE sc; 44 BOOL ret = FALSE; 45 BOOL ok; 46 DWORD bytesNeeded = 0; 47 DWORD srvCount; 48 DWORD resumeHandle = 0; 49 DWORD srvType; 50 DWORD srvState; 51 DWORD dwBytes = 0; 52 DWORD i; 53 OSStatus err; 54 55 sc = OpenSCManager( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE ); 56 err = translate_errno( sc, GetLastError(), kUnknownErr ); 57 require_noerr( err, exit ); 58 59 srvType = SERVICE_WIN32; 60 srvState = SERVICE_STATE_ALL; 61 62 for ( ;; ) 63 { 64 // Call EnumServicesStatus using the handle returned by OpenSCManager 65 66 ok = EnumServicesStatus ( sc, srvType, srvState, lpService, dwBytes, &bytesNeeded, &srvCount, &resumeHandle ); 67 68 if ( ok || ( GetLastError() != ERROR_MORE_DATA ) ) 69 { 70 break; 71 } 72 73 if ( lpService ) 74 { 75 free( lpService ); 76 } 77 78 dwBytes = bytesNeeded; 79 80 lpService = ( ENUM_SERVICE_STATUS* ) malloc( dwBytes ); 81 require_action( lpService, exit, ret = FALSE ); 82 } 83 84 err = translate_errno( ok, GetLastError(), kUnknownErr ); 85 require_noerr( err, exit ); 86 87 for ( i = 0; i < srvCount; i++ ) 88 { 89 if ( strcmp( lpService[i].lpServiceName, "Bonjour Service" ) == 0 ) 90 { 91 if ( ( lpService[i].ServiceStatus.dwCurrentState == SERVICE_PAUSED ) || ( lpService[i].ServiceStatus.dwCurrentState == SERVICE_STOPPED ) ) 92 { 93 ret = TRUE; 94 } 95 96 break; 97 } 98 } 99 100exit: 101 102 if ( lpService ) 103 { 104 free( lpService ); 105 } 106 107 if ( sc ) 108 { 109 CloseServiceHandle ( sc ); 110 } 111 112 return ret; 113} 114