HKEY hKey;
HANDLE hToken;
HANDLE hRootKey;
int iForbid = 157;
LPCTSTR data_Set=TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Exploer"); 
if ( RegOpenKeyEx ( HKEY_CURRENT_USER,
data_Set,
0,
KEY_WRITE,
&hKey) == ERROR_SUCCESS )
{
if( RegSetValueEx ( hKey,
TEXT("NoDriveTypeAutoRun"),
0,
REG_DWORD,
(LPBYTE)&iForbid,
sizeof( DWORD ) ) == ERROR_SUCCESS )
MessageBox(TEXT("自动播放功能已禁止!"),TEXT("提示"),MB_ICONINFORMATION);
else
MessageBox(TEXT("修改注册表出错!"),TEXT("提示"),MB_ICONERROR);
}
else
MessageBox(TEXT("打开注册表出错!"),TEXT("提示"),MB_ICONSTOP);
RegCloseKey(hKey);
总是提示“打开注册表出错!”,请高手看看是哪里出了问题了,小弟在此先谢谢了!

解决方案 »

  1.   

    出错时调用GetLastError,看看到底是什么原因。
      

  2.   

    先弄清楚,注册表有"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Exploer"这项吗?Explorer写成exploer了吧.
      

  3.   

    Unlike the RegCreateKeyEx function, the RegOpenKeyEx function does not create the specified key if the key does not exist in the registry.
      

  4.   

    大家都跟我一样没有发现那个小错误啊,是Explorer拼写错误,呵呵~
    我给写成Exploer了,还是谢谢大家的提示,呵呵