Jump to content

Unblocker Script


 Share

Recommended Posts

Recently I stumbled across this again and got frustrated, so I wrote a script to fix it (because that's what heroes do?). Every time I download a file from the internet or my email, the file gets marked as being from the internet. When I open the properties, there's a fancy checkbox to "Unblock" the file. I've experienced issues with this, especially when trying to download a Visual Studio project and import it for school. I learned a ton about FileStreams because I dove into PowerShell's UnblockFile source code. I'm still not very clear on what or why FileStreams, but I did manage to find out that unblocking a file is as simple as making a WinAPI FileDelete call with ":Zone.Information" appended to the file path.

Func _File_Unblock($sFilePath)

    Local $hFile = FileOpen($sFilePath & ":Zone.Identifier", 2)
    If $hFile = -1 Then Return SetError(1, 0, False)
    FileWrite($hFile, "")
    FileClose($hFile)
    Return True

EndFunc

I think the script is pretty self-explanatory, but I thought I'd share in case anyone else runs into this issue :)

Edit: So I found a bit more about this, mostly because a comment somewhere mentioned that this Zone.Identifier was actually an Ini file. This website showed how to open and edit the file, so I found that the format of the IniFile is something like this: (I used a copy of my UDF that I downloaded)

[ZoneTransfer]
ZoneId=3
ReferrerUrl=https://www.autoitscript.com/forum/topic/202026-acroau3-udf/
HostUrl=https://www.autoitscript.com/forum/applications/core/interface/file/attachment.php?id=63984

It appears that File Explorer deletes the entire stream when you click "Unblock". Setting the ZoneId to 0, 1, or 2 doesn't appear to make any changes and "Unblock" is still visible. I also found FileOpen allows Reading/Writing to FileStreams, so _WinAPI_FileDelete isn't needed.

Edited by seadoggie01

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

Disable downloaded files from being blocked in Windows 10
Open Group Policy Editor by typing gpedit.msc into the Start Menu.
Go to User Configuration -> Administrative Templates -> Windows Components -> Attachment Manager.
Double click the policy setting "Do not preserve zone information in file attachments". Enable it and click OK.

:)

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

I was working on this on a computer where I don't have admin permission sadly, but that's very helpful for at home! Thank you! :) 

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

On 5/21/2020 at 8:42 AM, seadoggie01 said:

Recently I stumbled across this again and got frustrated, so I wrote a script to fix it (because that's what heroes do?). Every time I download a file from the internet or my email, the file gets marked as being from the internet. When I open the properties, there's a fancy checkbox to "Unblock" the file. I've experienced issues with this, especially when trying to download a Visual Studio project and import it for school. I learned a ton about FileStreams because I dove into PowerShell's UnblockFile source code. I'm still not very clear on what or why FileStreams, but I did manage to find out that unblocking a file is as simple as making a WinAPI FileDelete call with ":Zone.Information" appended to the file path.

Func _File_Unblock($sFilePath)

    Local $hFile = FileOpen($sFilePath & ":Zone.Identifier", 2)
    If $hFile = -1 Then Return SetError(1, 0, False)
    FileWrite($hFile, "")
    FileClose($hFile)
    Return True

EndFunc

I think the script is pretty self-explanatory, but I thought I'd share in case anyone else runs into this issue :)

Edit: So I found a bit more about this, mostly because a comment somewhere mentioned that this Zone.Identifier was actually an Ini file. This website showed how to open and edit the file, so I found that the format of the IniFile is something like this: (I used a copy of my UDF that I downloaded)

[ZoneTransfer]
ZoneId=3
ReferrerUrl=https://www.autoitscript.com/forum/topic/202026-acroau3-udf/
HostUrl=https://www.autoitscript.com/forum/applications/core/interface/file/attachment.php?id=63984

It appears that File Explorer deletes the entire stream when you click "Unblock". Setting the ZoneId to 0, 1, or 2 doesn't appear to make any changes and "Unblock" is still visible. I also found FileOpen allows Reading/Writing to FileStreams, so _WinAPI_FileDelete isn't needed.

Looks very similar to a script I wrote a long time ago.  But good work!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...