Whilst it works perfectly in Windows 10 Anniversary Update (much to my surprise ), I'm at a loss to explain why it doesn't unblock files in Windows 7. I'm using AHK Unicode 1.1.24.01 x64 on both devices. Can anyone look at the code and provide a reason?
Code: Select all
; This script was prompted by https://blogs.technet.microsoft.com/heyscriptingguy/2015/01/10/powertip-use-powershell-to-unblock-files-in-folder/
#SingleInstance force
; Prompt to 'Run as Admin', i.e. show UAC dialog
If Not A_IsAdmin
{
Run *RunAs "%A_ScriptFullPath%" ; Requires v1.0.92.01+
ExitApp
}
; Create the GUI elements
Gui, Add, Text, x20 y10 w170 h20 , Select SOURCE folder
Gui, Add, Button, x25 y30 w100 h30 , SOURCE
Gui, Add, Button, x25 y65 w100 h30 , Cancel
Gui -SysMenu
Gui, Show, w150 h100, Windows File Unblocker
return
; Determine what the SOURCE button does
ButtonSOURCE:
FileSelectFolder, SourceVar, *%A_MyDocuments%, 4, Select a SOURCE folder ;Select a source folder (with default location)
; Submit the results of the user's choice
Gui, submit ;Save the selected folder path to a variable
;MsgBox %SourceVar% ;Use MsgBox to test output to commandline
Gui, Destroy ;Close the first GUI so it doesn't muck up the progress bar
; Create and run the PowerShell command
psScript =
(
Get-ChildItem -Path '%SourceVar%' -Recurse | Unblock-File
)
Run PowerShell.exe -Command &{%psScript%} ,, hide
; Create a second GUI showing looping progress bar ('cos unblocking loads of files can take some time)
; Credit to polyethene for the progress bar routine (https://autohotkey.com/board/topic/12306-infinite-progress-bar/#entry79882)
Gui, Add, Progress, vlvl -Smooth 0x8 w350 h18 ; PBS_MARQUEE = 0x8
Gui, Show, , Unblocking... Please wait...
SetTimer, Unblocking, 45
Return
Unblocking:
GuiControl, , lvl, 1
Process, Exist, powershell.exe, ; Check whether PowerShell still running
If (!Errorlevel){
SetTimer, Unblocking, Off ; Turn off process timer
Gui, Destroy ; Close the second GUI
MsgBox, 64, Windows File Unblocker, Finished! Your files have been unblocked! ; Inform user that process has finished
;Run, %SourceVar% ; Open the folder to show files
ExitApp
}
Return
; Determine what the CANCEL button does
ButtonCancel:
ExitApp
Esc::ExitApp ; Use the Esc key to exit the app