假设要自己编程来加载Windows下后缀为.sys的驱动程序;首先要使用 OpenSCManager 函数打开Windows服务控制管理器;
下面先来调用此函数看一下会不会打开成功;代码如下;
#include <windows.h>
#include <winsvc.h>
#include <conio.h>
#include <stdio.h>
#define DRIVER_NAME "HelloDriver"
#define DRIVER_PATH "..//MyDriver//HelloDriver.sys"
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
/* TODO: Place code here.*/
PVOID lpMsgBuf;
char szBuffer[100];
char szDriverImagePath[256];
//得到完整的驱动路径
//GetFullPathName(lpszDriverPath, 256, szDriverImagePath, NULL);
BOOL bRet = FALSE;
SC_HANDLE hServiceMgr=NULL;//SCM管理器的句柄
SC_HANDLE hServiceDDK=NULL;//NT驱动程序的服务句柄
//打开服务控制管理器
//hServiceMgr = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );
hServiceMgr &