Run a shortcut with a batch file

79,182

Solution 1

The help for start contains this tidbit:

START ["title"] [/D path] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
      [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
      [/NODE <NUMA node>] [/AFFINITY <hex affinity mask>] [/WAIT] [/B]
      [command/program] [parameters]

    "title"     Title to display in window title bar.

In other words the first quoted string will be used for the title. To launch something with quotes, you need to provide a quoted string before it, like this:

start "" "C:\Program Files (x86)\Steam\user1.lnk"

Since it's not a program with a console window, the contents don't matter, they won't be used.

Solution 2

One more possible approach is to get the target property of the shortcut and run it. Here's how to do it with shortcutjs.bat

setlocal
for /f "tokens=1,* delims=:" %%a in (
  'shortcutjs.bat'
) do (
  set "%%~a=%%~b"
)
echo target is %target%
call %target%
endlocal
Share:
79,182

Related videos on Youtube

Isaac
Author by

Isaac

Updated on November 11, 2020

Comments

  • Isaac
    Isaac over 3 years

    I am trying to set up multiple steam accounts, and you can instantly launch an account by making a shortcut for it, blah blah blah. The shortcuts works fine but I want to make a batch file to select which account to use, then launch the shortcut for that account. For some reason I can't find out how to launch a shortcut from a batch file. I have searched and searched but I cannot find how. Everything seems to work up until launching the shortcut which does nothing.

    Here is my code

        @echo off
        echo Which steam account to use?
        echo ---------------------------
        cd "C:\Program Files (x86)\Steam"
        TIMEOUT 2 >null
        echo 1. user1
        TIMEOUT 2 >null
        echo 2. user2
        set /p account="Select a number. "
        echo %account%
        TIMEOUT 2 >null
        if %account%==1 (
            echo Account "user1" selected.
            TIMEOUT 3 >null
            start "C:\Program Files (x86)\Steam\user1.lnk"
            )
        IF %account%==2 (
            echo Account "user2" selected.
            TIMEOUT 3 >null
            start "C:\Program Files (x86)\Steam\user2.lnk"
            )
    

    Running Windows 8.

    • Admin
      Admin almost 8 years
      The first set of quotes in a start command line is the WINDOWS TITLE. So start "" "c:\etc\etc.lnk" for a blank window title, or stick something between first set of quotes. This is a very common question.