|
#1
|
|||
|
|||
|
This is less of a BAT file question, more of an OS question I think....
BAT files can delete themselves. This is really handy to clean up after execution. To test this works is simple enough: C:\test_dir>echo del runme.bat > runme.bat C:\test_dir>type runme.bat del runme.bat C:\test_dir>runme.bat C:\test_dir>del runme.bat The batch file cannot be found. <<< this is OK C:\test_dir>type runme.bat The system cannot find the file specified. C:\test_dir> On a recent Windows XP box that I came across in a company, the above doesn't work! Explorer.EXE "locks" the BAT file and the file doesn't delete. If you try manually deleting, even through Windows GUI, the error is "Access is denied". If you kill explorer.exe, the file suddenly disappears (same for a reboot). The strange thing is this "standard operating environment" of Windows XP used to work fine for bat files to self-delete. The only change as far as I can tell is that the new XP box used sysprep to get built (which changes reg settings I think). Is there any reg keys / system settings that could possibly stop bat files from self-deleting?? |
|
#2
|
|||
|
|||
|
If, for some reason, the "read-only" attribute of the bat file were set,
then that would stop it from self-deleting, giving the "Access is denied" message. Using "del /f runme.bat" would be one way round that, if that were the case. Jon "cwp" <chungwangpong@yahoo.com.au> wrote in message news:1136413546.419107.269130@g43g2000cwa.googlegr oups.com... > This is less of a BAT file question, more of an OS question I think.... > > BAT files can delete themselves. This is really handy to clean up > after execution. To test this works is simple enough: > > C:\test_dir>echo del runme.bat > runme.bat > > C:\test_dir>type runme.bat > del runme.bat > > C:\test_dir>runme.bat > > C:\test_dir>del runme.bat > The batch file cannot be found. <<< this is OK > > C:\test_dir>type runme.bat > The system cannot find the file specified. > > C:\test_dir> > > On a recent Windows XP box that I came across in a company, the above > doesn't work! Explorer.EXE "locks" the BAT file and the file doesn't > delete. If you try manually deleting, even through Windows GUI, the > error is "Access is denied". If you kill explorer.exe, the file > suddenly disappears (same for a reboot). > > The strange thing is this "standard operating environment" of Windows > XP used to work fine for bat files to self-delete. The only change as > far as I can tell is that the new XP box used sysprep to get built > (which changes reg settings I think). > > Is there any reg keys / system settings that could possibly stop bat > files from self-deleting?? > |
|
#3
|
|||
|
|||
|
"cwp" <chungwangpong@yahoo.com.au> wrote in message news:1136413546.419107.269130@g43g2000cwa.googlegr oups.com... > This is less of a BAT file question, more of an OS question I think.... > > BAT files can delete themselves. This is really handy to clean up > after execution. To test this works is simple enough: > > C:\test_dir>echo del runme.bat > runme.bat > > C:\test_dir>type runme.bat > del runme.bat > > C:\test_dir>runme.bat > > C:\test_dir>del runme.bat > The batch file cannot be found. <<< this is OK > > C:\test_dir>type runme.bat > The system cannot find the file specified. > > C:\test_dir> > > On a recent Windows XP box that I came across in a company, the above > doesn't work! Explorer.EXE "locks" the BAT file and the file doesn't > delete. If you try manually deleting, even through Windows GUI, the > error is "Access is denied". If you kill explorer.exe, the file > suddenly disappears (same for a reboot). > > The strange thing is this "standard operating environment" of Windows > XP used to work fine for bat files to self-delete. The only change as > far as I can tell is that the new XP box used sysprep to get built > (which changes reg settings I think). > > Is there any reg keys / system settings that could possibly stop bat > files from self-deleting?? Deleting a batch file while it is executing is not "nice". It is equivalent to sawing off the branch you're sitting on. A more elegant way goes like this. It should work in all environments. runme.bat ======= @echo off .. . . some useful lines start /b cmd /c del runme.bat |
|
#4
|
|||
|
|||
|
On 4 Jan 2006 14:25:46 -0800, cwp wrote:
> This is less of a BAT file question, more of an OS question I think.... > > BAT files can delete themselves. This is really handy to clean up > after execution. To test this works is simple enough: > > C:\test_dir>echo del runme.bat > runme.bat > > C:\test_dir>type runme.bat > del runme.bat > > C:\test_dir>runme.bat > > C:\test_dir>del runme.bat > The batch file cannot be found. <<< this is OK > > C:\test_dir>type runme.bat > The system cannot find the file specified. > > C:\test_dir> > > On a recent Windows XP box that I came across in a company, the above > doesn't work! Explorer.EXE "locks" the BAT file and the file doesn't > delete. If you try manually deleting, even through Windows GUI, the > error is "Access is denied". If you kill explorer.exe, the file > suddenly disappears (same for a reboot). Refresh the explorer view. The file will be gone. |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Keeping backup of my pictures in my order | Gladys222 | Windows XP Photos | 10 | 01-05-2006 07:08 AM |
| Files and Settings Transfer Wizard - Is Batch Possible? | Jim | Windows XP Setup Deployment | 3 | 01-05-2006 06:25 AM |
| Permanently deleting files in the C:\Recycler folder | flyhigh182 | Windows XP Security Admin | 8 | 01-05-2006 04:21 AM |
| deleting files created by files and settings transfer wizard | Ted Curtin | Windows XP New Users | 1 | 01-05-2006 02:53 AM |
| Batch file to delete old backup | Anders Hellstrom | Windows XP General | 3 | 01-05-2006 02:35 AM |