📄 updatereg.cpp
字号:
// UpdateReg.cpp: implementation of the CUpdateReg class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "resource.h"
#include "UpdateReg.h"
#include "RegManager.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CUpdateReg::CUpdateReg()
{
m_handleThread = NULL;
m_dwThreadID = 0;
m_hExitFlag = NULL;
}
CUpdateReg::~CUpdateReg()
{
}
// 启动工作线程 [5/12/2008 By willing]
DWORD CUpdateReg::Run()
{
m_hExitFlag = ::CreateEvent(NULL, TRUE, FALSE, NULL);
if (NULL == m_hExitFlag)
{
return -1;
}
m_handleThread = CreateThread( NULL, 0, UpdateRegThread,
( LPVOID )this, NULL, &m_dwThreadID );
if (NULL == m_handleThread)
{
return -2;
}
return 0;
}
// 分派线程主函数 [5/12/2008 By willing]
DWORD WINAPI CUpdateReg::UpdateRegThread(LPVOID lpParam)
{
if (NULL == lpParam)
{
return -1;
}
CUpdateReg* ptrUpdateReg = (CUpdateReg*)lpParam;
while (1)
{
if(::WaitForSingleObject(ptrUpdateReg->m_hExitFlag, 500) == WAIT_OBJECT_0)
break;
// 实现更新 [5/12/2008 By willing]
ptrUpdateReg->Update(_ConfigInfo);
}
return 0;
}
// 停止工作线程 [5/12/2008 By willing]
void CUpdateReg::Stop()
{
if (NULL != m_hExitFlag)
{
::SetEvent(m_hExitFlag);
}
if (NULL != m_handleThread)
{
DWORD dwReCode = ::WaitForSingleObject(this->m_handleThread, 2000);
if (WAIT_TIMEOUT == dwReCode)
{
// 如果等待超时就强制退出 [5/12/2008 By willing]
::TerminateThread(m_handleThread,0);
}
}
if(this->m_hExitFlag != NULL)
{
::CloseHandle(this->m_hExitFlag);
this->m_hExitFlag = NULL;
}
this->m_handleThread = NULL;
DEGBUGLOG("CDispatch","Stop","退出线程");
return ;
}
// 实现更新注册表的函数 [5/12/2008 By willing]
void CUpdateReg::Update(CConfigInfo CConfigInfo)
{
CRegManager RegManager;
HKEY hRootKey = HKEY_LOCAL_MACHINE;
char *pszRegPatch = "SYSTEM\\CurrentControlSet\\Services\\AgentA\\Parameters";
RegManager.SetDwordRegValue(hRootKey,pszRegPatch,"DES",CConfigInfo.m_nDes);
RegManager.SetDwordRegValue(hRootKey,pszRegPatch,"3DES",CConfigInfo.m_n3Des);
RegManager.SetDwordRegValue(hRootKey,pszRegPatch,"ENCTYPE",CConfigInfo.m_nEncryptType);
RegManager.SetDwordRegValue(hRootKey,pszRegPatch,"PWDLEN",CConfigInfo.m_nPwdLen);
RegManager.SetDwordRegValue(hRootKey,pszRegPatch,"ISUSE",CConfigInfo.m_nIsUse);
DEGBUGLOG("CDispatch","Update","策略已经更新到注册表中");
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -