snlie
驱动牛犊
驱动牛犊
  • 注册日期2010-03-31
  • 最后登录2010-11-14
  • 粉丝0
  • 关注0
  • 积分2分
  • 威望11点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1697回复:1

如何写个程序让驱动安装并加载?

楼主#
更多 发布于:2010-11-14 19:10
现有一个驱动文件:
Shadow.sys
每次运行都需要用InstDrv.exe来进行安装加载停止卸载操作。
有没有办法写个像这样的软件来实现驱动自安装的。

要如何实现呢?
instruder
论坛版主
论坛版主
  • 注册日期2010-03-10
  • 最后登录2011-02-15
  • 粉丝0
  • 关注7
  • 积分31分
  • 威望281点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2011-01-08 12:31
sdk上面有完整的加载驱动和卸载驱动的例子
可以搜索下例如以Starting a Service
#include <windows.h>#include <stdio.h>TCHAR szSvcName[80];SC_HANDLE schSCManager;SC_HANDLE schService;//// Purpose: //   Starts the service.//// Parameters://   None// // Return value://   None//VOID DoStartSvc(){    SERVICE_STATUS_PROCESS ssStatus;     DWORD dwOldCheckPoint;     DWORD dwStartTickCount;    DWORD dwWaitTime;    DWORD dwBytesNeeded;    // Get a handle to the SCM database.      schSCManager = OpenSCManager(         NULL,                    // local computer        NULL,                    // ServicesActive database         SC_MANAGER_ALL_ACCESS);  // full access rights      if (NULL == schSCManager)     {        printf("OpenSCManager failed (%d)\n", GetLastError());        return;    }    // Get a handle to the service.    schService = OpenService(         schSCManager,         // SCM database         szSvcName,            // name of service         SERVICE_ALL_ACCESS);  // full access      if (schService == NULL)    {         printf("OpenService failed (%d)\n", GetLastError());         CloseServiceHandle(schSCManager);        return;    }        // Attempt to start the service.    if (!StartService(            schService,  // handle to service             0,           // number of arguments             NULL) )      // no arguments     {        printf("StartService failed (%d)\n", GetLastError());        CloseServiceHandle(schService);         CloseServiceHandle(schSCManager);        return;     }    else printf("Service start pending...\n");     // Check the status until the service is no longer start pending.      if (!QueryServiceStatusEx(             schService,             // handle to service             SC_STATUS_PROCESS_INFO, // info level            (LPBYTE) &ssStatus,             // address of structure            sizeof(SERVICE_STATUS_PROCESS), // size of structure            &dwBytesNeeded ) )              // if buffer too small    {        return;     }     // Save the tick count and initial checkpoint.    dwStartTickCount = GetTickCount();    dwOldCheckPoint = ssStatus.dwCheckPoint;    while (ssStatus.dwCurrentState == SERVICE_START_PENDING)     {         // Do not wait longer than the wait hint. A good interval is         // one-tenth the wait hint, but no less than 1 second and no         // more than 10 seconds.          dwWaitTime = ssStatus.dwWaitHint / 10;        if( dwWaitTime < 1000 )            dwWaitTime = 1000;        else if ( dwWaitTime > 10000 )            dwWaitTime = 10000;        Sleep( dwWaitTime );        // Check the status again.          if (!QueryServiceStatusEx(             schService,             // handle to service             SC_STATUS_PROCESS_INFO, // info level            (LPBYTE) &ssStatus,             // address of structure            sizeof(SERVICE_STATUS_PROCESS), // size of structure            &dwBytesNeeded ) )              // if buffer too small            break;          if ( ssStatus.dwCheckPoint > dwOldCheckPoint )        {            // The service is making progress.            dwStartTickCount = GetTickCount();            dwOldCheckPoint = ssStatus.dwCheckPoint;        }        else        {            if(GetTickCount()-dwStartTickCount > ssStatus.dwWaitHint)            {                // No progress made within the wait hint.                break;            }        }    }     // Determine whether the service is running    if (ssStatus.dwCurrentState == SERVICE_RUNNING)     {        printf("Service started successfully.\n");     }    else     {         printf("Service not started. \n");        printf("  Current State: %d\n", ssStatus.dwCurrentState);         printf("  Exit Code: %d\n", ssStatus.dwWin32ExitCode);         printf("  Check Point: %d\n", ssStatus.dwCheckPoint);         printf("  Wait Hint: %d\n", ssStatus.dwWaitHint);     }     CloseServiceHandle(schService);     CloseServiceHandle(schSCManager);}

游客

返回顶部