ATL should already be doing all of this for you in the generated WinMain. To register an ATL server, run your program from a CMD box with "-Service" as the command line. ATL will take care of getting everything register with the SCM (Service Control Manager). To run the ATL project as a regular COM local server for debugging purposes, pass "-RegServer" on the command line. To unregister, pass "-UnRegServer"
This was first published in October 2001