Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a shortcut with a batch file

Tags:

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.

like image 492
Isaac Avatar asked Jul 12 '16 01:07

Isaac


People also ask

How do I run a shortcut in a batch file?

Right-click the desktop and select New > Shortcut. Choose a location, ideally the same as your batch file, and click Next. Then enter a name for the shortcut and click Finish. Now right-click your new shortcut file, select Properties, and update the Target field to point to your batch file.

How do I run a shortcut from the command line?

Run the application using a shortcut to cmd /kRight-click where you want the shortcut created and choose New → Shortcut. Type cmd.exe /k string , where string is the command you want to execute, then click Next. Give the shortcut an appropriate name and click Finish.

How do you make a batch file that opens multiple programs?

To do this, go to File > Save As, navigate to the desktop, and type the name of your shortcut followed by . bat (for example, Chrome and Steam. bat) in the File name field. In the Save as type field, click the dropdown menu and select All files.


2 Answers

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.

like image 147
Anon Coward Avatar answered Sep 20 '22 18:09

Anon Coward


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 
like image 21
npocmaka Avatar answered Sep 19 '22 18:09

npocmaka