www.pudn.com > WinIoForVB.rar > InstDrv.cpp


// ---------------------------------------------------- // 
//                      WinIo v2.0                      // 
//  Direct Hardware Access Under Windows 9x/NT/2000/XP  // 
//           Copyright 1998-2002 Yariv Kaplan           // 
//               http://www.internals.com               // 
// ---------------------------------------------------- // 
 
#include  
#include "winio.h" 
 
bool _stdcall InstallWinIoDriver(PSTR pszWinIoDriverPath, bool IsDemandLoaded) 
{ 
  SC_HANDLE hSCManager; 
  SC_HANDLE hService; 
 
  // Remove any previous instance of the driver 
 
  RemoveWinIoDriver(); 
 
  hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); 
 
  if (hSCManager) 
  { 
    // Install the driver 
     
    hService = CreateService(hSCManager, 
                             "WINIO", 
                             "WINIO", 
                             SERVICE_ALL_ACCESS, 
                             SERVICE_KERNEL_DRIVER, 
                             (IsDemandLoaded == true) ? SERVICE_DEMAND_START : SERVICE_SYSTEM_START, 
                             SERVICE_ERROR_NORMAL, 
                             pszWinIoDriverPath, 
                             NULL, 
                             NULL, 
                             NULL, 
                             NULL, 
                             NULL); 
 
    CloseServiceHandle(hSCManager); 
 
    if (hService == NULL) 
      return false; 
  } 
  else 
    return false; 
 
  CloseServiceHandle(hService); 
   
  return true; 
} 
 
 
bool _stdcall RemoveWinIoDriver() 
{ 
  SC_HANDLE hSCManager; 
  SC_HANDLE hService; 
  bool bResult; 
 
  StopWinIoDriver(); 
 
  hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); 
 
  if (hSCManager) 
  { 
    hService = OpenService(hSCManager, "WINIO", SERVICE_ALL_ACCESS); 
 
    CloseServiceHandle(hSCManager); 
 
    if (hService) 
    { 
      bResult = DeleteService(hService); 
       
      CloseServiceHandle(hService); 
    } 
    else 
      return false; 
  } 
  else 
    return false; 
 
  return bResult; 
} 
 
 
bool _stdcall StartWinIoDriver() 
{ 
  SC_HANDLE hSCManager; 
  SC_HANDLE hService; 
  bool bResult; 
 
  hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); 
 
  if (hSCManager) 
  { 
    hService = OpenService(hSCManager, "WINIO", SERVICE_ALL_ACCESS); 
 
    CloseServiceHandle(hSCManager); 
 
    if (hService) 
    { 
      bResult = StartService(hService, 0, NULL) || GetLastError() == ERROR_SERVICE_ALREADY_RUNNING; 
 
      CloseServiceHandle(hService); 
    } 
    else 
      return false; 
  } 
  else 
    return false; 
 
  return bResult; 
} 
 
 
bool _stdcall StopWinIoDriver() 
{ 
  SC_HANDLE hSCManager; 
  SC_HANDLE hService; 
  SERVICE_STATUS ServiceStatus; 
  bool bResult; 
 
  hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); 
 
  if (hSCManager) 
  { 
    hService = OpenService(hSCManager, "WINIO", SERVICE_ALL_ACCESS); 
 
    CloseServiceHandle(hSCManager); 
 
    if (hService) 
    { 
      bResult = ControlService(hService, SERVICE_CONTROL_STOP, &ServiceStatus); 
 
      CloseServiceHandle(hService); 
    } 
    else 
      return false; 
  } 
  else 
    return false; 
 
  return bResult; 
}