Enable or Disable keyboard shortcuts on Windows devices
  • 02 Feb 2024
  • 3 Minutes to read
  • PDF

Enable or Disable keyboard shortcuts on Windows devices

  • PDF

Article summary

Utilizing keyboard shortcuts is a convenient method for swiftly executing various actions on devices. Nevertheless, there might be instances where you wish to deactivate specific keyboard shortcuts based on your requirements.

The following PowerShell script helps the IT Admins to disable or enable keyboard shortcuts on managed Windows devices.

  1. Create a file on your desktop, for example, disable_keyboard_shortcuts. ps1 and/or enable_keyboard_shortcuts.ps1 and open it in a text editor like notepad++

  2. The following keyboard shortcuts are disabled/enabled after executing respective scripts.

Shortcut Key

Function

Windows key + A

Open Quick Settings

Windows key + Ctrl + F

Search for PCs (if you’re on a network)

Windows key + E

Open File Explorer

Windows key + H

Launch voice typing

Windows key + Pause/Break

Open system information

Windows key + R

Open the Run dialog box

Windows key + S

Open search

Windows key + Shift + S

Capture a screenshot of part of your screen

Windows key + T

Cycle through apps on the taskbar

Windows key + V

Open the clipboard history

Windows key + X

Open the Quick Link menu

Windows key + Alt + R

Record video of the active game window (using Xbox Game Bar)

Windows key + Shift + V

Set focus to a notification.

Windows key + number

Open the desktop and launch the app pinned to the taskbar in the specified position indicated by ‘number’. If the app is already running, switch to that app.

Windows key + Shift + number

Open the desktop and initiate a new instance of the app pinned to the taskbar at the position indicated by ‘number’.

  • Copy the contents below to the files or click on the respective names to download the file.

    • Disable keyboard shortcuts.

      try
      {
          $status = New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
          Function RestrictShortcut($sid)
          {
              $policyPath = "HKU:\${sid}\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer"
      	# Check if the "Explorer" key exists
      	if (!(Test-Path $policyPath))
      	{
          	    # Create the "Explorer" key
          	    New-Item -Path $policyPath -Force | Out-Null
      	}
      	New-ItemProperty -Path $policyPath -Name "NoWinKeys" -Value 1 -PropertyType DWORD -Force | Out-Null        
          }
          $userDetails=Get-wmiobject win32_useraccount | where-object{$_.status -eq 'ok'}
          $loggedInUserCount = 0
          foreach($user in $userDetails)
          {
              $sid=$user.SID
              $username = $user.Name
              if(Test-Path "HKU:\${sid}")
              {
                  Write-Host $username,"is signed-in to the device."
                  Write-Host "Restricting Windows Shortcut for :",$username
                  RestrictShortcut($sid)
                  $loggedInUserCount++
              } 
          }
          if($loggedInUserCount -eq 0)
          {
              Write-Host "Policy hasn't applied to any user, this policy can only be applied when the user is logged in to the device"
          }
          else
          {
              Write-Host "Restart the device to review the changes."
          }
      }
      catch
      {
          Write-Host "Error occured while running script -> ",$_.Exception.Message
      }
    • Enable keyboard shortcuts.

try
{
    $status = New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
    Function RestrictShortcut($sid)
    {
        $policyPath = "HKU:\${sid}\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\"
	$keyname = "Explorer"
     	if(Test-Path "$policyPath\$keyName")
	{
	    Remove-Item -Path "$policyPath\$keyName" -Recurse -Force
	}
    }
    $userDetails=Get-wmiobject win32_useraccount | where-object{$_.status -eq 'ok'}
    $loggedInUserCount = 0
    foreach($user in $userDetails)
    {
        $sid=$user.SID
        $username = $user.Name
        if(Test-Path "HKU:\${sid}")
        {
            Write-Host $username,"is signed-in to the device."
            Write-Host "Enabling Windows Shortcut for :",$username
            RestrictShortcut($sid)
            $loggedInUserCount++
        } 
    }
    if($loggedInUserCount -eq 0)
    {
        Write-Host "Policy hasn't applied to any user, this policy can only be applied when the user is logged in to the device"
    }
    else
    {
        Write-Host "Restart the device to review the changes."
    }
}
catch
{
    Write-Host "Error occured while running script -> ",$_.Exception.Message
}

Follow our guide to upload & publish the PowerShell script using Scalefusion Dashboard.

Note:

It is necessary to restart the device for the above scripts to take effect.

Please note that to use the PowerShell scripts, the Scalefusion MDM Agent Application must be installed on the device(s). Please follow our guide to publish and install the Scalefusion MDM Agent Application.

Notes:

  1. The scripts and their contents are sourced from various albeit authenticated Microsoft sources and forums.

  2. Please validate the scripts on a test machine before deploying them on all your managed devices.

  3. Scalefusion has tested these scripts, however, Scalefusion will not be responsible for any loss of data or system malfunction that may arise due to the incorrect usage of these scripts.


Was this article helpful?