修改我的电脑注册到显示的信息

关于修改我的电脑注册到显示的信息

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

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值