You are doing this all wrong. When you create a handle, remember it. When you are done with it, close it.
You cannot hope to be able to enumerate all open handles in your process and close a bunch of them that meet some criteria. You have no way of knowing whether or not the handle is in use. There will be handles open in your process that were not opened by your code. Closing such handles will lead to all sorts of pain.