Delphi Tips 
-----------------------------

0128  D1   D2   D3   D4   D5   D6   D7   3.1   95   98    作成: 1999/02/08 osamu rev 1.1
   B1   B3   B4   B5   B6   B7   NT3   NT4   2K   XP  更新: 1999/02/08 osamu 編集
実行終了後、自分自身(実行ファイル)を削除したい

> 実行終了後、自分自身を削除したいのですが、
> なにか良い方法はありませんか?

こんなのはどうでしょう?
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で自分自身を消去するのは確認済みです。
参照: [Delphi-ML:22795] <Windows>

[新規作成] [最新の情報に更新]

How To
Lounge
KeyWords


Tips
Delphi
Home
Osamu Takeuchi osamu@big.or.jp