Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am building an application in MFC,through my application i want to add a new key and set the value to it.And again add a subkey to that key.I have written a code for it,but there might be some mistake in my code and the key is not getting created.Below is my code
C++
char *m_tmpChar;
m_tmpChar="iexplore.exe";

RegCreateKeyEx(HKEY_CURRENT_USER,L"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&hkey,0);

RegSetValueEx(hkey,L"disallowrun",NULL,REG_SZ,(unsigned char*)m_tmpChar,strlen(m_tmpChar)+1);

 RegCloseKey(hkey);

Please kindly help me for this.

Thanks in Advance

[Edit]Code block added[/Edit]
Posted
Updated 3-Nov-12 0:16am
v3

1 solution

It would be near by MFC :
C++
bool Test()
{
  bool bResult(false);
  CRegKey cKey;
  if (ERROR_SUCCESS ==
      cKey.Create(HKEY_CURRENT_USER,
                  _T("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"))) {
    bResult = (ERROR_SUCCESS ==cKey.SetStringValue(_T("disallowrun"), _T("iexplore.exe")));
  }
  return bResult;
}

Try also to use CString instead of char* :)
 
Share this answer
 
Comments
Rocky_Bas 3-Nov-12 8:29am    
This code is working for other registry keys but its not working for this particular registry key , i dont know why??

Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer
Jochen Arndt 3-Nov-12 9:42am    
Check the access rights of the Policies key. On my Win7 Pro, it is not writable for the current user. Write access requires accounts that are members of the administrator group.
Eugen Podsypalnikov 3-Nov-12 16:12pm    
As Jochen said, you could try to
- manipulate your manifest to provide the administrator rights for the application, or
- write a service started by the SYSTEM user and delegate such tasks to it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900