﻿id	summary	reporter	owner	description	type	status	milestone	component	version	severity	resolution	keywords	cc
2144	Compiled script does not open with FILE_SHARE_DELETE	anonymous		"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()
}}}"	Bug	closed		AutoIt	3.3.9.1	None	No Bug		
