How does one detect if a certian application is opened, and how do you close it from VB?

I have an ExitWindowsEx procedure that shuts the computer down at a certian time (closing time ). When the computer is rebooted, the "Windows was shut down improperly" comes up, and scandisk runs. How do I "shut down properly" to prevent this?