代码语言:javascript复制
//
//Registry.h
#if !defined(AFX_REGISTRY_H__E0610A5D_7166_4D02_9D7E_11AF7CF8E229__INCLUDED_)
#define AFX_REGISTRY_H__E0610A5D_7166_4D02_9D7E_11AF7CF8E229__INCLUDED_
//
#include <winreg.h>
/
// CRegistry window
class CRegistry : public CObject
{
// Construction
public:
CRegistry(HKEY hKey=HKEY_LOCAL_MACHINE);
public:
BOOL SaveKey(LPCTSTR lpFileName);
BOOL RestoreKey(LPCTSTR lpFileName);
BOOL Read(LPCTSTR lpValueName, CString* lpVal);
BOOL Read(LPCTSTR lpValueName, DWORD* pdwVal);
BOOL Read(LPCTSTR lpValueName, int* pnVal);
BOOL Write(LPCTSTR lpSubKey, LPCTSTR lpVal);
BOOL Write(LPCTSTR lpSubKey, DWORD dwVal);
BOOL Write(LPCTSTR lpSubKey, int nVal);
BOOL DeleteKey(HKEY hKey, LPCTSTR lpSubKey);
BOOL DeleteValue(LPCTSTR lpValueName);
void Close();
BOOL Open(LPCTSTR lpSubKey);
BOOL CreateKey(LPCTSTR lpSubKey);
virtual ~CRegistry();
protected:
HKEY m_hKey;
};
/
#endif // !defined(AFX_REGISTRY_H__E0610A5D_7166_4D02_9D7E_11AF7CF8E229__INCLUDED_)
代码语言:javascript复制// Registry.cpp : implementation file
//
#include "stdafx.h"
#include "Registry.h"
/
// CRegistry
CRegistry::CRegistry(HKEY hKey)
{
m_hKey=hKey;
}
CRegistry::~CRegistry()
{
Close();
}
/
// CRegistry Functions
BOOL CRegistry::CreateKey(LPCTSTR lpSubKey)
{
ASSERT(m_hKey);
ASSERT(lpSubKey);
HKEY hKey;
DWORD dw;
long lReturn=RegCreateKeyEx(m_hKey,lpSubKey,0L,NULL,REG_OPTION_VOLATILE,KEY_ALL_ACCESS,NULL,&hKey,&dw);
if(lReturn==ERROR_SUCCESS)
{
m_hKey=hKey;
return TRUE;
}
return FALSE;
}
BOOL CRegistry::Open(LPCTSTR lpSubKey)
{
ASSERT(m_hKey);
ASSERT(lpSubKey);
HKEY hKey;
long lReturn=RegOpenKeyEx(m_hKey,lpSubKey,0L,KEY_ALL_ACCESS,&hKey);
if(lReturn==ERROR_SUCCESS)
{
m_hKey=hKey;
return TRUE;
}
return FALSE;
}
void CRegistry::Close()
{
if(m_hKey)
{
RegCloseKey(m_hKey);
m_hKey=NULL;
}
}
BOOL CRegistry::DeleteValue(LPCTSTR lpValueName)
{
ASSERT(m_hKey);
ASSERT(lpValueName);
long lReturn=RegDeleteValue(m_hKey,lpValueName);
if(lReturn==ERROR_SUCCESS)
return TRUE;
return FALSE;
}
BOOL CRegistry::DeleteKey(HKEY hKey, LPCTSTR lpSubKey)
{
ASSERT(hKey);
ASSERT(lpSubKey);
long lReturn=RegDeleteKey(hKey,lpSubKey);
if(lReturn==ERROR_SUCCESS)
return TRUE;
return FALSE;
}
BOOL CRegistry::Write(LPCTSTR lpSubKey, int nVal)
{
ASSERT(m_hKey);
ASSERT(lpSubKey);
DWORD dwValue;
dwValue=(DWORD)nVal;
long lReturn=RegSetValueEx(m_hKey,lpSubKey,0L,REG_DWORD,(const BYTE *) &dwValue,sizeof(DWORD));
if(lReturn==ERROR_SUCCESS)
return TRUE;
return FALSE;
}
BOOL CRegistry::Write(LPCTSTR lpSubKey, DWORD dwVal)
{
ASSERT(m_hKey);
ASSERT(lpSubKey);
long lReturn=RegSetValueEx(m_hKey,lpSubKey,0L,REG_DWORD,(const BYTE *) &dwVal,sizeof(DWORD));
if(lReturn==ERROR_SUCCESS)
return TRUE;
return FALSE;
}
BOOL CRegistry::Write(LPCTSTR lpValueName, LPCTSTR lpValue)
{
ASSERT(m_hKey);
ASSERT(lpValueName);
ASSERT(lpValue);
long lReturn=RegSetValueEx(m_hKey,lpValueName,0L,REG_SZ,(const BYTE *) lpValue,strlen(lpValue) 1);
if(lReturn==ERROR_SUCCESS)
return TRUE;
return FALSE;
}
BOOL CRegistry::Read(LPCTSTR lpValueName, int* pnVal)
{
ASSERT(m_hKey);
ASSERT(lpValueName);
ASSERT(pnVal);
DWORD dwType;
DWORD dwSize=sizeof(DWORD);
DWORD dwDest;
long lReturn=RegQueryValueEx(m_hKey,lpValueName,NULL,&dwType,(BYTE *)&dwDest,&dwSize);
if(lReturn==ERROR_SUCCESS)
{
*pnVal=(int)dwDest;
return TRUE;
}
return FALSE;
}
BOOL CRegistry::Read(LPCTSTR lpValueName, DWORD* pdwVal)
{
ASSERT(m_hKey);
ASSERT(lpValueName);
ASSERT(pdwVal);
DWORD dwType;
DWORD dwSize=sizeof(DWORD);
DWORD dwDest;
long lReturn=RegQueryValueEx(m_hKey,lpValueName,NULL,&dwType,(BYTE *)&dwDest,&dwSize);
if(lReturn==ERROR_SUCCESS)
{
*pdwVal=dwDest;
return TRUE;
}
return FALSE;
}
BOOL CRegistry::RestoreKey(LPCTSTR lpFileName)
{
ASSERT(m_hKey);
ASSERT(lpFileName);
long lReturn=RegRestoreKey(m_hKey,lpFileName,REG_WHOLE_HIVE_VOLATILE);
if(lReturn==ERROR_SUCCESS)
return TRUE;
return FALSE;
}
BOOL CRegistry::SaveKey(LPCTSTR lpFileName)
{
ASSERT(m_hKey);
ASSERT(lpFileName);
long lReturn=RegSaveKey(m_hKey,lpFileName,NULL);
if(lReturn==ERROR_SUCCESS)
return TRUE;
return FALSE;
}
BOOL CRegistry::Read(LPCTSTR lpValueName, CString* lpVal)
{
ASSERT(m_hKey);
ASSERT(lpValueName);
ASSERT(lpVal);
DWORD dwType;
DWORD dwSize=200;
char szString[2550];
long lReturn=RegQueryValueEx(m_hKey,lpValueName,NULL,&dwType,(BYTE *)szString,&dwSize);
if(lReturn==ERROR_SUCCESS)
{
*lpVal=szString;
return TRUE;
}
return FALSE;
}
代码语言:javascript复制 //清除URL记录
m_status="清除URL记录";UpdateData(FALSE);
CRegistry key(HKEY_CURRENT_USER);
key.DeleteKey(HKEY_CURRENT_USER,"Software\Microsoft\Internet Explorer\TypedURLs ");
//清除IE记录
m_status="清除IE记录";UpdateData(FALSE);
CRegistry key3(HKEY_CURRENT_USER);
key3.DeleteKey(HKEY_CURRENT_USER,"Software\Microsoft\Internet Explorer\Explorer Bars\{C4EE31F3-4768-11D2-BE5C-00A0C9A83DA1}\FilesNamedMRU ");
key3.DeleteKey(HKEY_CURRENT_USER,"Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist\{75048700-EF1F-11D0-9888-006097DEACF9}\Count ");
//清除REALONE播放列表
m_status="清除REALONE播放列表";UpdateData(FALSE);
CRegistry key4(HKEY_CURRENT_USER);
char szpath[MAX_PATH];
for (int i=1;i<=10;i )
{
sprintf(szpath,"Software\RealNetworks\RealPlayer\6.0\Preferences\MostRecentClips%d ",i);
key4.DeleteKey(HKEY_CURRENT_USER,szpath);
}