首页
社区
课程
招聘
[讨论]win32应用程序控制驱动程序,是否都是这样实现?
发表于: 2007-8-8 16:43 6191

[讨论]win32应用程序控制驱动程序,是否都是这样实现?

2007-8-8 16:43
6191
最近学习到了应用程序和驱动程序的通讯部分,以下代码是否是一般实现控制驱动程序的模板,但我编译运行时总提示“注册驱动程序失败!”,哪位给看看?谢谢!
.386
.model flat, stdcall
option casemap:none
include windows.inc

include kernel32.inc
include user32.inc
include advapi32.inc

includelib kernel32.lib
includelib user32.lib
includelib advapi32.lib
.const
szSYS        db  'xxx.sys',0
szSERVICE    db  'xxxx',0
szDISPLAY    db  'xxxxxx',0
szERRORREG   db  '注册驱动程序失败!',0
szERRORCON   db '无法连接服务控制管理器!',0
.code

start proc

local hSCManager:HANDLE
local hService:HANDLE
local acDriverPath[MAX_PATH]:CHAR

; Open a handle to the SC Manager database 打开服务管理数据库句柄
invoke OpenSCManager, NULL, NULL, SC_MANAGER_CREATE_SERVICE  
;The OpenSCManager function establishes a connection to ;the service control manager on the specified computer and opens the specified database.
.if eax != NULL
  mov hSCManager, eax
  push eax
  invoke GetFullPathName, addr szSYS, sizeof acDriverPath, addr acDriverPath, esp ;获得指定文件的完整路径和文件名
     pop eax

  ; Register driver in SCM active database 注册驱动在服务控制管理数据库
; creates a service object and adds it to the specified service control manager database.
  invoke CreateService, hSCManager, addr szSERVICE, addr szDISPLAY, \
    SERVICE_START + DELETE, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, \
    SERVICE_ERROR_IGNORE, addr acDriverPath, NULL, NULL, NULL, NULL, NULL
  .if eax != NULL
   mov hService, eax
   invoke StartService, hService, 0, NULL   ;开启服务
   invoke DeleteService, hService
   invoke CloseServiceHandle, hService
  .else
   invoke MessageBox, NULL, addr szERRORREG, NULL, MB_ICONSTOP
  .endif
  invoke CloseServiceHandle, hSCManager
.else
  invoke MessageBox, NULL, addr szERRORCON, NULL, MB_ICONSTOP
.endif

invoke ExitProcess, 0

start endp

end start

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 0
支持
分享
最新回复 (2)
雪    币: 796
活跃值: (370)
能力值: ( LV9,RANK:380 )
在线值:
发帖
回帖
粉丝
2
服务名已经存在,无法创建。。。换个服务名。
2007-8-8 23:01
0
雪    币: 321
活跃值: (275)
能力值: ( LV13,RANK:1050 )
在线值:
发帖
回帖
粉丝
3
这是正规的一种驱动加载办法。
2007-8-10 15:02
0
游客
登录 | 注册 方可回帖
返回