Modify

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#2144 closed Bug (No Bug)

Compiled script does not open with FILE_SHARE_DELETE

Reported by: anonymous Owned by:
Milestone: Component: AutoIt
Version: 3.3.9.1 Severity: None
Keywords: Cc:

Description

I tried to implement a selfdelete using a copy of the executable in a file opend with FILE_DELETE_ON_CLOSE. When running this copy, I get the following error:

Unable to open the script file

Example script:

#include<File.au3>
#region Selfdelete functions
#OnAutoItStartRegister "__SelfDelete"

; Function to start self deletion
Func _SelfDelete($exitCode = 0)
	; by ProgAndy
	If Not @Compiled Then Return SetError(1, 0, 0)
	$sDeleteCopy = _TempFile(@TempDir, "~", ".exe")
	FileCopy(@ScriptFullPath, $sDeleteCopy, 1)
	; Open File handle in Delete after close read access before running
	Local $hFile= DllCall("kernel32.dll", "handle", "CreateFileW", "wstr", $sDeleteCopy, "dword", 1, "dword", 5, "ptr", 0, "dword", 4, "dword", 0x04000100, "ptr", 0)
	$hFile = $hFile[0]
	Local $iPid = Run('"'  &$sDeleteCopy & '" -selfdelete ' & @AutoItPID & ' "' & @ScriptFullPath & '"', @WorkingDir, @SW_HIDE)
	If @error Then
		DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hFile)
		Return SetError(2, 0, 0)
	EndIf
	Do
		Sleep(100)
	Until ProcessExists($iPid)
	; close our handle. The file will be deleted when the started process exits
	DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hFile)
	Exit $exitCode
EndFunc
; internal function
Func __SelfDelete()
	If Not ($CMDLINE[0] = 3 And $CMDLINE[1] == "-selfdelete") Then Return
	ProcessWaitClose(Number($CMDLINE[2]))
	MsgBox(0, "-", $CMDLINE[2])
	For $i = 1 To 10
		Sleep(100)
		If FileDelete($CMDLINE[3]) Then ExitLoop
	Next
	Exit
EndFunc

#endregion Selfdelete functions

_SelfDelete()

Attachments (0)

Change History (2)

comment:1 Changed 12 years ago by Valik

  • Resolution set to No Bug
  • Status changed from new to closed

I'm not sure why you are reporting this as a bug. I think that allowing the file to be deleted/renamed will break FileInstall() in cases where the file is deleted/renamed during execution.

comment:2 Changed 12 years ago by anonymous

I'm not sure why you are reporting this as a bug. I think that allowing the file to be deleted/renamed will break FileInstall() in cases where the file is deleted/renamed during execution.

I don't think so. The executable should still be locked while executing even if calls to CreateFile allow FILE_SHARE_DELETE.
It could have also been my PC acting up. I tried it several times with beta, stable, x86 and x64 and it did not work. Now I tried again and it runs flawlessy.

I'll try different PCs and if it doesn't work I'll consider it an AutoIt limitation.

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 ticket will remain with no owner.
Author


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

 
Note: See TracTickets for help on using tickets.