求C语言修改注册表函数

来源:百度知道 编辑:UC知道 时间:2024/06/14 18:14:14
在C程序里加入一个修改注册表中主页的程序,整整我们老师。。。
谢谢了

#include "stdio.h"
#include "stdlib.h"
#include"windows.h"
#include "iostream"
using namespace std;
int main(){
HKEY hKey;
LONG lRet;
lRet = RegOpenKeyExA(HKEY_CURRENT_USER,
"Software\\Microsoft\\Internet Explorer\\Main",
0,KEY_SET_VALUE, &hKey );
if( lRet != ERROR_SUCCESS ){
cout<<"open error!\n";
return FALSE;
}

LPCSTR data_Set="Start Page";

//只改以下一行内容,将字符串内容改成你想要的主页
LPCSTR da="http://www.baidu.com";
//

const BYTE * ta=(BYTE*)da;
DWORD length=strlen((char*)ta)+1;
lRet=RegSetValueExA(hKey,data_Set,0,REG_SZ,ta,length);
if(lRet!=ERROR_SUCCESS){
cout<<"cannot set!\n";
return false;