//能读懂并运用这段代码就行了.具体一些参数细节由图进行解释,很快就明白了,备注:关于win8下读写注册表需要相关权限.自行科普.
int test()
{LPCTSTR lpSubKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
HKEY hKey;
REGSAM flag = KEY_WOW64_64KEY;
DWORD dwDisposition = REG_OPENED_EXISTING_KEY;
LONG lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,lpSubKey, 0, KEY_ALL_ACCESS|flag,&hKey);
//LONG lRet = ::RegCreateKeyEx(HKEY_LOCAL_MACHINE, lpSubKey, NULL, NULL, REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition);
if ( ERROR_SUCCESS != lRet)
{
return -1;
}
TCHAR *pchrName = "D:\\非编程软件\\Tencent\\QQ\\Bin\\QQ.exe";
lRet = ::RegSetValueEx(hKey, TEXT("TEST"), NULL, REG_SZ, (LPBYTE)pchrName, strlen(pchrName)*sizeof(TCHAR)+1); //设置注册表项
if ( ERROR_SUCCESS != lRet)
{
return -1;
}
::RegCloseKey(hKey); //与RegCreateKeyEx配对写
return 0;
}