Jump to content

Recommended Posts


Posted

Okay, slept well and thought about your request, it's a bit of a programming challenge, but I managed to work the delete on next reboot for files out :rolleyes:

DeleteFileonReboot.reg

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\Delete on reboot\command]
@="delfile.cmd \"%1\""

[HKEY_CLASSES_ROOT\*\shell\Open]

delfile.cmd

@echo off
setlocal
set pathwithquotes=%1
set originalpath=%pathwithquotes:~1,-1%
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Currentversion\RunOnce /v "Del %originalpath% OnNextReboot" /d "cmd.exe /c DEL /F /Q \"%originalpath%\"" /f
endlocal

delfile.cmd goes into windir or system32

[HKEY_CLASSES_ROOT\*\shell\Open] is for security, without it "Delete on Reboot" becomes the default action on all unknown files, ( no, that's not what you want :wacko: ).

Also fixed the code for the deletefolderonreboot tweak. It's faster. BTW, it won't work with special characters as % or & in filenames yet

Posted

I stumbled with this one so it handles even filenames with special characters in it, not an easy task, because the batch instruction set is not very well documented:

DeleteFileonReboot.reg

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\Delete on reboot\command]
@="delfile.cmd \"%1\""

[HKEY_CLASSES_ROOT\*\shell\Open]

delfile.cmd

@echo off
setlocal disableextensions
set pathwithquotes=%1
setlocal enableextensions
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Currentversion\RunOnce /v "Del %pathwithquotes:~1,-1% OnNextReboot" /d ^"cmd.exe /c DEL /F /Q \"%pathwithquotes:~1,-1%\"^" /f
endlocal

--------------------------------------------------------------------------

DeleteFolderonReboot.reg

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Folder\shell\Delete on reboot\command]
@="delfile.cmd \"%1\""

delfolder.cmd

@echo off
setlocal disableextensions
set pathwithquotes=%1
setlocal enableextensions
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Currentversion\RunOnce /v "Del %pathwithquotes:~1,-1% OnNextReboot" /d ^"cmd.exe /c RD /S /Q \"%pathwithquotes:~1,-1%\"^" /f
endlocal

It's nearly the same. In fact, only difference is the command you type in the prompt :lol:

Posted

Sixpack, look this:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\Delete on reboot\command]
@="CMD /E:OFF /C REG ADD HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\Currentversion\\RunOnce /v \"Del %1 OnNextReboot\" /d ^\"cmd.exe /c DEL /F /Q \\\"%1\\\"\" /f\""

[HKEY_CLASSES_ROOT\*\shell\Open]

[HKEY_CLASSES_ROOT\Folder\shell\Delete on reboot\command]
@="CMD /E:OFF /C REG ADD HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\Currentversion\\RunOnce /v \"Del %1 OnNextReboot\" /d ^\"cmd.exe /c RD /S /Q \\\"%1\\\"\" /f\""

No more need for cmd files on hd.

This works on all files, even at those with special characters. Only exception for files and folders with %var% in it.

Posted

:w00t:

going to try it tomorrow

i did experiment with context menu dll's [got nice one's] so the registery is a little f***t up

so i'll install windows and test it

:P

Posted
my guess is it cant be done

or there must be a dll someware that can do all this

but give up, NEVER

:lol:

P.S %var% as in SET VAR=var:

Examples:

%systemdrive%

%systemroot%

%windir%

%programfiles%

%temp%

%path%

For a full list type SET in a command prompt.

  • 2 weeks later...
Posted

Cool, this looks amazing :D

Your making a file that when opend, the next time you reboot it deletes the specifid file yeah, when would the file specified be deleted? before or after your OS starts loading?

Thanks you ;)

Posted

The files get removed when a user logs on to the system. So no critical Windows sytem files will get removed, but you can get rid of some files that are in use by some programs or the windows system

  • 6 years later...
Posted (edited)

I know this is an old post........but people do say 'use the search'

I need to delete the temp folder on 'next reboot' through a CMD my install runs, i need to this because i need to clean the temp folder after my install.

This works but as we know the temp folder are different from XP to Win7.

@echo off
setlocal disableextensions
set pathwithquotes=%1
setlocal enableextensions
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Currentversion\RunOnce /v "Del %"C:\Documents and Settings\???\Local Settings\Temp":~1,-1% OnNextReboot" /d ^"cmd.exe /c RD /S /Q \"%"C:\Documents and Settings\???\Local Settings\Temp":~1,-1%\"^" /f
endlocal

So i try using the %TEMP% option so i will delete on both but it doesn't work

@echo off
setlocal disableextensions
set pathwithquotes=%1
setlocal enableextensions
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Currentversion\RunOnce /v "Del %"%TEMP%":~1,-1% OnNextReboot" /d ^"cmd.exe /c RD /S /Q \"%"%TEMP%":~1,-1%\"^" /f
endlocal

Can anyone help?

EDIT- Sorted now.

REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Currentversion\RunOnce /v NextReboot /d "cmd.exe /c RD /S /Q %TEMP%"

Cheers, James

Edited by jamesbebby
Posted

@ jamesbebby

There is no need to ever delete the %TEMP% directory, what you should be doing, although it shouldn't be necessary since your installer(s) should do it, is deleting specific files and /or folders within the %TEMP% location.

Posted (edited)

Whats the command to delete all files & folders in the temp folder??? And not the temp folder itself.

EDIT- I believe this is how people do it

REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Currentversion\RunOnce /v NextReboot /d "cmd.exe /c RD /S /Q %TEMP%"
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Currentversion\RunOnce /v NextReboot /d "cmd.exe /c MD /S /Q %TEMP%"

Cheers, James

Edited by jamesbebby
Posted

There are some files and directories placed inside the Temp location for use by other some processes, they are not what you want to delete, so why do it?

Your installers should remove their own temporary files as part of the installation routine. If they do not then the most responsible idea would be to remove all files and directories which have been added only by that routine. For that you would need to do either a before and after compare or ensure that the installation files are all placed within a unique directory which can then be deleted after installation without affecting others. You will then likely find that you will not be deleting any in use files since the ones you need to remove are not in use and they can be deleted with a simple command without rebooting.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...