VirtualBox

Ignore:
Timestamp:
Sep 8, 2009 1:33:06 PM (15 years ago)
Author:
vboxsync
Message:

VBoxService: Rewritten Guest Additions lookup, added Wow6432Node support (running on 64-bit but having the keys in 32-bit node due to an old previous VBoxService).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo-win.cpp

    r22728 r22840  
    337337
    338338    HKEY hKey = NULL;
    339     long rc = 0;
     339    int rc;
    340340    DWORD dwSize = 0;
    341341    DWORD dwType = 0;
     
    344344
    345345    /* Check the new path first. */
    346     rc = RegOpenKeyExA (HKEY_LOCAL_MACHINE, "SOFTWARE\\Sun\\VirtualBox Guest Additions", 0, KEY_READ, &hKey);
     346    rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Sun\\VirtualBox Guest Additions", 0, KEY_READ, &hKey);
     347#ifdef RT_ARCH_AMD64
    347348    if (rc != ERROR_SUCCESS)
    348349    {
    349         VBoxServiceVerbose(3, "Guest Additions version lookup: Looking in xVM key ...\n");
    350 
    351         /* New path does not exist, check the old one ... */
    352         rc = RegOpenKeyExA (HKEY_LOCAL_MACHINE, "SOFTWARE\\Sun\\xVM VirtualBox Guest Additions", 0, KEY_READ, &hKey);
     350        /* Check Wow6432Node (for new entries). */
     351        rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wow6432Node\\Sun\\VirtualBox Guest Additions", 0, KEY_READ, &hKey);
     352    }
     353#endif
     354
     355    /* Still no luck? Then try the old xVM paths ... */
     356    if (RT_FAILURE(rc))
     357    {
     358        rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Sun\\xVM VirtualBox Guest Additions", 0, KEY_READ, &hKey);
     359#ifdef RT_ARCH_AMD64
    353360        if (rc != ERROR_SUCCESS)
    354361        {
    355             /* Nothing seems to exist, print some warning. */
    356             VBoxServiceError("Failed to open registry key (guest additions)! Error: %d\n", rc);
    357             return 1;
    358         }
    359     }
    360 
    361     VBoxServiceVerbose(3, "Guest Additions version lookup: Key: 0x%p, RC: %d\n", hKey, rc);
    362 
    363     /* Installation directory. */
    364     dwSize = sizeof(szInstDir);
    365     rc = RegQueryValueExA (hKey, "InstallDir", NULL, &dwType, (BYTE*)(LPCTSTR)szInstDir, &dwSize);
    366     if ((rc != ERROR_SUCCESS) && (rc != ERROR_FILE_NOT_FOUND))
    367     {
    368         RegCloseKey (hKey);
    369         VBoxServiceError("Failed to query registry key (install directory)! Error: %d\n", rc);
    370         return 1;
    371     }
    372 
    373     /* Flip slashes. */
    374     for (char* pszTmp = &szInstDir[0]; *pszTmp; ++pszTmp)
    375         if (*pszTmp == '\\')
    376             *pszTmp = '/';
    377 
    378     /* Revision. */
    379     dwSize = sizeof(szRev);
    380     rc = RegQueryValueExA (hKey, "Revision", NULL, &dwType, (BYTE*)(LPCTSTR)szRev, &dwSize);
    381     if ((rc != ERROR_SUCCESS) && (rc != ERROR_FILE_NOT_FOUND))
    382     {
    383         RegCloseKey (hKey);
    384         VBoxServiceError("Failed to query registry key (revision)! Error: %d\n",  rc);
    385         return 1;
    386     }
    387 
    388     /* Version. */
    389     dwSize = sizeof(szVer);
    390     rc = RegQueryValueExA (hKey, "Version", NULL, &dwType, (BYTE*)(LPCTSTR)szVer, &dwSize);
    391     if ((rc != ERROR_SUCCESS) && (rc != ERROR_FILE_NOT_FOUND))
    392     {
    393         RegCloseKey (hKey);
    394         VBoxServiceError("Failed to query registry key (version)! Error: %u\n",  rc);
    395         return 1;
     362            /* Check Wow6432Node (for new entries). */
     363            rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wow6432Node\\Sun\\xVM VirtualBox Guest Additions", 0, KEY_READ, &hKey);
     364        }
     365#endif
     366    }
     367
     368    /* Did we get something worth looking at? */
     369    if (RT_FAILURE(rc))
     370    {
     371        VBoxServiceError("Failed to open registry key (guest additions)! Error: %Rrc\n", rc);
     372    }
     373    else
     374    {
     375        VBoxServiceVerbose(3, "Guest Additions version lookup: Key: 0x%p, rc: %Rrc\n", hKey, rc);
     376        /* Installation directory. */
     377        dwSize = sizeof(szInstDir);
     378        rc = RegQueryValueEx(hKey, "InstallDir", NULL, &dwType, (BYTE*)(LPCTSTR)szInstDir, &dwSize);
     379        if ((rc != ERROR_SUCCESS) && (rc != ERROR_FILE_NOT_FOUND))
     380        {
     381            VBoxServiceError("Failed to query registry key (install directory)! Error: %Rrc\n", rc);
     382        }   
     383        else
     384        {
     385            /* Flip slashes. */
     386            for (char* pszTmp = &szInstDir[0]; *pszTmp; ++pszTmp)
     387                if (*pszTmp == '\\')
     388                    *pszTmp = '/';
     389        }
     390        /* Revision. */
     391        dwSize = sizeof(szRev);
     392        rc = RegQueryValueEx(hKey, "Revision", NULL, &dwType, (BYTE*)(LPCTSTR)szRev, &dwSize);
     393        if ((rc != ERROR_SUCCESS) && (rc != ERROR_FILE_NOT_FOUND))
     394            VBoxServiceError("Failed to query registry key (revision)! Error: %Rrc\n", rc);
     395        /* Version. */
     396        dwSize = sizeof(szVer);
     397        rc = RegQueryValueEx(hKey, "Version", NULL, &dwType, (BYTE*)(LPCTSTR)szVer, &dwSize);
     398        if ((rc != ERROR_SUCCESS) && (rc != ERROR_FILE_NOT_FOUND))
     399            VBoxServiceError("Failed to query registry key (version)! Error: %Rrc\n", rc);
    396400    }
    397401
     
    401405    VboxServiceWriteProp(uiClientID, "GuestAdd/Version", szVer);
    402406
    403     RegCloseKey (hKey);
    404 
    405     return VINF_SUCCESS;
     407    if (NULL != hKey)
     408        RegCloseKey(hKey);
     409
     410    return rc;
    406411}
    407412
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette