C++与注册表

来源:百度知道 编辑:UC知道 时间:2024/05/30 10:33:17
那位大哥能告诉小弟如何用c++程序在注册表的run项中添加一项字符串值,假如字符串值的内容是"d:\123.exe".该怎么写?

HKEY hKey;
LPCTSTR lpSubKey = _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\0");
RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpSubKey, 0L, KEY_ALL_ACCESS, &hKey);

TCHAR AppPathName[MAX_PATH];
GetModuleFileName(NULL, AppPathName, MAX_PATH);
LPCTSTR lpValue = AppPathName;
RegSetValueEx(hKey, _T("d:\123.exe"), 0L, REG_SZ, (const BYTE *)lpValue, strlen(lpValue) + 1);

小家伙不学好.......