How to Set a Hotkey for a Shortcut in Batch Script
Keyboard shortcuts (hotkeys) allow you to launch applications instantly without navigating menus or searching the desktop. Windows supports assigning a hotkey to any .lnk shortcut file, and this can be done programmatically using Batch Script. In this guide, we will explore how to create shortcuts with hotkey assignments and how to modify existing shortcuts to add keyboard shortcuts.
This technique is perfect for power users and system administrators who want to set up standardized keyboard shortcuts across multiple workstations.
How Shortcut Hotkeys Work in Windows
When you assign a hotkey to a shortcut, Windows registers that key combination globally. Pressing the combination launches the shortcut's target application from anywhere in the system, regardless of which window is active.
Rules and Limitations
- Hotkeys must include Ctrl+Alt as a modifier (Windows adds this automatically if you only specify a letter).
- The shortcut must be located on the Desktop, in the Start Menu, or in the Taskbar pinned folder. Shortcuts in arbitrary folders do not support hotkeys.
- Only
.lnkfiles support hotkeys. Regular files and folders do not. - Hotkeys are not case-sensitive:
Ctrl+Alt+NandCtrl+Alt+nare the same.
Assigning a hotkey that conflicts with an existing system or application shortcut will override the existing one. For example, assigning Ctrl+Alt+D may conflict with some graphics card software. Choose unique combinations to avoid issues.
Setting a Hotkey via VBScript
Since Batch Script cannot create or modify .lnk files natively, we use the WScript.Shell COM object. The Hotkey property accepts a string in the format "CTRL+ALT+KeyName".
Creating a Shortcut with a Hotkey
@echo off
setlocal
set "shortcut=%USERPROFILE%\Desktop\Quick Notepad.lnk"
set "target=C:\Windows\System32\notepad.exe"
set "hotkey=CTRL+ALT+N"
> "%temp%\hotkey.vbs" (
echo Set ws = CreateObject("WScript.Shell"^)
echo Set sc = ws.CreateShortcut("%shortcut%"^)
echo sc.TargetPath = "%target%"
echo sc.Hotkey = "%hotkey%"
echo sc.Save
)
cscript /nologo "%temp%\hotkey.vbs"
del "%temp%\hotkey.vbs"
echo [OK] Shortcut created with hotkey: %hotkey%
pause
After running this script, pressing Ctrl+Alt+N from anywhere will launch Notepad.
Supported Key Names
The Hotkey property supports the following modifiers and key names:
| Modifier | Value |
|---|---|
| Ctrl | CTRL |
| Alt | ALT |
| Shift | SHIFT |
| Key | Value | Key | Value |
|---|---|---|---|
| Letters | A through Z | Function keys | F1 through F12 |
| Numbers | 0 through 9 | Numpad | NUM0 through NUM9 |
Valid Hotkey Examples
CTRL+ALT+T- Launch a terminalCTRL+ALT+SHIFT+S- Launch a settings toolCTRL+ALT+F5- Refresh a custom tool
Adding a Hotkey to an Existing Shortcut
If a shortcut already exists on the desktop, you can modify only its Hotkey property without changing anything else.
@echo off
setlocal
set "shortcut=%USERPROFILE%\Desktop\My Application.lnk"
set "hotkey=CTRL+ALT+M"
if not exist "%shortcut%" (
echo [ERROR] Shortcut not found.
pause
exit /b 1
)
> "%temp%\sethotkey.vbs" (
echo Set ws = CreateObject("WScript.Shell"^)
echo Set sc = ws.CreateShortcut("%shortcut%"^)
echo sc.Hotkey = "%hotkey%"
echo sc.Save
)
cscript /nologo "%temp%\sethotkey.vbs"
del "%temp%\sethotkey.vbs"
echo [OK] Hotkey %hotkey% assigned to "%shortcut%".
pause
When modifying an existing shortcut, the CreateShortcut method opens it for editing rather than creating a new one. Only the properties you explicitly set will be changed.
Common Mistakes
The Wrong Way: Missing the CTRL+ALT Modifier
:: WRONG - single key without modifiers
echo sc.Hotkey = "N"
Output Concern:
Windows will silently add CTRL+ALT as the default modifier, making the actual hotkey CTRL+ALT+N. While this works, it can be confusing because your code does not reflect the actual key combination.
The Correct Way: Explicitly Specifying Modifiers
:: CORRECT - clear and explicit
echo sc.Hotkey = "CTRL+ALT+N"
Always write the full combination so anyone reading the script knows exactly what keys to press.
The Wrong Way: Placing the Shortcut in a Random Folder
:: WRONG - hotkey will not work from a custom folder
set "shortcut=C:\MyTools\launcher.lnk"
Output Concern: The shortcut is created successfully and the hotkey property is set, but pressing the key combination does nothing. Windows only registers hotkeys for shortcuts in specific locations.
The Correct Way: Use Desktop or Start Menu
:: CORRECT - Desktop works for hotkeys
set "shortcut=%USERPROFILE%\Desktop\launcher.lnk"
:: ALSO CORRECT - Start Menu works
set "shortcut=%APPDATA%\Microsoft\Windows\Start Menu\Programs\launcher.lnk"
Using PowerShell as an Alternative
@echo off
set "shortcut=%USERPROFILE%\Desktop\Quick Calc.lnk"
set "target=C:\Windows\System32\calc.exe"
set "hotkey=CTRL+ALT+C"
powershell -command ^
"$ws = New-Object -ComObject WScript.Shell; ^
$sc = $ws.CreateShortcut('%shortcut%'); ^
$sc.TargetPath = '%target%'; ^
$sc.Hotkey = '%hotkey%'; ^
$sc.Save()"
echo [OK] Calculator shortcut with hotkey %hotkey% created.
pause
Removing a Hotkey from a Shortcut
To remove an assigned hotkey, set the Hotkey property to an empty string.
@echo off
set "shortcut=%USERPROFILE%\Desktop\My Application.lnk"
> "%temp%\rmhotkey.vbs" (
echo Set ws = CreateObject("WScript.Shell"^)
echo Set sc = ws.CreateShortcut("%shortcut%"^)
echo sc.Hotkey = ""
echo sc.Save
)
cscript /nologo "%temp%\rmhotkey.vbs"
del "%temp%\rmhotkey.vbs"
echo [OK] Hotkey removed.
pause
Complete Hotkey Manager Script
This interactive tool manages hotkey assignments for desktop shortcuts.
@echo off
title Shortcut Hotkey Manager
setlocal enabledelayedexpansion
:menu
cls
color 0F
echo =============================================
echo SHORTCUT HOTKEY MANAGER
echo =============================================
echo.
echo [1] Create shortcut with hotkey
echo [2] Add hotkey to existing shortcut
echo [3] Remove hotkey from shortcut
echo [4] List desktop shortcuts
echo [5] Exit
echo.
set "opt="
set /p "opt=Select: "
if "!opt!"=="1" (
echo.
set "sc_name="
set /p "sc_name=Shortcut Name: "
if not defined sc_name goto menu
set "sc_target="
set /p "sc_target=Target .exe: "
if not defined sc_target goto menu
set "sc_hotkey="
set /p "sc_hotkey=Hotkey (e.g., CTRL+ALT+T): "
if not defined sc_hotkey goto menu
> "%temp%\hk_create.vbs" (
echo Set ws = CreateObject("WScript.Shell"^)
echo Set sc = ws.CreateShortcut("%USERPROFILE%\Desktop\!sc_name!.lnk"^)
echo sc.TargetPath = "!sc_target!"
echo sc.Hotkey = "!sc_hotkey!"
echo sc.Save
)
cscript /nologo "%temp%\hk_create.vbs"
del "%temp%\hk_create.vbs"
echo [OK] Created "!sc_name!" with hotkey !sc_hotkey!.
pause
goto menu
)
if "!opt!"=="2" (
echo.
echo --- Desktop Shortcuts ---
dir /b "%USERPROFILE%\Desktop\*.lnk" 2>nul
echo.
set "sc_file="
set /p "sc_file=Shortcut filename (with .lnk): "
if not defined sc_file goto menu
set "sc_hotkey="
set /p "sc_hotkey=Hotkey to assign: "
if not defined sc_hotkey goto menu
if not exist "%USERPROFILE%\Desktop\!sc_file!" (
echo [ERROR] Shortcut not found.
pause
goto menu
)
> "%temp%\hk_set.vbs" (
echo Set ws = CreateObject("WScript.Shell"^)
echo Set sc = ws.CreateShortcut("%USERPROFILE%\Desktop\!sc_file!"^)
echo sc.Hotkey = "!sc_hotkey!"
echo sc.Save
)
cscript /nologo "%temp%\hk_set.vbs"
del "%temp%\hk_set.vbs"
echo [OK] Hotkey assigned.
pause
goto menu
)
if "!opt!"=="3" (
echo.
echo --- Desktop Shortcuts ---
dir /b "%USERPROFILE%\Desktop\*.lnk" 2>nul
echo.
set "sc_file="
set /p "sc_file=Shortcut filename (with .lnk): "
if not defined sc_file goto menu
if not exist "%USERPROFILE%\Desktop\!sc_file!" (
echo [ERROR] Shortcut not found.
pause
goto menu
)
> "%temp%\hk_rm.vbs" (
echo Set ws = CreateObject("WScript.Shell"^)
echo Set sc = ws.CreateShortcut("%USERPROFILE%\Desktop\!sc_file!"^)
echo sc.Hotkey = ""
echo sc.Save
)
cscript /nologo "%temp%\hk_rm.vbs"
del "%temp%\hk_rm.vbs"
echo [OK] Hotkey removed.
pause
goto menu
)
if "!opt!"=="4" (
echo.
echo --- Desktop Shortcuts ---
dir /b "%USERPROFILE%\Desktop\*.lnk" 2>nul
echo.
pause
goto menu
)
if "!opt!"=="5" exit /b
goto menu
Practical Use Cases
CTRL+ALT+T: Launch Command Prompt or TerminalCTRL+ALT+E: Open File ExplorerCTRL+ALT+B: Open default browserCTRL+ALT+S: Open VS Code or preferred editorCTRL+ALT+P: Open PowerShell
Best Practices
- Place shortcuts on the Desktop or Start Menu for hotkeys to be registered by Windows.
- Use explicit modifier strings like
CTRL+ALT+Xinstead of justX. - Avoid conflicts with existing system shortcuts (e.g.,
CTRL+ALT+DEL). - Document assigned hotkeys in a text file or README for team deployments.
- Test immediately after assignment to verify the hotkey works globally.
Conclusion
Assigning hotkeys to shortcuts in Batch Script is a powerful productivity enhancement. By using the WScript.Shell COM object to set the Hotkey property, you can create instant-access keyboard shortcuts for any application. The key is ensuring the shortcut resides in a supported location (Desktop or Start Menu) and that the chosen key combination does not conflict with existing shortcuts. With this technique, launching your most-used tools becomes as fast as pressing three keys.