You may have a look at the article
Self Deleting Executables [
^]. This uses C++ but explains why deleting is difficult.
Another option would be to let the application that is installed by the setup program delete the setup file upon its first run. But this requires that the application knows where to find the file and that it has sufficuient rights to delete the file.
The file location can be stored in the registry at
HKLM
(maybe your setup program already stores some data there in the Software tree). But the registry entry can't be deleted when your application runs with user privileges. So the registry entry may stay there (it can be finally deleted by an uninstall).
You may have noticed that some applications require that they are executed with administrator privileges when started the first time after installation. This is usually done to write some registry entries in the
HKLM
tree and/or do the clean up for the setup. You may also use such requirements, but it's not user friendly.