关于修改我的电脑注册到显示的信息
HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows NT/CurrentVersion/
RegisteredOwner 个人名称
RegisteredOrganization 组织名称
//subkey name
const TCHAR Registered[] = _T("SOFTWARE//Microsoft//Windows NT//CurrentVersion");
//valuename
const TCHAR Owner[] = _T("RegisteredOwner");
const TCHAR Organization[] = _T("RegisteredOrganization");
HKEY hKey;
LONG lRet, lRetOwner, lRetOrganization;
DWORD dwLength, dwDataType;
TCHAR szCurValue[MAX_PATH];
TCHAR szBuffer[MAX_PATH];
//open the regedit
lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, Registered, 0, KEY_READ | KEY_WRITE, &hKey);
if (lRet != ERROR_SUCCESS) //judge open reg success
{
AfxMessageBox("Edit failure,Please check the register is enable to edit!",
MB_OK | MB_ICONEXCLAMATION);
}
else
{
//check RegisteredOwner is exist
dwLength = sizeof(szBuffer);
lRetOwner = RegQueryValueEx(hKey, Owner, NULL, &dwDataType,
(LPBYTE)szBuffer, &dwLength);
//transfer CString to TCHAR
TCHAR *szOwner;
szOwner = new TCHAR[m_strOwner.GetLength() + 1];
szOwner = m_strOwner.GetBuffer(m_strOwner.GetLength());
//Check the value get success
if (lRetOwner != ERROR_SUCCESS) //not exist
{
RegSetValueEx(hKey, Owner, 0, REG_SZ,
(LPBYTE)szOwner, strlen(szOwner));
}
else //exist
{
//get register key value
dwLength = sizeof(szCurValue);
RegQueryValueEx(hKey, Owner,0, &dwDataType,
(LPBYTE)szCurValue, &dwLength);
//compare the old and new value
if (lstrcmp(szOwner, szCurValue))
{
RegSetValueEx(hKey, Owner, 0, REG_SZ,
(LPBYTE)szOwner, strlen(szOwner));
}
}
//check RegisteredOrganization is exist
dwLength = sizeof(szBuffer);
lRetOrganization = RegQueryValueEx(hKey, Organization, NULL, &dwDataType,
(LPBYTE)szBuffer, &dwLength);
//transfer CString to TCHAR
TCHAR *szOrganization;
szOrganization = new TCHAR[m_strOrganization.GetLength() + 1];
szOrganization = m_strOrganization.GetBuffer(m_strOrganization.GetLength());
//Check the value get success
if (lRetOrganization != ERROR_SUCCESS) //not exist
{
RegSetValueEx(hKey, Organization,0, REG_SZ,
(LPBYTE)szOrganization, strlen(szOrganization));
}
else //exist
{
//get register key value
dwLength = sizeof(szCurValue);
RegQueryValueEx(hKey, Organization,0, &dwDataType,
(LPBYTE)szCurValue, &dwLength);
//compare the old and new value
if (lstrcmp(szOrganization, szCurValue))
{
RegSetValueEx(hKey, Organization, 0, REG_SZ,
(LPBYTE)szOrganization, strlen(szOrganization));
}
}
RegCloseKey(hKey); //close register
}