Toggle protected operating system files (Explorer Show/Hide SuperHidden)

Post your working scripts, libraries and tools.
User avatar
xypha
Posts: 24
Joined: 24 Apr 2020, 04:14

Toggle protected operating system files (Explorer Show/Hide SuperHidden)

17 Dec 2023, 02:34

Toggle protected operating system files in Windows File Explorer, i.e., show or hide SuperHidden files - applies to OS folders like $Recycle.Bin and files like hiberfil.sys.
Inspired by this post by gonzax
Adapted to AHK v2 and improved to show status of registry key (in the form of a check mark) in tray menu.

Code: Select all

; Autoexecute
; always at the top of your script

#Requires AutoHotkey v2.0

A_TrayMenu.Delete()                             ; delete standard menu
A_TrayMenu.Add "&Toggle OS files", ToggleOS     ; User-defined Function
A_TrayMenu.Add()                                ; add a separator
A_TrayMenu.AddStandard()                        ; restore standard menu
ToggleOSCheck()                                 ; check value of ShowSuperHidden_Status

; Toggle OS Function
; below code can be anywhere in your script

ToggleOSCheck() {
Global ShowSuperHidden_Status
ShowSuperHidden_Status := RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "ShowSuperHidden") 
If (ShowSuperHidden_Status = 0)
    A_TrayMenu.UnCheck "&Toggle OS files"
Else {
    ShowSuperHidden_Status := 1
    A_TrayMenu.Check "&Toggle OS files"
    }
}

ToggleOS(*) {
ToggleOSCheck()
If (ShowSuperHidden_Status = 0) { ; enable if disabled
    RegWrite "1", "REG_DWORD", "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "ShowSuperHidden"
    ToggleOSCheck()
    WindowsRefreshOrRun()
    } Else { ; disable if enabled 
    RegWrite "0", "REG_DWORD", "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "ShowSuperHidden"
    ToggleOSCheck()
    WindowsRefreshOrRun()
    }
}

;  Windows Refresh Or Run

WindowsRefreshOrRun() {
if WinExist("ahk_class CabinetWClass") {
    WinActivate
    Sleep 500  ; change as per your system performance
    Send "{F5}" ; refresh
} else {
    Run 'explorer.exe',,"max"
    WinWait("ahk_class CabinetWClass")
    WinActivate
    }
}

This code is old.
Updates will be posted here on GitHub.

Return to “Scripts and Functions (v2)”

Who is online

Users browsing this forum: No registered users and 52 guests