Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vista vs. RegCreateKeyEx (non-MFC app)

Status
Not open for further replies.

Miros

Programmer
Jan 27, 2001
506
US
I have a program that works fine in Win98 and WinXP. Vista apparently will not let my program modify the registry.

1) My program needs to save the path to the files it will work with in the registry.
Code:
long GetOrCreateRegistryInfoInt( char *keyname, long defaultvalue, long &keyval ) 
  {

    HKEY  hKey ;
    DWORD dwDispose ;

    keyval = defaultvalue ;

    long result = RegCreateKeyEx( HKEY_CURRENT_USER, "Software\\NameOfCompany", 0, NULL, REG_OPTION_NON_VOLATILE, 
        KEY_READ | KEY_WRITE, NULL, &hKey, &dwDispose ) ;
    if ( result == ERROR_SUCCESS )
      {
        if ( dwDispose == REG_CREATED_NEW_KEY  )
          {
            result = RegSetValueEx( hKey, keyname, 0, REG_DWORD, 
              ( UCHAR* )&defaultvalue, sizeof( long ) ) ;
          }
        else
          {
            ULONG size = sizeof( long ) ;

            result = RegQueryValueEx( hKey, keyname, 0, NULL, 
              ( UCHAR* )&keyval, &size ) ;
          }
        
        RegCloseKey( hKey ) ;
      }
    return result ;
  }
Is there a better hKey to use than HKEY_CURRENT_USER? Or will Vista just not allow me to change the registry?

2) I add various options to the context menu for certain extensions. This "used to be done" by adding the following keys:
Code:
      HKEY_CLASSES_ROOT\.bmp = Paint Picture
      HKEY_CLASSES_ROOT\Paint.Picture = Bitmap Image 
      // these 2 should already be in most people's registries
      HKEY_CLASSES_ROOT\Paint.Picture\shell\My_New_Command\command = {myapp} "%1"
      // this adds "My_New_Command to the context menu for .bmp files
      // {myapp} is the full path to my application.
Is this still the correct process, or has Vista completely changed this?
 
With HKEY_CURRENT_USER in Vista should be everything as usual. What do you get - error responce from RegCreateKeyEx()? What error code actually?
 
Actually, I think that bit is working (will test again later today). It was just hidden by the failure of the context menu items to appear.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top