BOOL DOKANAPI DokanServiceDelete(LPCWSTR ServiceName) { if (DokanServiceCheck(ServiceName)) { DokanServiceControl(ServiceName, DOKAN_SERVICE_STOP); if (DokanServiceControl(ServiceName, DOKAN_SERVICE_DELETE)) { return TRUE; } else { return FALSE; } } return TRUE; }
BOOL DOKANAPI DokanServiceInstall(LPCWSTR ServiceName, DWORD ServiceType, LPCWSTR ServiceFullPath) { SC_HANDLE controlHandle; SC_HANDLE serviceHandle; controlHandle = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE); if (controlHandle == NULL) { DokanDbgPrint("DokanServiceInstall: Failed to open Service Control " "Manager. error = %d\n", GetLastError()); return FALSE; } serviceHandle = CreateService(controlHandle, ServiceName, ServiceName, 0, ServiceType, SERVICE_AUTO_START, SERVICE_ERROR_IGNORE, ServiceFullPath, NULL, NULL, NULL, NULL, NULL); if (serviceHandle == NULL) { BOOL error = GetLastError(); if (error == ERROR_SERVICE_EXISTS) { DokanDbgPrintW( L"DokanServiceInstall: Service (%s) is already installed\n", ServiceName); } else { DokanDbgPrintW( L"DokanServiceInstall: Failed to install service (%s). error = %d\n", ServiceName, error); } CloseServiceHandle(controlHandle); return FALSE; } CloseServiceHandle(serviceHandle); CloseServiceHandle(controlHandle); DokanDbgPrintW(L"DokanServiceInstall: Service (%s) installed\n", ServiceName); if (DokanServiceControl(ServiceName, DOKAN_SERVICE_START)) { DokanDbgPrintW(L"DokanServiceInstall: Service (%s) started\n", ServiceName); return TRUE; } else { DokanDbgPrintW(L"DokanServiceInstall: Service (%s) start failed\n", ServiceName); return FALSE; } }
BOOL DOKANAPI DokanServiceInstall( LPCWSTR ServiceName, DWORD ServiceType, LPCWSTR ServiceFullPath) { SC_HANDLE controlHandle; SC_HANDLE serviceHandle; controlHandle = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE); if (controlHandle == NULL) { DokanDbgPrint("failed to open SCM"); return FALSE; } serviceHandle = CreateService(controlHandle, ServiceName, ServiceName, 0, ServiceType, SERVICE_AUTO_START, SERVICE_ERROR_IGNORE, ServiceFullPath, NULL, NULL, NULL, NULL, NULL); if (serviceHandle == NULL) { if (GetLastError() == ERROR_SERVICE_EXISTS) DokanDbgPrint("Service is already installed\n"); else DokanDbgPrint("failted to install service: %d\n", GetLastError()); CloseServiceHandle(controlHandle); return FALSE; } CloseServiceHandle(serviceHandle); CloseServiceHandle(controlHandle); DokanDbgPrint("Service isntalled\n"); if (DokanServiceControl(ServiceName, DOKAN_SERVICE_START)) { DokanDbgPrint("Service started\n"); return TRUE; } else { DokanDbgPrint("Service start failed\n"); return FALSE; } }