Roger L. Kraft

CS 30200/ECE 46810 - Programming Assignment 1

For this assignment you will write a "launcher" program that creates Windows processes. This assignment makes use of files contained in this zip file. This assignment is due Monday, January 25.

Write a console program that prompts the user with a list of the following five programs that come with every copy of Windows, notepad.exe, wordpad.exe, cmd.exe, calc.exe, and explorer.exe. Have the five programs numbered in the list from 1 to 5. Have the user choose one of the five programs by inputting a number between 1 and 5. Then your program should use the Windows function CreateProcess() to start up the program that the user chose. After the process has been created, output a message that states the PID of the newly created process. After your program launches the user's choice, your program should once again prompt the user with the list of available programs and let the user launch another program (but see the next paragraph for an exception). Your program should keep on letting the user launch programs until the user enters zero.

One of the five programs should be special. Mark the cmd.exe program in the menu with a * in front of its number. For the cmd.exe program, your launcher program should wait for the launched cmd.exe process to terminate. In other words, the launcher blocks after it launches the cmd.exe process and the launcher waits (i.e., remains blocked) until the cmd.exe process terminates. When cmd.exe terminates, your program should look up the cmd.exe exit value and output a message that states the exit value. Then the launcher should prompt the user for another choice.

In the zip file there is an image file, launcher_demo.png, that shows a screen shot of a user session with the launcher.exe program. Use this screen shot to help you write your program's user prompts.

Here are a few additional requirements of your launcher. Your launcher program should use standard Windows environment variables to create command lines for the above five programs in a way that is independent of any particular Windows installation. For example, some versions of Windows have a C:\Windows system directory and some have a C:\WINNT system directory. Some people have a C:\Program Files directory while others might have a D:\Program Files directory. Your program should work independently of these kinds of choices. Relevant environment variables are, for example, ComSpec, SystemDrive, SystemRoot, ProgramFiles, HomeDrive, windir. Below are two references that list a number of standard Windows environment variables.

The best way to create command-line strings that contain the values of environment variables is to combine the getenv() function with the sprintf() function.

When your program launches the cmd.exe program, it should give the new console window the title "What is your command?". The console prompt should be "Speak to me>". The console window should have light blue letters on a bright white background. (Note: I am purposely not telling you how to do these.) See the launcher_demo_cmd.png screen shot in the zip file.

Your program should print out reasonable error messages when something goes wrong (e.g., file not found). Use the error message function included in the example programs from the class lectures.

Turn in a zip file called CS302Hw1Surname.zip (where Surname is your last name) containing your C program launcher.c.

This assignment is due Monday, January 25.

Here are references to the relevant functions in the Windows API.