Question: I have a desire to write a Win32 executable (in C++) that performs all of its COM registration at startup so that its object(s) are then accessible via COM to client apps. When the executable terminates, it should then deregister with COM.
Is this kind of thing possible and if so, what are the steps involved?
I have been googling feverishly all afternoon without really finding any answers to this. Most solutions require up front registration (e.g. via a /register switch).
Thanks

Answer: 
I suspect that [CoRegisterClassObject](http://msdn.microsoft.com/en-us/library/windows/desktop/ms693407%28v=vs.85%29.aspx) and [CoRevokeClassObject](http://msdn.microsoft.com/en-us/library/windows/desktop/ms688650%28v=vs.85%29.aspx) are the functions you are looking for. You can find more information [here](http://msdn.microsoft.com/en-us/library/windows/desktop/ms680076%28v=vs.85%29.aspx).
There is no magic in the COM server registering regardless of in-proc or out-of-proc. Registering means writing to the registry deregistering means deleting registry keys.

Usual EXE COM server read command line arguments to handle install/uninstall request and provide separate subroutines or execution paths but you can freely include the install/uninstall process in every execution.

```
WinMain()
{
  Install()
  CoRegisterClassObject();
  .. Message Loop ..
  CoRevoveClassOBject();
  Uninstall();
}

```