Delete file on next startup

Just starting out? Need help? Post your questions and find answers here.
abc123
Enthusiast
Enthusiast
Posts: 195
Joined: Wed Apr 18, 2007 9:27 pm

Delete file on next startup

Post by abc123 »

This i searched and had no luck! Keywords: Delete on Startup, File on Startup...

How do i get a file to be delete in the temp folder on the next startup/login?
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Write a little commandline tool, specify the filename and put it in the autostart folder. You can also edit the registry: "Run" & "Run Once"
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Did you try the manual?

Deletefile, Deletedirectory?

cheers
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

rsts wrote:Did you try the manual?

Deletefile, Deletedirectory?

cheers
Did you read the question?
eJan
Enthusiast
Enthusiast
Posts: 366
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Post by eJan »

@abc123 look here: http://www.purebasic.fr/english/viewtopic.php?t=20184

Code: Select all

For current user use Registry Key: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce
For all users use: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce
This is exported Registry when Kaspersky starts with Windows:

Code: Select all

 Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
"AVP"="\"C:\\Program Files\\Kaspersky Lab\\Kaspersky Internet Security 7.0\\avp.exe\""
Edit:
Thanks iNX, i have found something:

Code: Select all

; MSDN: http://msdn2.microsoft.com/en-us/library/aa365240(VS.85).aspx
; MSDN: http://support.microsoft.com/kb/140570

; Move szSrcFile To szDstFile Next time system is rebooted
; MoveFileEx(szSrcFile, szDstFile, MOVEFILE_DELAY_UNTIL_REBOOT);
;
; Delete szSrcFile Next time system is rebooted
; MoveFileEx(szSrcFile, NULL, MOVEFILE_DELAY_UNTIL_REBOOT)

; [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager]
; "PendingFileRenameOperations"=

Procedure ReplaceFile(sSourceFile.s, sDestFile.s)
  ;SetFileAttributes_(sSourceFile, #FILE_ATTRIBUTE_NORMAL)
  MoveFileEx_(sDestFile, #Null, #MOVEFILE_DELAY_UNTIL_REBOOT);
  MoveFileEx_(sSourceFile, sDestFile, #MOVEFILE_DELAY_UNTIL_REBOOT)
  ProcedureReturn 1
EndProcedure

ReplaceFile(sSourceFile.s, sDestFile.s)
Use:

Code: Select all

MoveFileEx_(sDestFile, #Null, #MOVEFILE_DELAY_UNTIL_REBOOT)
Last edited by eJan on Sat Apr 26, 2008 6:13 pm, edited 1 time in total.
User avatar
bingo
Enthusiast
Enthusiast
Posts: 210
Joined: Fri Apr 02, 2004 12:21 pm
Location: germany/thueringen
Contact:

Post by bingo »

for vista !

use:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce

* no admin required (no uac-prompt !)

cmd.exe /c rd /s /q c:\your_folder

or

cmd.exe /c del /f c:\your_file.xxx

simple , but efficient 8)
["1:0>1"]
iNX
User
User
Posts: 27
Joined: Wed Jan 24, 2007 12:15 pm

Post by iNX »

if you're familiar with windows API, you could use moveFileEx that does exactly what you need, with a single call.

Code: Select all

BOOL MoveFileEx(
  LPCTSTR lpExistingFileName,
  LPCTSTR lpNewFileName,
  DWORD dwFlags
);

If dwFlags specifies MOVEFILE_DELAY_UNTIL_REBOOT and lpNewFileName is NULL, MoveFileEx registers the lpExistingFileName file to be deleted when the system restarts. If lpExistingFileName refers to a directory, the system removes the directory at restart only if the directory is empty.

Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

That's great, iNX. I never knew you could do that. :)
Post Reply