Opened 8 years ago

Closed 6 years ago

#3243 closed Bug (Fixed)

_WinAPI_MoveFileEx(...$sNewFile = "" for delete not 0

Reported by: christian.blackburn@… Owned by: Jpm
Milestone: Component: AutoIt
Version: Severity: None
Keywords: Cc:


_WinAPI_MoveFileEx(...$sNewFile = "" for delete not 0

The documentation for _WinAPI_MoveFileEx ( is incorrect. If you want to delete a file it won't work with a 0, you have to use an empty string (""). I found this out the hard way today using SysInternals PendMoves ( for troubleshooting. For the record, I strongly prefer the empty string as the correct syntax. That being said, I think some exception code should be added for legacy support to allow "", 0.

_WinAPI_MoveFileEx("C:\Windows\SysWOW64\drivers\SBREDrv.sys", 0, $MOVE_FILE_DELAY_UNTIL_REBOOT)

_WinAPI_MoveFileEx("C:\Windows\SysWOW64\drivers\SBREDrv.sys", "", $MOVE_FILE_DELAY_UNTIL_REBOOT)

PendMove v1.2
Copyright (C) 2004-2013 Mark Russinovich
Sysinternals -

Source: C:\Windows\SysWOW64\drivers\SBREDrv.sys
Target: UNC\tufileserver4\software$\AdminTools\Removal Tools\VIPRE\0

Source: C:\Windows\SysWOW64\drivers\SBREDrv.sys
Target: C:\temp\0

Source: C:\Windows\SysWOW64\drivers\SBREDrv.sys
Target: DELETE

Christian Blackburn
Fast and Friendly Computer Repair
Cell: 916-978-1Fix (1349), Fax:266-0821

Attachments (0)

Change History (4)

comment:1 Changed 8 years ago by christian.blackburn@…

I thought I should clarify the following. The first result is when I ran my compiled code off an SMB network share:
Target: UNC\tufileserver4\software$\AdminTools\Removal Tools\VIPRE\0

This is after I ran it from C:\Temp\
Target: C:\temp\0

And this is when I figured out that 2nd _WinAPI_MoveFileEx parameter is "" vs. 0.
Target: DELETE


comment:2 Changed 8 years ago by Christian Blackburn <christian.blackburn@…>

Also, in the code example these declarations should probably go first:

#include <APIFilesConstants.au3>
#include <Misc.au3>
#include <WinAPIDiag.au3>
#include <WinAPIFiles.au3>

comment:3 Changed 8 years ago by Melba23

So this should work:

Func _WinAPI_MoveFileEx($sExistingFile, $sNewFile, $iFlags = 0, $pProgressProc = 0, $pData = 0)
	Local $sTypeOfNewFile = 'wstr'
		$sTypeOfNewFile = 'ptr'
		$sNewFile = 0
		If $sNewFile = 0 Then $sNewFile = ""

	Local $aRet = DllCall('kernel32.dll', 'bool', 'MoveFileWithProgressW', 'wstr', $sExistingFile, $sTypeOfNewFile, $sNewFile, _
			'ptr', $pProgressProc, 'ptr', $pData, 'dword', $iFlags)
	If @error Then Return SetError(@error, @extended, 0)
	; If Not $aRet[0] Then Return SetError(1000, 0, 0)

	Return $aRet[0]
EndFunc   ;==>_WinAPI_MoveFileEx



comment:4 Changed 6 years ago by Jpm

  • Milestone set to
  • Owner set to Jpm
  • Resolution set to Fixed
  • Status changed from new to closed

Fixed by revision [12097] in version:

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

as closed The owner will remain Jpm.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.