UnBlock Files in a Directory

Put simple Tips and Tricks that are not entire Tutorials in this forum
User avatar
lmstearn
Posts: 695
Joined: 11 Aug 2016, 02:32
Contact:

UnBlock Files in a Directory

03 May 2022, 05:04

After downloading all the files from OneDrive MS_OneDrive_Bustup had recycled from Desktop, after the backup on Desktop folders was stopped by me, all of the recovered files had a blocked flag on them. (The correct pathnames showed up for the files in the recycle bin, but the restore action wiped them)
This little one-liner ran silently, and, after performing the trick. opened up a PS window in the script directory.
For paranoia, go this way to get a list of all files modified- other ways posted here are welcome.

Code: Select all

SetWorkingDir %A_ScriptDir%
psScript =
(
dir -Path "Your_FQ_Folder_PathName" -Recurse | Unblock-File
)

;RunWait PowerShell.exe -Command &{%psScript%} ,, hide
Run PowerShell.exe -NoExit -Command &{%psScript%}
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH
iseahound
Posts: 1446
Joined: 13 Aug 2016, 21:04
Contact:

Re: UnBlock Files in a Directory

03 May 2022, 11:00

Note that this could be done in AutoHotkey as shown here:

viewtopic.php?style=19&t=90290

As a side note I do not recognize the Unblock File cmdlet, so it may not be compatible with earlier versions of Powershell (like on Windows 7)
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: UnBlock Files in a Directory

03 May 2022, 19:52

Or with Persistent Zone Identifier object help
https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/ms537029(v=vs.85)

Code: Select all

file := "D:\Downloads\qweqwe.dll"
PersistentZoneIdentifier := "{0968E258-16C7-4DBA-AA86-462DD61E31A3}"
IZoneIdentifier := "{CD45F185-1B21-48E2-967B-EAD743A8914E}"
IPersistFile := "{0000010b-0000-0000-C000-000000000046}"
ZoneIdentifier := ComObjCreate(PersistentZoneIdentifier, IZoneIdentifier)
PersistFile := ComObjQuery(ZoneIdentifier, IPersistFile)
DllCall(NumGet(NumGet(PersistFile+0) + 5*A_PtrSize), "ptr", PersistFile, "ptr", &file, "UInt", 0)  ; load
DllCall(NumGet(NumGet(ZoneIdentifier+0) + 5*A_PtrSize), "ptr", ZoneIdentifier)  ; remove
DllCall(NumGet(NumGet(PersistFile+0) + 6*A_PtrSize), "ptr", PersistFile, "ptr", &file, "Int", 1)  ; save
ObjRelease(PersistFile)
ObjRelease(ZoneIdentifier)
User avatar
lmstearn
Posts: 695
Joined: 11 Aug 2016, 02:32
Contact:

Re: UnBlock Files in a Directory

04 May 2022, 06:40

Addendum to above: the nice blue PS popup command window doesn't come with the Try the new cross-platform PowerShell https://aka.ms/pscore6 plug. :P
iseahound wrote:
03 May 2022, 11:00
Note that this could be done in AutoHotkey as shown here:
viewtopic.php?style=19&t=90290
As a side note I do not recognize the Unblock File cmdlet, so it may not be compatible with earlier versions of Powershell (like on Windows 7)
Thanks! Good idea for a future project to recurse the directories as suggested here and store them in an object array.

Ah, the version here is 5.1.19041.1645, the zone ids came in with Win 8. Might make a difference if you just install PowerShell 7.3 on the W7 system- if something goes wrong there's no official tech support, that's for sure. :thumbdown:
malcev wrote:
03 May 2022, 19:52
Or with Persistent Zone Identifier object help
https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/ms537029(v=vs.85)

Code: Select all

file := "D:\Downloads\qweqwe.dll"
PersistentZoneIdentifier := "{0968E258-16C7-4DBA-AA86-462DD61E31A3}"
IZoneIdentifier := "{CD45F185-1B21-48E2-967B-EAD743A8914E}"
IPersistFile := "{0000010b-0000-0000-C000-000000000046}"
ZoneIdentifier := ComObjCreate(PersistentZoneIdentifier, IZoneIdentifier)
PersistFile := ComObjQuery(ZoneIdentifier, IPersistFile)
DllCall(NumGet(NumGet(PersistFile+0) + 5*A_PtrSize), "ptr", PersistFile, "ptr", &file, "UInt", 0)  ; load
DllCall(NumGet(NumGet(ZoneIdentifier+0) + 5*A_PtrSize), "ptr", ZoneIdentifier)  ; remove
DllCall(NumGet(NumGet(PersistFile+0) + 6*A_PtrSize), "ptr", PersistFile, "ptr", &file, "Int", 1)  ; save
ObjRelease(PersistFile)
ObjRelease(ZoneIdentifier)
Good one, :thumbup: - the C++ code is helped a bit by the ATL and urlmon libs.
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH
iseahound
Posts: 1446
Joined: 13 Aug 2016, 21:04
Contact:

Re: UnBlock Files in a Directory

06 May 2022, 17:20

For PowerShell compatibility:

Code: Select all

Get-ChildItem -File -Force -Recurse | foreach {echo $_.fullname; Remove-Item -LiteralPath $_.fullname -Stream Zone.Identifier -ErrorAction SilentlyContinue}

Return to “Tips and Tricks (v1)”

Who is online

Users browsing this forum: No registered users and 81 guests