Page 1 of 1

UnBlock Files in a Directory

Posted: 03 May 2022, 05:04
by lmstearn
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%}

Re: UnBlock Files in a Directory

Posted: 03 May 2022, 11:00
by iseahound
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)

Re: UnBlock Files in a Directory

Posted: 03 May 2022, 19:52
by malcev
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)

Re: UnBlock Files in a Directory

Posted: 04 May 2022, 06:40
by lmstearn
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.

Re: UnBlock Files in a Directory

Posted: 06 May 2022, 17:20
by iseahound
For PowerShell compatibility:

Code: Select all

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