I have two files in the same folder that I'd like to run. One is a .txt
file, and the other is the program shortcut to an .exe
. I'd like to make a batch file in the same location to open the text file and the shortcut then close the batch file (but the text file and program remain open).
I tried this with no luck:
open "myfile.txt" open "myshortcut.lnk"
Also didn't work:
start "myfile.txt" start "myshortcut.lnk"
If you want to use a custom file icon for your batch file, we recommend using a shortcut. 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.
Type "start [filename.exe]" into Command Prompt, replacing "filename" with the name of your selected file. Replace "[filename.exe]" with your program's name. This allows you to run your program from the file path.
To open the BAT file in Notepad, right-click it and choose Show more options > Edit from the menu (or just Edit in some Windows versions). You might find it helpful to use more advanced text editors that support syntax highlighting when editing a BAT file.
In the Windows Command shell, type is a built in command which displays the contents of a text file. Use the type command to view a text file without modifying it. In PowerShell, type is a built-in alias to the Get-Content cmdlet, which also displays the contents of a file, but using a different syntax.
How to start Windows files and programs from a batch file. To run Microsoft Windows programs or file, use the START command. The example below would run Windows Notepad. You can also specify the direct location of the file by typing the following command.
To start a Windows file, use the start command followed by the name of the file. In the example below, we have a start command that is starting the chdown.txt file in the default text editor and then also sounding an alarm MP4 audio file in the default media player. start chdown.txt && alarm.mp4.
Browse to where the file is stored and right click and drag the file to the desktop. Because you right clicked a menu will open with create short cut here option. Select that and the shortcut will be created. Right click on the icon and select properties to open a settings dialogue box.
As long as Windows knows how to open a file, you can use the start command with any file. For example, you could use the start command to open a movie file, video file, Word document, Excel file, and any other file. How to make a batch file. See the start command for further information. Batch file help.
This would have worked too. The first quoted pair are interpreted as a window title name in the start command.
start "" "myfile.txt" start "" "myshortcut.lnk"
I was able to figure out the solution:
start notepad "myfile.txt" "myshortcut.lnk" exit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With