I ejected an Audio-CD playing with Winamp by mistake and thought it would be nice to have the drive door locked automatically. So I wrote gen_autolock which has done a good job for me so far. GPL'd source is included. Download it from here: gen_autolock_20060321.zip .
Note: As I understood MSDN the function used to lock the drive door is not supported on Win9x.