65.9K
CodeProject is changing. Read more.
Home

VS Service Pack

starIconstarIconstarIconstarIconstarIcon

5.00/5 (1 vote)

Mar 21, 2001

viewsIcon

49056

downloadIcon

757

Visual Studio Add-In that displays the latest service pack installed

Introduction

This is a simple add-in that allows you to quickly and easily find out which service pack you have installed for Visual Studio.

Creating the Add-in

Use the Visual C++ Add-in Wizard (specified in MDSN January 2001 in "Creating Add-ins Using Visual C++") to create an add-in:

  1. File --> New
  2. Projects
  3. Developer Studio Add-In Wizard
  4. type project name (VSSPVer) and click OK
  5. Let everything stay checked and click OK.
  6. Modify the default method name (both in interface and associated C++ class, definition and declaration) replacing it with the new name OnSPVersion.

The implementation looks like this:

STDMETHODIMP CCommands::OnSPVersion() 
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());

    // TODO: Replace this with the actual code to execute this command
    //  Use m_pApplication to access the Developer Studio Application object,
    //  and VERIFY_OK to see error strings in DEBUG builds of your add-in
    //  (see stdafx.h)

    HKEY    hkVSSPVer    = NULL;
    LONG    lRetVal        = NO_ERROR;
    CString    strVersion;

    lRetVal = 
        ::RegOpenKeyEx
        (
            HKEY_LOCAL_MACHINE, 
            _T("SOFTWARE\\Microsoft\\VisualStudio\\6.0\\ServicePacks"), 
            0L, 
            KEY_READ, 
            &hkVSSPVer
        );
    if(lRetVal == NO_ERROR)
    {
        DWORD dwType;
        lRetVal = RegQueryValueEx(hkVSSPVer, _T("latest"), NULL, &dwType, NULL, NULL);
        if((lRetVal == NO_ERROR) && (dwType == REG_DWORD))
        {
            DWORD dwVSSPVersion = 0;
            DWORD dwDataLen        = sizeof(DWORD);

            lRetVal = ::RegQueryValueEx(hkVSSPVer, _T("latest"), NULL, 
                                        &dwType, (LPBYTE)&dwVSSPVersion, &dwDataLen);
            if(lRetVal == NO_ERROR)
            {
                strVersion.Format(IDS_VSSPVER_VERSION, dwVSSPVersion);
            }
            else
            {
                strVersion.LoadString(IDS_VSSPVER_UNKNOWN);
            }
        }
        else
        {
            strVersion.LoadString(IDS_VSSPVER_UNKNOWN);
        }

        RegCloseKey(hkVSSPVer);
    }
    else
    {
        strVersion.LoadString(IDS_VSSPVER_UNKNOWN);
    }

    VERIFY_OK(m_pApplication->EnableModeless(VARIANT_FALSE));
    ::MessageBox(NULL, strVersion, _T("Microsoft Visual Studio"), 
                 MB_OK | MB_ICONINFORMATION);
    VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE));

    return S_OK;
}

That's it. Compile, register the DLL using regsvr32 and that's it. It will appear into menu Tools/Customize/Add-ins and macro files with the name "VSSPVer Developer Studio Add-in".