求助!RegOpenKey返回值为2
在win7中用VC6.0写了如下小程序,但RegOpenKey总是失败~为什吗捏?在线等~
#include <windows.h>
#include <iostream>
#include <string>
using namespace std;
void main()
{
char regname[] = "Software\\Miscrosoft\\Windows\\CurrentVersion\\Run";
HKEY hkResult;
int ret = RegOpenKey(HKEY_LOCAL_MACHINE,regname,&hkResult);
if(ret!=ERROR_SUCCESS)
{
cout<<ret<<" failed to open regedit\n";
return;
}
ret = RegSetValueEx(hkResult,"test",0,REG_EXPAND_SZ,(unsigned char *)"C:\\Windows\\System32\\test.exe",25);
if(ret == 0)
{
cout<<"success to write run key\n";
RegCloseKey(hkResult);
}
else
{
cout<<"failed to open regedit."<<endl;
}
}
[解决办法]
If the function succeeds, the return value is ERROR_SUCCESS.
If the function fails, the return value is a nonzero error code defined in Winerror.h. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.
[解决办法]
前面或后面加//试试
[解决办法]
HKEY_LOCAL_MACHINE
是这个子目录里面的么?