Forum > Windows

[SOLVED] DeleteFile not working on Windows 11

(1/3) > >>

jamestien:
Hello,

Just updated to Windows 11, which caused my program stopped working properly. My program creates temporary file on startup and will delete it upon program termination. Found out that "DeleteFile" function will always return Access denied and failed for deletion. All the file security properties were set to full control for all the accounts.

The temp filename was randomly generated based on current time.
cidbaf63589d72ba91f3c050aa399035a9f6


Anyone encounter the same issue on Windows 11?


UPDATE:
Found the culprit, temporary file created by Zipper had READONLY attribute.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  unzip := TUnZipper.Create;  try    unzip.FileName := sFileName;                                     //Input of compressed ZIP file    unzip.OutputPath := GetTempDir(FALSE);                           //Output directory for unzipped files.    unzip.Examine;    unzip.UnZipAllFiles;    RenameFile(unzip.OutputPath+unzip.Entries[0].ArchiveFileName,gDatabase_TempFile);        FileSetAttr(gDatabase_TempFile,faNormal);  //<============================= This solved the issue.     //DeleteFile(gDatabase_TempFile);   finally    unzip.Free;  end;  

GetMem:
@jamestien

--- Quote ---Anyone encounter the same issue on Windows 11?
--- End quote ---
No, but what error message do you get?

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---if not DeleteFile(Path) then  ShowMessage(SysErrorMessage(GetLastOSError));

jamestien:
GetLastError retuned value of 5, which is Access denied.

The failed filename was "cidbaf63589d72ba91f3c050aa399035a9f6" or any other random strings. Tried to delete other more standard 8.3 filename without problem, really weird on Win 11, never had problem on Win10 before.

GetMem:
@jamestein
Strange. If you have full access to file and the file is not locked by another program(or yours), like this:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var  fs: TFileStream;begin  fs := TFileStream.Create('Path', fmOpen or fmShareDenyWrite);  try    //access denied here  finally    fs.Free; //you forget to free the stream  end;end;then the only remaining option is an antiviurs software.

Also I found this: https://forum.lazarus.freepascal.org/index.php/topic,48284.msg347662.html#msg347662 I'm not sure if it helps.

af0815:
If times goes by the file deleteable ? I have seen on windows two problems with deleting of files.

The first issue, if a AV-Scanner will hold the file for upto 20 second blocked (= access denied on my side)
The second, if if have graphical data inside and this on a gui element, the file will also blocked in the lifetime of the image. A copy of the file will not unlock this issue. The lock is only released, if another from a other file is loaded, or the application is closed.

I have such issues with generating and showing eg. self generated preview pictures.

Navigation

[0] Message Index

[#] Next page

Go to full version