Modify

Opened 9 years ago

Closed 7 years ago

#3243 closed Bug (Fixed)

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

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

Description

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

The documentation for _WinAPI_MoveFileEx (https://www.autoitscript.com/autoit3/docs/libfunctions/_WinAPI_MoveFileEx.htm) 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 (https://technet.microsoft.com/en-us/sysinternals/pendmoves.aspx) 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 - wwww.sysinternals.com

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

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

Attachments (0)

Change History (4)

comment:1 Changed 9 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

-Christian

comment:2 Changed 9 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 9 years ago by Melba23

So this should work:

Func _WinAPI_MoveFileEx($sExistingFile, $sNewFile, $iFlags = 0, $pProgressProc = 0, $pData = 0)
	Local $sTypeOfNewFile = 'wstr'
	If Not StringStripWS($sNewFile, $STR_STRIPLEADING + $STR_STRIPTRAILING) Then
		$sTypeOfNewFile = 'ptr'
		$sNewFile = 0
	EndIf
	
	If BitAnd($iFlags, $MOVE_FILE_DELAY_UNTIL_REBOOT) Then
		If $sNewFile = 0 Then $sNewFile = ""
	EndIf

	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

Happy?

M23

comment:4 Changed 7 years ago by Jpm

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

Fixed by revision [12097] in version: 3.3.15.1

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

Action
as closed The owner will remain Jpm.
Author


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

 
Note: See TracTickets for help on using tickets.