WIN7X64过TP驱动源码


可以过简单的TP游戏,自己放弃的一个版本,具体可以过那些需要自己去测试
资源截图
代码片段和文件信息
#include “stdafx.h“
#include “Driver.h“
#include 
#include 
#include 

#include “Global.h“

#pragma comment(lib “setupapi.lib“)
#pragma comment(lib “newdev.lib“)
CDriver::CDriver()
{
}


CDriver::~CDriver()
{
}

CString  CDriver::installDvr()
{
CString ret=NULL;
if (NULL != m_hSerMgr)
{
ret=“状态:因为驱动服务已经存在,所以驱动服务安装失败!
“;
return ret;
}
HANDLE hToken;
OpenProcessToken(GetCurrentProcess() TOKEN_ADJUST_PRIVILEGES &hToken);
AdjustProcessPrivilege(hToken SE_DEBUG_NAME);
m_hSerMgr = OpenSCManagerA(NULL NULL SC_MANAGER_ALL_ACCESS);
if (m_hSerMgr==NULL)
{
ret=“状态:驱动服务安装失败!
“;
return ret;
}
m_hServer = CreateServiceA(m_hSerMgr m_strSysFileName m_strSysFileName SERVICE_ALL_ACCESS 
SERVICE_KERNEL_DRIVER SERVICE_DEMAND_START SERVICE_ERROR_NORMAL m_strSysFilePath NULL NULL 
NULL NULL NULL);
if (NULL == m_hServer)
{
DWORD dwRet = GetLastError();
if (dwRet != ERROR_IO_PENDING && dwRet != ERROR_SERVICE_EXISTS)
{
if (!StartServiceA(m_hServer 0 0)){
DeleteService(m_hServer); //启动失败、则删除已经创建的服务
}
if (NULL != m_hSerMgr)
{
CloseServiceHandle(m_hSerMgr);
m_hSerMgr = NULL;
}

ret = “状态:驱动服务安装失败!
“;
return ret;
}
m_hServer = OpenServiceA(m_hSerMgr m_strSysFileName SERVICE_ALL_ACCESS);
if (NULL == m_hServer)
{
ret=“状态:因为驱动服务已经存在,所以驱动服务安装失败!
“;
return ret;
}
}
else
{
ret = “状态:驱动服务安装成功!
“;
}
return ret;
}

CString CDriver::startDvr()
{
CString ret = NULL;
if (NULL == m_hSerMgr && NULL == m_hServer)
{
ret=“状态:启动驱动失败!
“;
return ret;
}
if (!StartServiceA(m_hServer NULL NULL))
{
DWORD dwRet = GetLastError();
if (dwRet != ERROR_IO_PENDING && dwRet != ERROR_SERVICE_ALREADY_RUNNING)
{
ret = “状态:启动驱动失败!
“;
return ret;
}
else
{
ret = “状态:因为驱动服务已经启动,所以驱动服务启动失败!
“;
return ret;
}
}
else
{
ret = “状态:驱动服务启动成功!
“;
}
return ret;
}
CString CDriver::stopDvr()
{
CString ret = NULL;
if (NULL == m_hSerMgr && NULL == m_hServer)
{
ret=“状态:因为驱动服务没有启动,所以驱动服务停止失败!
“;
return ret;
}
SERVICE_STATUS stSerStatus = { 0 };
if (!ControlService(m_hServer SERVICE_CONTROL_STOP &stSerStatus))
{
ret = “状态:因为驱动服务没有启动,所以驱动服务停止失败!
“;
return ret;
}
else
{
ret = “状态:驱动服务停止成功!
“;
}
return ret;
}
CString CDriver::unloadDvr()
{
CString ret = NULL;
if (NULL == m_hSerMgr && NULL == m_hServer)
{
ret=“状态:打开驱动服务失败,可能该驱动服务不存在!
“;
return ret;
}
if (!DeleteService(m_hServer))
{
ret=“状态:驱动服务卸载失败!
“;
return ret;
}
else
{
CloseServerHandle();
ret = “状态:驱动服务卸载成功!
“;
}
return ret;
}

void CDriver::CloseServerHandle()
{
if (NULL != m_hServer)
{
CloseServiceHandle(m_hServer);
m_hServer = NULL;
}
if (NULL != m_hSerMgr)
{
CloseServiceHandle(m_hSerMgr);
m_hSerMgr = NULL;
}
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)