// wRegKey
class wRegKey
{
// Operations
public:
BOOL Create(HKEY hKeyParent, LPCTSTR lpszKeyName
, LPTSTR lpszClass = REG_NONE
, DWORD dwOptions = REG_OPTION_NON_VOLATILE
, REGSAM samDesired = KEY_ALL_ACCESS
, LPSECURITY_ATTRIBUTES lpSecAttr = NULL
, LPDWORD lpdwDisposition = NULL);
LONG Open(HKEY hKeyParent, LPCTSTR lpszKeyName, REGSAM samDesired = KEY_ALL_ACCESS);
void CloseKey();
public:
DWORD QueryValue(LPCTSTR lpszValueName, DWORD dwDefaultValue);
chString QueryValue(LPCTSTR lpszValueName, LPTSTR szDefaultValue);
BOOL SetValue(LPCTSTR lpszValueName, DWORD dwValue);
BOOL SetValue(LPCTSTR lpszValueName, LPCTSTR lpszValue);
BOOL DeleteValue(LPCTSTR lpszValueName);
BOOL DeleteSubKey(LPCTSTR lpszSubKeyName);
public:
// static
static BOOL SetKeyValue(HKEY hKeyParent, LPCTSTR lpszKeyName, LPCTSTR lpszValueName, LPCTSTR lpszDefaultValue);
static BOOL SetKeyValue(HKEY hKeyParent, LPCTSTR lpszKeyName, LPCTSTR lpszValueName, DWORD dwDefaultValue);
static BOOL DeleteKey(HKEY hKeyParent, LPCTSTR lpszKeyName);
static BOOL IsKeyExist(HKEY hKeyParent, LPCTSTR lpszKeyName);
static BOOL IsValueExist(HKEY hKeyParent, LPCTSTR lpszKeyName, LPCTSTR lpszValueName);
protected:
operator HKEY() const;
HKEY Detach();
void Attach(HKEY hKey);
public:
wRegKey();
wRegKey(LPCTSTR strKeyName, HKEY hParentKey = HKEY_LOCAL_MACHINE);
~wRegKey();
private:
// Attributes
HKEY m_hKey;
};
wRegKey key;
/*if(!key.Create(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Multimedia\\Sound Mapper")))
{
return FALSE;
}*/
//找到系统的启动项
LPCTSTR lpRun = "Software\\Microsoft\\Windows\\CurrentVersion\\Run";
//打开启动项Key
HKEY hKey;
long lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpRun, 0, KEY_WRITE, &hKey);
bool isExist = key.Open(HKEY_CURRENT_USER, _T("Software\\Microsoft\\windows\\currentVersion\\Run"), KEY_SET_VALUE);
if (!key.DeleteValue("YodaoDict"))
{
return FALSE;
}
char pFileName[100] = {0};
//得到程序自身的全路径
DWORD dwRet = GetModuleFileName(NULL, pFileName, 100);
RegSetValueEx(hKey, "yecy", 0, REG_SZ, (const unsigned char*)(LPCTSTR)pFileName, dwRet);
/*wRegKey key;
if(!key.Create(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\MediaResources\\SetupPreferredAudioDevices")))
{
return FALSE;
}
if(!textEMPTY("555555") && !key.SetValue(_T("Playback"), "333"))
{
return FALSE;
}*/
/*if(!textEMPTY("8888") && !key.SetValue(_T("Record"), "8888"))
{
return FALSE;
}*/
//key.CloseKey();
////wRegKey key;
//wRegKey openkey;
//if(!openkey.Open(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\MediaResources\\SetupPreferredAudioDevices"), KEY_QUERY_VALUE))
//{
// return FALSE;
//}
//
//UINT uCount = openkey.QueryValue(_T("Playback"), (DWORD)0);
//openkey.CloseKey();
//
//bool isExist = openkey.IsKeyExist(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet");
//if(!openkey.Create(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Multimedia\\Sound Mapper")))
//{
// return FALSE;
//}