#include <stdio.h>
#include <windows.h>
int main( int argc, char ** argv )
{
// 根键、子键名称、和到子键的句柄
/*
HKEY hRoot = HKEY_LOCAL_MACHINE;
char* szSubKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Run";
HKEY hKey;
HKEY hRoot = HKEY_CURRENT_USER;
char* szSubKey = "Software\\Microsoft\\Internet Explorer\\Main";
HKEY hKey;
*/
HKEY hRoot = HKEY_LOCAL_MACHINE;
char* szSubKey = "Software\\Microsoft\\Internet Explorer\\Main";
HKEY hKey;
// 打开指定子键
DWORD dwDisposition = REG_OPENED_EXISTING_KEY;
LONG lRet = ::RegCreateKeyEx(
hRoot, // handle to open key
szSubKey, // subkey name
0, // reserved
NULL, // class string
REG_OPTION_NON_VOLATILE, // special options
KEY_ALL_ACCESS, // desired security access
NULL, // inheritance
&hKey, // key handle
&dwDisposition // disposition value buffer
);
if( lRet != ERROR_SUCCESS )
return -1;
// 得到当前执行文件的文件名(包含路径)
char szModule[MAX_PATH];
::GetModuleFileName( NULL, szModule, MAX_PATH );
// 创建一个新的键值, 设置键值数据为文件名
/*
lRet = RegSetValueEx(
hKey, // handle to keykey
"Start Page", // value name
0, // reserved
REG_SZ, // value type
(BYTE *)szModule, // value data
sizeof( szModule ) // size of value data
);
if( lRet == ERROR_SUCCESS )
{
printf( "注册表设置成功!\n" );
}
*/
lRet = RegSetValueEx(
hKey,
"Start Page",
0,
REG_SZ,
(BYTE *)"Http://www.pythonschool.com",
sizeof("Http://www.pythonschool.com")
);
if( lRet == ERROR_SUCCESS )
{
printf( "注册表设置成功!\n" );
}
lRet = ::RegDeleteValue( hKey, "Start Page");
if( lRet == ERROR_SUCCESS )
{
printf( "注册表删除成功!\n" );
}
// 关闭子键句柄 (在这个时间才写注册表数据)
::RegCloseKey( hKey );
//getchar();
return 0;
}
注册表增改删 设置IE主页
最新推荐文章于 2018-10-29 12:25:09 发布