• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 405
  • Last Modified:

How to unload/reload a driver from Win32

Hello,
Any pointers as how to unload or reload a device driver from a Win32 application.  TIA.
0
chu_bun
Asked:
chu_bun
1 Solution
 
mosquitoothCommented:
OK. This loads a driver:

SC_HANDLE hService = OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);

SC_HANDLE hService2 = OpenService(hService,"YourDriver",SERVICE_ALL_ACCESS);

SERVICE_STATUS servstat;
QueryServiceStatus(hService2,&servstat);
 
if(servstat.dwCurrentState == SERVICE_STOPPED)
{
  StartService(hService2,0,NULL);
}

Unloading is quite simple, only change to checking if dwCurrentState != SERVICE_STOPPED. Then call:

ControlService(hService2,SERVICE_CONTROL_STOP,&servstat);

Hope this helps
mosquitooth
0
 
chu_bunAuthor Commented:
I never thought it was that simple.  Thanks!
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now