Demonstrates how to deal with files that are locked/in use. See the DelLater homepage for the compiled executable and more information.
;#################################
;# DelLater v1.0 #
;# For Win 95/98/ME/2K/XP/2003 #
;# Copyright (C) 2003, DiamondCS #
;# http://www.diamondcs.com.au #
;# Donated to the public domain. #
;#################################
.386
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
.data
sTitle db 'DelLater',0
sError db 'Unable to mark this file for deletion',0
sMoved db 'File marked for deletion after reboot',0
sExist db 'File not found',0
sText db 'Usage: dellater.exe <filename>',0
sWininit db '\wininit.ini',0
sGroup db 'rename',0
sNull db 'NUL',0
sWindir db 270 dup(0)
wfd WIN32_FIND_DATA <?>
osvi OSVERSIONINFO <>
.code
_entrypoint:
call GetCommandLineA
;## Process the cmdline
cmp byte ptr [eax], 22h
je paramNext2
paramNext1:
inc eax
cmp byte ptr [eax], 20h
je paramLast
cmp byte ptr [eax], 0
je NoParams
jmp paramNext1
paramNext2:
inc eax
cmp byte ptr [eax], 22h
je EndParams
jmp paramNext2
EndParams:
inc eax
paramLast:
cmp byte ptr [eax], 0
je NoParams
inc eax
cmp byte ptr [eax], 0
je NoParams
;## Parameters found, check if file exists
push eax ;preserve eax
push offset wfd
push eax
call FindFirstFile
cmp eax, INVALID_HANDLE_VALUE
jne MarkFile
pop eax
push 10h
push offset sExist
push eax
push 0h
call MessageBoxA
jmp CodeEnd
MarkFile:
;## Check OS version
mov osvi.dwOSVersionInfoSize, 148
push offset osvi
call GetVersionEx
cmp dword ptr [osvi.dwPlatformId], VER_PLATFORM_WIN32_NT
je WinNT
cmp dword ptr [osvi.dwMajorVersion], 4
jne WinNT
Win9x:
;## Win95/98/ME method
push 270
push offset sWindir
call GetWindowsDirectory
push offset sWininit
push offset sWindir
call lstrcat
pop eax
push eax
push 260
push eax
push eax
call GetShortPathName
pop eax
push eax
push offset sWindir
push eax
push offset sNull
push offset sGroup
call WritePrivateProfileString
cmp eax, 0
je Failed
jmp Success
;## WinNT/2K/XP/2003 method
WinNT:
pop eax
push eax ;preserve eax
push MOVEFILE_DELAY_UNTIL_REBOOT
push NULL
push eax ;Filename
call MoveFileEx
cmp eax, 0
je Failed
Success:
pop eax
push 40h
push offset sMoved
push eax
push 0h
call MessageBoxA
jmp CodeEnd
Failed:
pop eax
push 10h
push offset sError
push eax
push 0h
call MessageBoxA
jmp CodeEnd
;## No parameters specified, display usage info
NoParams:
push 40h
push offset sTitle
push offset sText
push 0h
call MessageBoxA
CodeEnd:
invoke ExitProcess, 0
end _entrypoint
;## The End
Related websites:
DiamondCS: DelLater
MSDN: MoveFileEx
How to determine file ownership
Copyright © 2008, Diamond Computer Systems Pty. Ltd. All rights reserved.