Programming Assignment 2
CS 30200 / ECE 46810
Operating Systems
Spring, 2021

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

Write a console program that prompts the user with a list of the following five programs that come with Windows, notepad.exe, cmd.exe, nslookup.exe, charmap.exe, and wordpad.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 CreateProcessA() 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 two paragraphs for two exceptions). Your program should keep on letting the user launch programs until the user enters zero.

The program cmd.exe is 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, your 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 your launcher should prompt the user for another choice.

The program nslookup.exe is also special. Mark the nslookup.exe program in the menu with a # in front of its number. The nslookup.exe program is, like your launcher, a console application (that is, it's not a GUI program). For the nslookup.exe program, your launcher program should NOT create a new console window for nslookup.exe to run in. Your launcher should run nslookup.exe in your launcher's own console window. While the nslookup.exe program is running, it will share the console with your launcher. That means that your launcher needs to, once again, wait for nslookup.exe to terminate before it issues a new prompr to the user (otherwise, your lancher and nslookup.exe will fight with each other over the console window, and the fight will not end well). When nslookup.exe terminates, your launcher can immediately prompt the user for a new choice. You should terminate nslookup by using an "exit" command.

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. Write your program's user prompts so that they look exactly like the screen shot's 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 a command-line string that contains the value of an environment variable 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 Up:>". The console window should have light yellow letters on a red background. The console window should be positioned with its top left corner at the top left corner of your desktop.(Note: I am purposely not telling you exactly how to do these. You will need to use a combination of parameters to CreateProcessA(), entries in the STARTUPINFO data structure, and using the _putenv() function to set environment variables.) Your new console window should look like the launcher_demo_cmd.png screen shot in the zip file.

In the zip file there is an executable program called launcher_demo.exe that you can run to see how your launcher program should behave. An image file called launcher_demo.png shows you what a short session using the launcher program looks like.

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 CS302Hw2Surname.zip (where Surname is your last name) containing your version of launcher.c.

This assignment is due Monday, February 15.

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