実行終了後、自分自身(実行ファイル)を削除したい
|
> 実行終了後、自分自身を削除したいのですが、
> なにか良い方法はありませんか?
こんなのはどうでしょう?
MoveFileEx(lpszExisting,NULL,MOVEFILE_DELAY_UNTIL_REBOOT);
NTではこれで再起動時に削除されます。
Windows95 ではこのAPIはサポートされないので
以下の方法をとるように、MoveFileEx のヘルプで示されています。
Windows 95: The MoveFileEx function is not supported on Windows 95.
To rename or delete a file at reboot on a Windows 95 system, use the following procedure.
・To Rename or Delete a File on Windows 95
Check for the existence of the WININIT.INI file in the Windows directory. If WININIT.INI exists, open it and add new entries to the existing [rename] section. If the file does not exist, create the file and create a [rename] section. Add lines of the following format to the [rename] section:
DestinationFileName=SourceFileName
Both DestinationFileName and SourceFileName must be short filenames. To delete a file, use NUL as the value for DestinationFileName.
The system processes WININIT.INI during system boot. After WININIT.INI has been processed, the system names it WININIT.BAK.
ちなみに、いずれも再起動が必要です。また私自身は、Windows95 で上記の方法は試したことがありませんが、WindowsNTで自分自身を消去するのは確認済みです。 |
|