microsoft / Microsoft-Win32-Content-Prep-Tool

A tool to wrap Win32 App and then it can be uploaded to Intune
1k stars 209 forks source link

Access to the path 'IntunePackage.intunewin' is denied #133

Open dkneisz opened 1 month ago

dkneisz commented 1 month ago

Since I can't ropen issue #67, I created a new one:

I still have this issue e.g. when trying this with Notepad++ (v8.7 in my case).

The output is:

INFO   Computed SHA256 hash for 'C:\Users\<user>\AppData\Local\Temp\6ffb452b-4e08-4528-b6d4-38b4936b18ae\IntuneWinPackage\Contents\cef925a8-ce7a-4d97-ad72-d5825090ef0e' within 61 milliseconds
INFO   Computing SHA256 hash for C:\Users\<user>\AppData\Local\Temp\6ffb452b-4e08-4528-b6d4-38b4936b18ae\IntuneWinPackage\Contents\IntunePackage.intunewin
INFO   Computed SHA256 hash for C:\Users\<user>\AppData\Local\Temp\6ffb452b-4e08-4528-b6d4-38b4936b18ae\IntuneWinPackage\Contents\IntunePackage.intunewin within 63 milliseconds
INFO   Copying encrypted file from 'C:\Users\<user>\AppData\Local\Temp\6ffb452b-4e08-4528-b6d4-38b4936b18ae\IntuneWinPackage\Contents\cef925a8-ce7a-4d97-ad72-d5825090ef0e' to 'C:\Users\<user>\AppData\Local\Temp\6ffb452b-4e08-4528-b6d4-38b4936b18ae\IntuneWinPackage\Contents\IntunePackage.intunewin'
INFO   Removing temporary files
ERROR  System.UnauthorizedAccessException: Access to the path 'IntunePackage.intunewin' is denied.
   at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive, Boolean throwOnTopLevelDirectoryNotFound, WIN32_FIND_DATA& data)
   at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive, Boolean checkHost)
   at Microsoft.Management.Service.IntuneWinAppUtil.PackageUtil.CreatePackage(String folder, String setupFile, String outputFolder, String catalogFolder)
   at Microsoft.Management.Service.IntuneWinAppUtil.Program.Main(String[] args)

My guess is, that this is caused by the virus scanner / endpoint protection. When I do the same on a device without virus scanner / endpoint protection it works. It looks like the IntuneWinAppUtil is trying to (re)move the file while the virus scanner / endpoint protection is still scanning the file. Maybe a solution could be to retry this operation a few times before throwing an error. In most cases people will not be able to deacitvate the virus scanner / endpoint protection to get around this.

josephgibbs commented 1 month ago

Good catch! I've also had this issue when trying to package Notepad++ using Microsoft's Intune packaging utility. This may indeed have been due to my company's endpoint protection agent. I agree that doing a try and catch on the System.UnauthorizedAccessException exception, and waiting for some period of time could be a solution in this case. Ideally we would not be building Intune packages on machines without endpoint protection, so this is a necessary patch.