|
代码核心如下:
BOOL LoadDriver( IN LPCTSTR lpFileName )
{
HANDLE hDevice=0;
SC_HANDLE hSCManager = OpenSCManager( NULL, NULL,SC_MANAGER_CREATE_SERVICE );
if ( NULL != hSCManager )
{
SC_HANDLE hService = CreateService( hSCManager, SERVICE_NAME,
SERVICE_NAME, SERVICE_START,
SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START,
SERVICE_ERROR_IGNORE, lpFileName, NULL, NULL, NULL, NULL, NULL );
if ( ERROR_SERVICE_EXISTS == GetLastError() )
{
hService = OpenService( hSCManager, SERVICE_NAME, SERVICE_START );
}
if(!StartService( hService, 0, NULL ))
{
cout<<"StartService Error!\n";
return false; |
|