Skip to content

Latest commit

 

History

History
188 lines (136 loc) · 12.5 KB

File metadata and controls

188 lines (136 loc) · 12.5 KB

Windows Utility Scripts

This directory of IGLibScripts contains some useful Windows Utility scripts.

Contents:

Quick To Do

Quick - Documentation - To Improve

  • In Examples for each script, add a comment before each code snippet that tells what the example does (what is the effect). For example:
# Hides the taskbar; -RestartExplorer restarts the Windows Explorer, such that settings take effect.
.\HideTaskbar.ps1 -RestartExplorer
# Attempts to apply the registry changes that hide the taskbar to all users
.\HideTaskbar.ps1 -AllUsers -RestartExplorer
# Reverts the effect of the script / un-hides the taskbar (only fot the current user)
.\HideTaskbar.ps1 -Revert -RestartExplorer

Windows PowerShell Utilities and Template Engine - Documentation

Documentation is currently in this external document.


Miscellaneous Remarks

Remarks on RemoveTaskbar.ps1

In the newer versions of Windows 11 (24H2 or higher), control over removing the taskbar via registry has changed or this possibility was removed (as well as the ability to change icon size in taskbar). The basis for the script is given in this article or in this post.

Beside that, there are some differences between RemoveTaskbar.ps1 and HideTaskbar.ps1 when iterating over user profile (SIDs - security identifiers).

Remarks on AddContextMenuItem.ps1

Additional Tips for Use

The script AddCodeToExplorerMenu.ps1 uses AddContextMenuItem.ps1, and can therefore be consulted to see how the script is used. It can also be used as template for creating sscripts for adding specific items to Windows Explorer's context menu.

A few optional ideas (maybe included in AddCodeToExplorerMenu.ps1 later):

  • Show only on Shift-right-click: add the Extended flag (so it appears only in the “extended”/Shift menu).
  • Limit to certain file types: use -AppliesTo (e.g., only show for .txt or for directories).
  • Open a new VS Code window: add -n to the args.
  • Add a background-only “Open VS Code here”: use %V for the folder path (you already did).

Some quick copy-paste examples using the AddContextMenuItem.ps1, including how to achieve some of the above possibilities:

# 1) Make the entry appear only on Shift-right-click (Files + Directories)
.\AddContextMenuItem.ps1 `
  -Title "Open with VS Code" `
  -CommandPath "$env:LOCALAPPDATA\Programs\Microsoft VS Code\Code.exe" `
  -Arguments '"%1"' `
  -Icon "$env:LOCALAPPDATA\Programs\Microsoft VS Code\Code.exe" `
  -Targets Files,Directories `
  -RestartExplorer
# Add the Extended flag
New-ItemProperty -Path "HKCU:\Software\Classes\*\shell\Open_with_VS_Code" -Name Extended -Value "" -Force | Out-Null
New-ItemProperty -Path "HKCU:\Software\Classes\Directory\shell\Open_with_VS_Code" -Name Extended -Value "" -Force | Out-Null
# 2) Background-only “Open VS Code here” (no file/folder selection), new window
.\AddContextMenuItem.ps1 `
  -Title "Open VS Code here" `
  -CommandPath "$env:LOCALAPPDATA\Programs\Microsoft VS Code\Code.exe" `
  -BackgroundArguments '-n "%V"' `
  -Icon "$env:LOCALAPPDATA\Programs\Microsoft VS Code\Code.exe" `
  -Targets Background `
  -RestartExplorer
# 3) Only show for certain types (e.g., .ps1 files)
# Add the menu:
.\AddContextMenuItem.ps1 `
  -Title "Open PS1 in VS Code" `
  -CommandPath "$env:LOCALAPPDATA\Programs\Microsoft VS Code\Code.exe" `
  -Arguments '"%1"' `
  -Icon "$env:LOCALAPPDATA\Programs\Microsoft VS Code\Code.exe" `
  -Targets Files `
  -RestartExplorer

# Then scope it with AppliesTo (PowerShell-only files)
New-ItemProperty -Path "HKCU:\Software\Classes\*\shell\Open_PS1_in_VS_Code" -Name "AppliesTo" -Value "System.ItemType:='.ps1'" -Force | Out-Null

If one needs this to also appear in the new Windows 11 condensed menu (not just “Show more options”), the Explorer needs to be wired up with Command Handler registration.

Notes for Developers

Disabling Modern Standby (S0 mode) and enabling the Standard Sleep (S3 mode) would not work on many modern laptops (because many OEMs are disabling the S3 mode in firmware) and because of this, a PowerShell script to do this was not provided. Only the registry edit scripts were provided, the EnableS3Standby_NormalSleep.reg for enabling the normal sleep mode, and DisableS0Standby_ModernStandby.reg to disable the Modern Standby (which, if it works, may result in crashing computer when sleep mode is entered via UI or buttons / closing the lid of a laptop). Some links are in the first registry file. See also:

Notes - Hiding the Taskbar

Script: HideTaskbar.ps1
Script does currently not work: although it attempts to set the specific registry value, after verification, the value has not changed.

To verify what this specific value is, evaluate the following expression in PowerShell:

(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3" -Name Settings).Settings[8]
  • Basis: from this Reddit, the last link:
    • No taskbar on Windows, see the last answer from Sengupta; this may actually be about completely removing the taskbar (?).
    • Or: this post, method 3 or method 4.
  • This may be outdated or serve a different purpose maybe, e.g. for removing the taskbar rather than auto-hiding it.

A different approach (editing a different registry key):

In Registry Editor (Win-R, regedit), go to

Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, set TaskbarDa to 0 for hidden, 1 for visible. Q: is this for temporarily hiding or permanently removing the taskbar?

Another variant from here (methodunder No. 3): In registy, navigate to Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, then on the right pane, right-click any space and click New, then DWORD (32-bit) Value, and name the new DWORD AutoHideTaskbar.

In UI, hide / unhide the taskbar via Settings/Personalization/Taskbar/Taskbar Behaviors/Automatically hide the taskbar.

Notes - ToDo

Add to Context Menu

Script AddToContextMenu.ps1, which adds a certain command to the Explorer's context menu. For example, "Open with VS Code".

Patameters:

  • Title (e.g. "Open with VS Code")
  • Command (e.g. "C:\\Users\\YourUserName\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe" "%V" to open directories, "...\\Code.exe" "%1" for files)
  • Icon (optional) - you can set it to the path of executable, e.g. "C:\\Users\\YourUserName\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"
Add Open with VS Code

See: