Skip to main content

How to Create a Desktop Shortcut with Custom Arguments in Batch Script

Creating desktop shortcuts programmatically is a fundamental skill for any developer working on deployment scripts, installer utilities, or system configuration tools. While Windows provides a graphical way to create shortcuts, doing it from a Batch Script allows for automation and customization at scale. In this guide, we will learn how to create .lnk shortcut files that include custom command-line arguments, working directories, and other properties.

This technique is especially useful for launching applications with specific configurations, such as opening a browser to a particular URL or starting a tool with predefined flags.

Why Batch Cannot Create Shortcuts Directly

Batch Script does not have a native command for creating .lnk files. The Windows shortcut format is a binary file structure that cannot be generated with echo or copy. Instead, we use one of two helper methods:

  1. VBScript via WScript.Shell COM object (most common and reliable).
  2. PowerShell via the same COM object (modern alternative).

Both approaches create a small helper script that Batch invokes, and then cleans up afterward.

The WScript.Shell COM object provides a CreateShortcut method that supports all shortcut properties.

Basic Shortcut Creation

@echo off
setlocal

set "shortcut=%USERPROFILE%\Desktop\My App.lnk"
set "target=C:\Program Files\MyApp\app.exe"

> "%temp%\mksc.vbs" (
echo Set ws = CreateObject("WScript.Shell"^)
echo Set sc = ws.CreateShortcut("%shortcut%"^)
echo sc.TargetPath = "%target%"
echo sc.Save
)

cscript /nologo "%temp%\mksc.vbs"
del "%temp%\mksc.vbs"

echo [OK] Shortcut created on Desktop.
pause

Adding Custom Arguments

The key property is sc.Arguments. This is where you pass command-line flags, parameters, or any additional text that should be appended when the shortcut is launched.

@echo off
setlocal

set "shortcut=%USERPROFILE%\Desktop\Chrome Incognito.lnk"
set "target=C:\Program Files\Google\Chrome\Application\chrome.exe"
set "args=--incognito --new-window https://example.com"

> "%temp%\mksc.vbs" (
echo Set ws = CreateObject("WScript.Shell"^)
echo Set sc = ws.CreateShortcut("%shortcut%"^)
echo sc.TargetPath = "%target%"
echo sc.Arguments = "%args%"
echo sc.Save
)

cscript /nologo "%temp%\mksc.vbs"
del "%temp%\mksc.vbs"

echo [OK] Shortcut with arguments created.
pause

When the user double-clicks "Chrome Incognito" on the desktop, it launches Chrome in incognito mode and navigates to https://example.com.

Understanding Shortcut Properties

The CreateShortcut method exposes several configurable properties:

PropertyDescriptionExample
TargetPathThe executable or file to launchC:\app\tool.exe
ArgumentsCommand-line arguments--verbose --port 8080
WorkingDirectoryThe starting directory for the programC:\app\data
IconLocationCustom icon path and indexshell32.dll, 3
WindowStyleWindow state: 1=Normal, 3=Maximized, 7=Minimized1
DescriptionTooltip text shown on hoverLaunch my tool
HotkeyKeyboard shortcut to launchCTRL+ALT+T
@echo off
setlocal

set "shortcut=%USERPROFILE%\Desktop\Dev Server.lnk"
set "target=C:\Python39\python.exe"
set "args=-m http.server 8080"
set "workdir=C:\Projects\MyWebsite"
set "icon=C:\Python39\python.exe, 0"
set "desc=Start local development server on port 8080"

> "%temp%\mksc.vbs" (
echo Set ws = CreateObject("WScript.Shell"^)
echo Set sc = ws.CreateShortcut("%shortcut%"^)
echo sc.TargetPath = "%target%"
echo sc.Arguments = "%args%"
echo sc.WorkingDirectory = "%workdir%"
echo sc.IconLocation = "%icon%"
echo sc.WindowStyle = 1
echo sc.Description = "%desc%"
echo sc.Save
)

cscript /nologo "%temp%\mksc.vbs"
del "%temp%\mksc.vbs"

echo [OK] Full shortcut created.
pause

This creates a shortcut that:

  • Launches Python's built-in HTTP server.
  • Serves files from C:\Projects\MyWebsite.
  • Uses the Python icon.
  • Shows a descriptive tooltip on hover.

Common Mistakes

The Wrong Way: Putting Arguments in TargetPath

:: WRONG - arguments should not be in TargetPath
echo sc.TargetPath = "C:\app\tool.exe --verbose"

Output Concern: Windows will try to find an executable literally named tool.exe --verbose, which does not exist. The shortcut will be broken and display an error when launched.

The Correct Way: Separate TargetPath and Arguments

:: CORRECT
echo sc.TargetPath = "C:\app\tool.exe"
echo sc.Arguments = "--verbose"

Always keep the executable path in TargetPath and everything else in Arguments.

The Wrong Way: Forgetting to Escape Parentheses

:: WRONG - unescaped parentheses break Batch parsing
echo Set ws = CreateObject("WScript.Shell")

Output Concern: Batch interprets the closing parenthesis ) as the end of an IF or FOR block, causing a syntax error.

The Correct Way: Using the Caret Escape

:: CORRECT
echo Set ws = CreateObject("WScript.Shell"^)

The caret ^ before ) tells Batch to treat it as a literal character.

tip

Always escape parentheses with ^ when writing VBScript inside a Batch ( ... ) block. This is the most common source of errors when generating VBS from BAT files.

Method 2: Using PowerShell

If you prefer PowerShell or need to avoid VBScript, the same COM object is accessible from PowerShell.

@echo off
set "shortcut=%USERPROFILE%\Desktop\MyTool.lnk"
set "target=C:\Tools\mytool.exe"
set "args=--config production"

powershell -command ^
"$ws = New-Object -ComObject WScript.Shell; ^
$sc = $ws.CreateShortcut('%shortcut%'); ^
$sc.TargetPath = '%target%'; ^
$sc.Arguments = '%args%'; ^
$sc.WorkingDirectory = 'C:\Tools'; ^
$sc.Save()"

echo [OK] Shortcut created via PowerShell.
pause
info

PowerShell is available on all Windows 10 and later systems. For Windows 7 compatibility, prefer the VBScript method.

Creating Multiple Shortcuts at Once

For deployment scenarios, you might need to create several shortcuts programmatically.

@echo off
setlocal enabledelayedexpansion

:: Define shortcuts: Name|Target|Arguments
set "s1=Notepad|C:\Windows\notepad.exe|"
set "s2=Calculator|C:\Windows\System32\calc.exe|"
set "s3=CMD Admin|C:\Windows\System32\cmd.exe|/k echo Running as admin"
set "s4=Event Viewer|C:\Windows\System32\eventvwr.msc|"

for %%i in (1 2 3 4) do (
for /f "tokens=1,2,3 delims=|" %%a in ("!s%%i!") do (
set "name=%%a"
set "exe=%%b"
set "arg=%%c"

> "%temp%\mksc_%%i.vbs" (
echo Set ws = CreateObject("WScript.Shell"^)
echo Set sc = ws.CreateShortcut("%USERPROFILE%\Desktop\!name!.lnk"^)
echo sc.TargetPath = "!exe!"
echo sc.Arguments = "!arg!"
echo sc.Save
)

cscript /nologo "%temp%\mksc_%%i.vbs"
del "%temp%\mksc_%%i.vbs"
echo [OK] Created: !name!
)
)

echo.
echo All shortcuts created.
pause

Complete Shortcut Manager Script

@echo off
title Desktop Shortcut Creator
setlocal enabledelayedexpansion

:menu
cls
color 0F
echo =============================================
echo DESKTOP SHORTCUT CREATOR
echo =============================================
echo.
echo [1] Create a custom shortcut
echo [2] Create shortcut with arguments
echo [3] List desktop shortcuts
echo [4] Remove a desktop shortcut
echo [5] Exit
echo.
set "opt="
set /p "opt=Select: "

if "!opt!"=="1" goto create_basic
if "!opt!"=="2" goto create_args
if "!opt!"=="3" goto list_shortcuts
if "!opt!"=="4" goto remove_shortcut
if "!opt!"=="5" exit /b
goto menu

:create_basic
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 Path (.exe): "
if not defined sc_target goto menu

> "%temp%\sc_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.Save
)
cscript /nologo "%temp%\sc_create.vbs"
del "%temp%\sc_create.vbs"
echo [OK] Shortcut "!sc_name!" created.
pause
goto menu

:create_args
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 Path (.exe): "
if not defined sc_target goto menu
set "sc_args="
set /p "sc_args=Arguments: "
set "sc_workdir="
set /p "sc_workdir=Working Directory (or leave empty): "
set "sc_desc="
set /p "sc_desc=Description/Tooltip (or leave empty): "

> "%temp%\sc_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.Arguments = "!sc_args!"
if defined sc_workdir echo sc.WorkingDirectory = "!sc_workdir!"
if defined sc_desc echo sc.Description = "!sc_desc!"
echo sc.Save
)
cscript /nologo "%temp%\sc_create.vbs"
del "%temp%\sc_create.vbs"
echo [OK] Shortcut "!sc_name!" created with arguments.
pause
goto menu

:list_shortcuts
echo.
echo --- Desktop Shortcuts ---
dir /b "%USERPROFILE%\Desktop\*.lnk" 2>nul
echo.
pause
goto menu

:remove_shortcut
echo.
set "del_name="
set /p "del_name=Shortcut name to remove (without .lnk): "
if not defined del_name goto menu
if exist "%USERPROFILE%\Desktop\!del_name!.lnk" (
del "%USERPROFILE%\Desktop\!del_name!.lnk"
echo [OK] Removed.
) else (
echo [NOT FOUND]
)
pause
goto menu

Best Practices

  1. Always separate TargetPath from Arguments: Never combine them in a single property.
  2. Escape parentheses with ^ when embedding VBScript inside Batch echo blocks.
  3. Clean up temporary VBS files immediately after use with del.
  4. Use %USERPROFILE%\Desktop instead of hardcoding the Desktop path, as it adapts to any user account.
  5. Set WorkingDirectory whenever the application depends on relative file paths to function correctly.

Conclusion

Creating desktop shortcuts with custom arguments in Batch Script is a practical technique that bridges the gap between manual setup and full automation. By leveraging the WScript.Shell COM object through VBScript or PowerShell, you gain full control over every aspect of the shortcut, from the target executable and arguments to the icon and window style. This approach is essential for deployment scripts, installer packages, and any scenario where user environments need to be configured programmatically.