AutoHotKey: remove the Mark Of The Web
- Nov. 11, 2024
Introduction
When you download files, even more when programming code or macros are involved, Windows will apply the so-called Mark Of The Web (MOTW): it is a marker to signify that the file originates from the internet, email, etc. The file can be potentially dangerous for your system. Then you need to go to the properties of the file and remove the marker. E.g. macros in an Excel file will refuse to work when the MOTW marker is not removed. You have to uncheck a checkbox to undo the macro execution block.
So when I download a bunch of files, I want to automatically remove the MOTW marker. The below AutoHotKey script kan remove the marker for all files in the Downloads folder that are more recent than the last 5 minutes. That parameter can be changed easily.
^q:: ; Ctrl+q hotkey { ; Get the current timestamp to calculate the recent time window recentThreshold := 5 * 60 ; Time in seconds recentTime := A_Now EnvAdd, recentTime, -%recentThreshold%, Seconds cPath_Downloads := A_MyDocuments "\..\Downloads" Loop, Files, %cPath_Downloads%\* { ; Check if the file was modified within the recent threshold if (A_LoopFileTimeModified > recentTime) { ; Check for MOTW (Zone.Identifier alternate data stream) if (FileExist(A_LoopFileLongPath ":Zone.Identifier")) { ; Remove the MOTW by deleting the Zone.Identifier stream FileDelete, %A_LoopFileLongPath%:Zone.Identifier if ErrorLevel MsgBox, 48, Error, Failed to remove MOTW from: %A_LoopFileName% } } } } return
Code explanations
The code is I think rather straightforward. I use Ctrl-q here as the shortcut key (hotkey) but maybe you prefer a different combination.