( Index )
Month

Brief Information about the March '06 CSIG Meeting

Programs Utility - Browser View

VC++ 6 and C# 2005 Express Discussion

B. Arnold

Programs List

Welcome to the CSIG, a Special Interest Group of the ACGNJ. The subject for this month is a discussion about the MFC Non-Windows Programming using Microsoft Visual C++ version 6.0. By "Non-Windows or Non-GUI" I mean a program that uses the Command Box (Sometimes called DOS Box) instead of the Windows Graphical Interface. This is the simplist of programming ventures because the Graphical User Interface, GUI, does not have to be programmed.

There will also be a discussion on C# 2005 Express Edition. Since this compiler is FREE from Microsoft it is quickly becoming a very popular application. I have converted most of tonight's VC6 code into C-Sharp code so that the differences may be compared.

The program presented is designed provide a list of installed programs. You may remember that a similar program was presented in 2004. This one uses some of the code from the original but adds a number of features. In particular, it automatically launches a browser to display the results in HTML code. Another major improvement is that is displays detail information about the computer in the title of the page. As shown above, this information includes the Operating System and the version.

Here's a typical situation: When you go to Control Panel, Add-Remove Programs, you will see a list of installed programs. How do you get a hard copy? Why do you need it? Here are several reasons that I use: a) If you are about to reinstall your operating system from scratch because of a bad virus, crash, upgrade, etc., you would like to have a complete list of your installed programs so that you can reinstall each of them. b) I have a computer with several plug in hard drives. I often have to "power down, remove drive, insert drive, reboot, check, repeat" in order to find an application. A hard copy would solve this problem.

The program helps solve the problem by looking in the Registry and listing all of the installed programs.

The beginning of the evening (starting at 7:30pm) will be a RANDOM ACCESS discussion. The main presentation will present the program.

As always, the download site has code and programs from our meetings. ( Source Code Files )

Sample Code - VC6

Sample Code
/////////////////////////////////////////////////////////////////////////////
// The main entry point of this MFC program.

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
    {
    int nRetCode = 0;       char buff[_MAX_PATH];   unsigned long buffsize;
    FILE *fs; char tempPath[_MAX_PATH];

    // initialize MFC and print and error on failure
    if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
        {
        // TODO: change error code to suit your needs
        fprintf(stderr, "Fatal Error: MFC initialization failed\n");
        nRetCode = 1;
        }
    else
        {
        // TODO: code your application's behavior here.
        //CString strHello;
        //strHello.LoadString(IDS_HELLO);
        //cout << (LPCTSTR)strHello << endl;

        fprintf(stderr, "%s\n",   VERSION);
        fprintf(stderr, "%s\n\n", VERSIONUL);
        fprintf(stderr, "    THE  BROWSER  WINDOW  WILL  LAUNCH  SHORTLY\n");

        CString target, *prgstr;

        m_Category.RemoveAll();
        Categories(WINXPSTARTPATH);     // Fill m_Category array

        for (int i=0;i < m_Category.GetSize();i++)
            {
            char *p;    CString sCompany, sLinebuff;
            target = WINXPSTARTPATH;
            target += "\\";
            target += m_Category[i];
            p = GetDisplayName(target.GetBuffer(150), "UninstallString");
            if (p)
                {
                sCompany = GetDisplayName(target.GetBuffer(150), "Publisher");
                p = GetDisplayName(target.GetBuffer(150), "DisplayName");
                if (p)
                    {
                    if (sCompany.GetLength() <= COMPANYWIDTH)
                        sLinebuff.Format("%-*.*s%s   %s", 
                            COMPANYWIDTH,
                            COMPANYWIDTH,
                            sCompany.GetBuffer(50),
                            "",
                            p);
                    else
                        sLinebuff.Format("%-*.*s%s   %s", 
                            COMPANYWIDTH-3,
                            COMPANYWIDTH-3,
                            sCompany.GetBuffer(50),
                            "...",
                            p);
                    m_Program.Add(sLinebuff.GetBuffer(150));
                    }
                }
            }

        GetTempPath(_MAX_PATH, tempPath);
        strcat(tempPath, "Programs.htm");
		....

Sample Code - C# C-Sharp Express

/* ************************************************************************
Programs.cs by Bruce Arnold ............ March 21, 2006

Object:  to list the installed applications in a Windows computer.

Algorithm:  the program accesses the "uninstall" section of the registry and
            collects all of the "Display Name" values.  The Company name is also listed.
            Output is now HTML and automatically launches the browser.
            Most duplicate names have been eliminated by checking uninstall string.

Note:  this has been converted to C-sharp Express from the original C++ VC 6.0 code.

***************************************************************************** */

using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;


namespace Programs
{
    class Programs
    {
        static void Main(string[] args)
        {
            Categories();
        }

        static int Categories()      {
            RegistryKey winXPstartpath = Registry.LocalMachine.OpenSubKey(
                "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall");

            string tempPath = System.IO.Path.GetTempPath();
            tempPath += "Programs.htm";

            using (StreamWriter sw = File.CreateText(tempPath))
            {
                sw.WriteLine("<HTML>");
                sw.WriteLine("<HEAD>");
                sw.WriteLine("<TITLE>Programs.exe Version 1.20 by B. Arnold</TITLE>");
                sw.WriteLine("</HEAD>");
                sw.WriteLine("<BODY>");

                // Note:  for ComputerName add "System.Windows.Forms"
                //                          to "References" in Solution Explorer.
                sw.WriteLine("<H1 ALIGN=center>Computer - {0} </H1>", 
                    System.Windows.Forms.SystemInformation.ComputerName.ToString());

                sw.WriteLine("<H3 ALIGN=center>{0}</H3>", Environment.OSVersion.ToString());
                if (5 == System.Environment.OSVersion.Version.Major)
                {
                    if (0 == System.Environment.OSVersion.Version.Minor)
                        sw.WriteLine("<H3 ALIGN=center>( {0} )</H3>", "Windows 2000");
                    else if (1 == System.Environment.OSVersion.Version.Minor)
                        sw.WriteLine("<H3 ALIGN=center>( {0} )</H3>", "Windows XP");
                }
...........

"Random Access" questions start at 7:30 Tuesday night.

SOURCE CODE

Source Code Files

For help, email me at b a r n o l d @ i e e e . o r g
Back to C++ Main Page