Click here to Skip to main content
15,867,308 members
Articles / Desktop Programming / MFC

How to Start the Microsoft System Information Dialog

Rate me:
Please Sign up or sign in to vote.
4.11/5 (9 votes)
4 Oct 20022 min read 185.4K   3.6K   24   25
Starting Microsoft System Information programmatically from application
This article describes how to start Microsoft System Information programmatically from the application.

Microsoft System Information

Introduction

Everyone has seen the "System Info ..." button in the About box of Microsoft applications. It can be found in Microsoft Office apps, Visual Studio .NET and others. When clicked, it starts the Microsoft System Information utility. System Information displays a comprehensive view of your hardware, system components, and software environment. On earlier versions of Windows, namely Microsoft Office installed it (thanks to Matt Philmon for noticing that). I have once found out how to get its path in case the utility is installed developing MDB to SQLServer database converter with VB 6.0 - the function retrieving its path and starting it is added automatically to all VB projects about box. Look at the code below, it reads the registry for the first path and if not found, checks the second one for MSInfo32.exe. I think that in the newer versions of MS Windows, the MSInfo32.exe is left for backward compatibility just to start real program located somewhere else. For example, in Windows 2000, System Information is Microsoft Management Console (MMC) snap-in MSInfo32.msc located in the "C:\Program Files\Common Files\Microsoft Shared\MSInfo\" and MSInfo32.exe only seems to launch it.

Source Code

MFC Source Code

C++
// Required for the path functions

#if ( _MFC_VER < 0x0700 && !defined _INC_SHLWAPI ) 
    #include < Shlwapi.h >
    #pragma comment( lib, "Shlwapi.lib" ) 
#endif

// Required for the CRegKey

#include <atlbase.h>

#define IDS_REG_KEY_MSINFO_PATH1 _T( 
  "Software\\Microsoft\\Shared Tools\\MSInfo" )
#define IDS_REG_KEY_MSINFO_PATH2 _T( 
  "Software\\Microsoft\\Shared Tools Location" )
#define IDS_REG_VAL_MSINFO_PATH1 _T( "Path" )
#define IDS_REG_VAL_MSINFO_PATH2 _T( "MSInfo" )
#define IDS_MSINFO_EXE_NAME      _T( "MSInfo32.exe" )

//...

BOOL GetSysInfoPath( CString& strPath )
{        
    // Empty the string buffer and initialize variables.
    
    strPath.Empty();
    LPTSTR  pszPath = strPath.GetBuffer( MAX_PATH );
        
    CRegKey reg;
    DWORD   dwSize  = MAX_PATH;
    LONG    nRet    = reg.Open( HKEY_LOCAL_MACHINE, IDS_REG_KEY_MSINFO_PATH1,
                                KEY_READ );
                
    // Try to find "MSInfo32.exe" at the first location:
        
    if ( nRet == ERROR_SUCCESS )
    {
        #if ( _MFC_VER >= 0x0700 )
            nRet = reg.QueryStringValue( IDS_REG_VAL_MSINFO_PATH1, pszPath, 
                                         &dwSize );
        #else
            nRet = reg.QueryValue( 
              pszPath, IDS_REG_VAL_MSINFO_PATH1, &dwSize );
        #endif

        reg.Close();
    }
    
    // If first attemp fails then try to find "MSInfo32.exe" 
    // at the second location:

    if ( nRet != ERROR_SUCCESS )
    {
        nRet = reg.Open( 
          HKEY_LOCAL_MACHINE, IDS_REG_KEY_MSINFO_PATH2, KEY_READ );

        if ( nRet == ERROR_SUCCESS )
        {
            #if ( _MFC_VER >= 0x0700 )
                reg.QueryStringValue( IDS_REG_VAL_MSINFO_PATH2, pszPath,
                                      &dwSize );
            #else
                reg.QueryValue( pszPath, IDS_REG_VAL_MSINFO_PATH2, &dwSize );
            #endif
            
            // The second location does not contain the full
            // path (exe name is missing), complete it:

            if ( nRet == ERROR_SUCCESS )
                VERIFY( ::PathAppend( pszPath, IDS_MSINFO_EXE_NAME ) );

            reg.Close();
        }
    }
        
    strPath.ReleaseBuffer();
    strPath.FreeExtra();
    
    // Check for valid file.    
    return ::PathFileExists( strPath );
}

C# Source Code

C#
//...

using Microsoft.Win32;    // Required for the registry classes.
using System.IO;        // Required for the Path class.
using System.Diagnostics;    // Required for the process classes.

//...

public bool GetMsinfo32Path( ref string strPath )
{            
    strPath = string.Empty;
    object objTmp = null;
    RegistryKey regKey = Registry.LocalMachine;

    if( regKey != null )
    {
        regKey = regKey.OpenSubKey( 
             "Software\\Microsoft\\Shared Tools\\MSInfo" );
        if( regKey != null )
            objTmp = regKey.GetValue( "Path" );
    
        if( objTmp == null )
        {
            regKey = regKey.OpenSubKey( 
               "Software\\Microsoft\\Shared Tools Location" );
            if( regKey != null )
            {
                objTmp = regKey.GetValue( "MSInfo" );
                if( objTmp != null )
                    strPath = Path.Combine(
                       objTmp.ToString(), "MSInfo32.exe" );
            }
        }
        else
            strPath = objTmp.ToString();

        try
        {
            FileInfo fi = new FileInfo( strPath ); 
            return fi.Exists;
        }
        catch( ArgumentException )
        {
            strPath = string.Empty; 
        }
    }

    return false;
}

So we can get the full path to Msinfo32.exe and can run it:

MFC Sample

C++
void CSomeDialog::StartSysInfo( void )
{
    CString strMsinfo32( _T( "" ) );

    if( GetSysInfoPath( strMsinfo32 ) )
    {
        // Disable type cast warning for cast from HINSTANCE to INT. 
        // Although ShellExecute returns HINSTANCE for compatibility 
        // with 16-bit Windows applications, it is not a true HINSTANCE.
        // It can be cast only to an integer and compared to either 32 
        // or the SE_ERR_XXX error codes.

        #if _MSC_VER >= 1300 //Represents Microsoft Visual C++ .NET
            #pragma warning( disable : 4311 ) 
        #endif

        UINT uRet = (UINT)::ShellExecute( GetSafeHwnd(), _T( "open" ), 
                        strMsinfo32, NULL, NULL, SW_SHOWNORMAL );
        
        // Restore type cast warnings defaults

        #if _MSC_VER >= 1300 //Represents Microsoft Visual C++ .NET
            #pragma warning( default : 4311 )
        #endif
        
        if( uRet < = HINSTANCE_ERROR )
        {
            AfxMessageBox( _T( "Error Executing \"MsInfo32.exe\" !" ), 
                MB_OK | MB_ICONEXCLAMATION );
        }
    }
    else
    {
        AfxMessageBox( _T( "\"MsInfo32.exe\" cannot be found !" ), 
                MB_OK | MB_ICONEXCLAMATION );
    }
}

Using with Chris Maunder's Hyperlink control:

C++
// In the header:

#include "HyperLink.h"
//...
public:
    CHyperLink    m_wndLinkSysInfo;

// In the cpp:

BOOL CSomeDialog::OnInitDialog( void )
{
    // ...

    CString strSysInfo( _T( "" ) );
    if( GetSysInfoPath( strSysInfo ) )
        m_wndLinkSysInfo.SetURL( strSysInfo );
    else
        m_wndLinkSysInfo.EnableWindow( FALSE );
    //...
}

C# Sample

C#
private void StartSysInfo( string strSysInfo )
{
    try 
    {
        Process.Start( strSysInfo );
    }
    catch ( Win32Exception ex )
    {
        MessageBox.Show ( this, ex.Message, Application.ProductName, 
            MessageBoxButtons.OK, MessageBoxIcon.Exclamation );
    }
}

// Start using LinkLabel control:

private void lnkSysInfo_LinkClicked( object sender, 
             System.Windows.Forms.LinkLabelLinkClickedEventArgs e )
{            
    lnkSysInfo.Links[ lnkSysInfo.Links.IndexOf( e.Link ) ].Visited = true;
    StartSysInfo( e.Link.LinkData.ToString() );
}

// Start on button click:

private void cmdSysInfo_Click( object sender, System.EventArgs e )
{
    string strSysInfo = string.Empty; 
    if( GetMsinfo32Path( ref strSysInfo ) )
        StartSysInfo( strSysInfo );
}

There is one more info tool on Windows NT 4.0 called WinMSD.exe - the descriptive name is Windows NT Diagnostics program. On Windows 2000 and XP platforms, the WinMSD tool has been replaced with MsInfo32.exe - so under Windows 2000/XP, WinMsd.exe is a stub executable file that starts Msinfo32.exe.

History

  • 24th January, 2002: Posted article
  • 5th February, 2002: Minor changes
  • 28th July, 2002: Improved code for MFC 7.0, added C# code and download
  • 4th August, 2002: Demo downloads fixed
  • 5th October, 2002: New downloads

License

This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.

A list of licenses authors might use can be found here.


Written By
Software Developer (Senior) SafeNet Inc
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralWindows x64 [modified] Pin
Titan Storm25-Oct-06 13:35
Titan Storm25-Oct-06 13:35 
GeneralIs there a way to retrive all the info to file Pin
cpp_prgmer13-Jan-06 3:10
cpp_prgmer13-Jan-06 3:10 
AnswerRe: Is there a way to retrive all the info to file Pin
Armen Hakobyan15-Jan-06 21:17
professionalArmen Hakobyan15-Jan-06 21:17 
JokeRe: Is there a way to retrive all the info to file Pin
robosport27-May-06 15:51
robosport27-May-06 15:51 
Generalmsinfo.exe have a problem Pin
Anonymous10-Sep-03 7:55
Anonymous10-Sep-03 7:55 
when I turned on my comp. today I had a message come up saying that I no longer have a msinfo.exe file
I was wondering if I could download it online or what Do I need to do
help please? email me at darkedge00@yahoo.com
thanks
GeneralRe: msinfo.exe have a problem Pin
kenneth starkman18-Dec-04 10:35
susskenneth starkman18-Dec-04 10:35 
Questionhow to get drive letters in hard disk? Pin
jessonel13-Apr-03 18:38
jessonel13-Apr-03 18:38 
QuestionDownload MFC demo project source code - 32 Kb is a HTML file? Pin
Zoltan1-Oct-02 4:09
Zoltan1-Oct-02 4:09 
AnswerRe: Download MFC demo project source code - 32 Kb is a HTML file? Pin
Armen Hakobyan2-Oct-02 11:31
professionalArmen Hakobyan2-Oct-02 11:31 
GeneralDemo downloads Pin
Earl Allen11-Aug-02 12:28
Earl Allen11-Aug-02 12:28 
GeneralMfc Source Code Link Doesn't Work Pin
Swinefeaster29-Jul-02 11:28
Swinefeaster29-Jul-02 11:28 
GeneralRe: Mfc Source Code Link Doesn't Work Pin
Armen Hakobyan29-Jul-02 16:27
professionalArmen Hakobyan29-Jul-02 16:27 
GeneralRe: Mfc Source Code Link Doesn't Work Pin
Swinefeaster29-Jul-02 17:13
Swinefeaster29-Jul-02 17:13 
GeneralRe: Mfc Source Code Link Doesn't Work Pin
Armen Hakobyan3-Aug-02 14:16
professionalArmen Hakobyan3-Aug-02 14:16 
GeneralRe: Mfc Source Code Link Doesn't Work Pin
Swinefeaster3-Aug-02 14:40
Swinefeaster3-Aug-02 14:40 
Generalwinmsd.exe Pin
25-Jan-02 0:24
suss25-Jan-02 0:24 
GeneralRe: winmsd.exe Pin
Armen Hakobyan25-Jan-02 2:01
professionalArmen Hakobyan25-Jan-02 2:01 
GeneralRe: winmsd.exe Pin
Eric Lapouge27-Jan-02 10:26
Eric Lapouge27-Jan-02 10:26 
GeneralRe: winmsd.exe Pin
Armen Hakobyan28-Jan-02 23:21
professionalArmen Hakobyan28-Jan-02 23:21 
GeneralRe: winmsd.exe Pin
Eric Lapouge29-Jan-02 6:40
Eric Lapouge29-Jan-02 6:40 
GeneralRe: winmsd.exe Pin
29-Jan-02 3:28
suss29-Jan-02 3:28 
GeneralRe: winmsd.exe - why is this even posted?!? Pin
burkazoid4-Feb-02 6:00
burkazoid4-Feb-02 6:00 
GeneralRe: winmsd.exe - why is this even posted?!? Pin
Matt Philmon5-Feb-02 19:38
Matt Philmon5-Feb-02 19:38 
GeneralRe: winmsd.exe Pin
Matt Philmon5-Feb-02 19:40
Matt Philmon5-Feb-02 19:40 
GeneralRe: winmsd.exe Pin
22-Feb-02 18:14
suss22-Feb-02 18:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.