TL:DR When trying to install and run a .bat script file via intune Win32 app the install behavior is stuck on SYSTEM and greyed out, but the batch script requires to be run as current logged in user.

The original problem: I need to delete the Microsoft Edge shortcut from the users desktop on their laptop, it's a work place that uses intune manage all the laptops

My solution that doesn't work: I have made a batch script to delete the Microsoft Edge shortcut on the desktop, it requires to runs as user. I have then packaged that batch file via the Microsoft Win32 Content Prep Tool, then I have uploaded the .intunewin to intune when adding a new Win32 app, but I can't set the install behavior on intune, it's greyed out and stuck on system, which doesn't work since the batch script requires to be run as user. When doing the win32 app install behavior as SYSTEM the batch script tries to find the shortcut via %username% but %username% is NOT the current logged in user when it has SYSTEM as install behavior.

Note: The ONLY file that is packaged is the .bat script file, the script does not use any msi or anything else.

1 Answer 1


Better late than never?

If you don't mind using PowerShell (it doesn't appear in your tag list), you could do it with this:

Get-ChildItem -Path 'C:\Users\*\Desktop\*' -File -Filter '*Edge*.lnk' -ErrorAction SilentlyContinue | Remove-Item

That one-liner obtains all files matching the filter in every user's Desktop directory then sends them along the pipeline to the Remove-Item cmdlet. The ErrorAction parameter is there to suppress "Access denied" errors from those directories that require special privileges.

All that's left is calling PowerShell from your batch file. That might look something like this:

powershell.exe -ExecutionPolicy Bypass -NoLogo -NoProfile -Command "Get-ChildItem -Path 'C:\Users\*\Desktop\*' -File -Filter '*Edge*.lnk' -ErrorAction SilentlyContinue | Remove-Item"

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.