Click here to Skip to main content
12,632,959 members (33,215 online)
Click here to Skip to main content
Add your own
alternative version

Stats

168.3K views
3.3K downloads
23 bookmarked
Posted

How to start the Microsoft System Information dialog

, 4 Oct 2002
Rate this:
Please Sign up or sign in to vote.
This article describes how to start Microsoft System Information programatically 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:

// 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:

//...

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:

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

// 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:

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

  • 24-Jan-2002 Posted the article.
  • 05-Feb-2002 Minor changes.
  • 28-Jul-2002 Improved code for MFC 7.0, added C# code and download.
  • 4-Aug-2002 Demo downloads fixed.
  • 5 Oct 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

Share

About the Author

Armen Hakobyan
Software Developer (Senior) SafeNet Inc
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralWindows x64 [modified] Pin
Titan Storm25-Oct-06 14:35
memberTitan Storm25-Oct-06 14:35 
GeneralIs there a way to retrive all the info to file Pin
cpp_prgmer13-Jan-06 4:10
membercpp_prgmer13-Jan-06 4:10 
AnswerRe: Is there a way to retrive all the info to file Pin
Armen Hakobyan15-Jan-06 22:17
memberArmen Hakobyan15-Jan-06 22:17 
JokeRe: Is there a way to retrive all the info to file Pin
robosport27-May-06 16:51
memberrobosport27-May-06 16:51 
Generalmsinfo.exe have a problem Pin
Anonymous10-Sep-03 8:55
sussAnonymous10-Sep-03 8:55 
GeneralRe: msinfo.exe have a problem Pin
kenneth starkman18-Dec-04 11:35
susskenneth starkman18-Dec-04 11:35 
Questionhow to get drive letters in hard disk? Pin
jessonel13-Apr-03 19:38
memberjessonel13-Apr-03 19:38 
QuestionDownload MFC demo project source code - 32 Kb is a HTML file? Pin
Zoltan1-Oct-02 5:09
memberZoltan1-Oct-02 5:09 
AnswerRe: Download MFC demo project source code - 32 Kb is a HTML file? Pin
Armen Hakobyan2-Oct-02 12:31
memberArmen Hakobyan2-Oct-02 12:31 
GeneralDemo downloads Pin
Earl Allen11-Aug-02 13:28
memberEarl Allen11-Aug-02 13:28 
GeneralMfc Source Code Link Doesn't Work Pin
Swinefeaster29-Jul-02 12:28
memberSwinefeaster29-Jul-02 12:28 
GeneralRe: Mfc Source Code Link Doesn't Work Pin
Armen Hakobyan29-Jul-02 17:27
memberArmen Hakobyan29-Jul-02 17:27 
GeneralRe: Mfc Source Code Link Doesn't Work Pin
Swinefeaster29-Jul-02 18:13
memberSwinefeaster29-Jul-02 18:13 
GeneralRe: Mfc Source Code Link Doesn't Work Pin
Armen Hakobyan3-Aug-02 15:16
memberArmen Hakobyan3-Aug-02 15:16 
GeneralRe: Mfc Source Code Link Doesn't Work Pin
Swinefeaster3-Aug-02 15:40
memberSwinefeaster3-Aug-02 15:40 
Generalwinmsd.exe Pin
adara25-Jan-02 1:24
memberadara25-Jan-02 1:24 
GeneralRe: winmsd.exe Pin
Armen Hakobyan25-Jan-02 3:01
memberArmen Hakobyan25-Jan-02 3:01 
GeneralRe: winmsd.exe Pin
Eric Lapouge27-Jan-02 11:26
memberEric Lapouge27-Jan-02 11:26 
GeneralRe: winmsd.exe Pin
Armen Hakobyan29-Jan-02 0:21
memberArmen Hakobyan29-Jan-02 0:21 
GeneralRe: winmsd.exe Pin
Eric Lapouge29-Jan-02 7:40
memberEric Lapouge29-Jan-02 7:40 
GeneralRe: winmsd.exe Pin
adara29-Jan-02 4:28
memberadara29-Jan-02 4:28 
GeneralRe: winmsd.exe - why is this even posted?!? Pin
burkazoid4-Feb-02 7:00
memberburkazoid4-Feb-02 7:00 
GeneralRe: winmsd.exe - why is this even posted?!? Pin
Matt Philmon5-Feb-02 20:38
memberMatt Philmon5-Feb-02 20:38 
GeneralRe: winmsd.exe Pin
Matt Philmon5-Feb-02 20:40
memberMatt Philmon5-Feb-02 20:40 
GeneralRe: winmsd.exe Pin
Mike Lamb22-Feb-02 19:14
memberMike Lamb22-Feb-02 19: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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161208.2 | Last Updated 5 Oct 2002
Article Copyright 2002 by Armen Hakobyan
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid