If you make a hard reset then everything is restored, all changes in the registry are deleted.
So that is probably not the case. Maybe you have already opened COM1 in your code, but you just fail to see it right now? Maybe some other application has opened COM1?
There is no magic here, the error message you see is because some program, your own or some other has opened COM1. It is as simple as that.
Maybe ActiveSync has opened COM1 ?