Jump to content

Toggle hidden files Show/Hide


Recommended Posts

This script changes the state of Hidden files, if hidden files are set to show this turns them off, if hidden files are set to hide this shows them.

Comments?





 
# This key contains all of the profiles on the machine (including non-user profiles)
$profileList = Get-ChildItem -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
 
# This key contains the path to the folder that contains all the profiles (typically c:\users)
$profileFolder = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList').ProfilesDirectory
 
# This key contains the path to the default user profile (e.g. C:\Users\Default).  This is **NOT** HKEY_USERS\.DEFAULT!
# We don't do anything with it in this sample script, but it can be loaded and modified just like any other profile.
$defaultFolder = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList').Default
 
# HKEY_USER key is not loaded into PowerShell by default and we'll need it, so we'll create new PSDrive to reference it.
New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null
 
$profileList | % {
    
    $profileKeys = Get-ItemProperty $_.PSPath
    
    $sid = $profileKeys.PSChildName
    $profilePath = $profileKeys.ProfileImagePath
    
    # This is an easy way to exclude profiles outside of the default USERS profile folder, e.g. LocalSystem.
    # You may or may not want to do this depending on your requirements.
    if ($profilePath -like "$($profileFolder)*") {
        
        # Check if the profile is already loaded.        
        if (Get-ChildItem "HKU:\$sid" -ErrorAction SilentlyContinue) {
            $profileLoaded = $true
        } else {
            $profileLoaded = $false
        }
        
        Write-Output "$sid `t $profilePath `t $profileLoaded"
        
        # Load the key if necessary
        if ($profileLoaded) {
            $userKeyPath = "HKU:\$sid"
        } else {
            $userKeyPath = "HKLM:\TempHive_$sid"
            & reg.exe load "HKLM\TempHive_$sid" "$profilePath\ntuser.dat"
        }
        
        # DO SOMETHING WITH $USERKEYPATH HERE.
#############################################################################################


$hide = (Get-ItemProperty -path $USERKEYPATH\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced).Hidden

If ($hide -eq 0) { 

Set-ItemProperty -Path $USERKEYPATH\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name Hidden -Value "1"

}
 
IF ($hide -eq 1) { 

Set-ItemProperty -Path $USERKEYPATH\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name Hidden -Value "0"

}


##############################################################################################        
        if (!$profileLoaded) {
            & reg.exe unload "HKLM\TempHive_$sid"
        }
        
    }
}
 
Remove-PSDrive -Name HKU

################################################################

$TasknameStop = "ExplorerStop"
$TasknameStart = "ExplorerStart"
$lastlogon = (New-Object -ComObject WScript.Shell).RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\LastLoggedOnUser")

SCHTASKS /CREATE /sc ONCE /st 00:00 /TN $TasknameStop /RU $lastlogon /TR "taskkill /f /im explorer.exe"
SCHTASKS /CREATE /sc ONCE /st 00:00 /TN $TasknameStart /RU $lastlogon /TR "explorer.exe" 
start-sleep -s 1
schtasks /Run /TN $TasknameStop
start-sleep -s 1
schtasks /Run /TN $TasknameStart
start-sleep -s 1
schtasks /delete /tn $TasknameStop /f
schtasks /delete /tn $TasknameStart /f

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...