17

On Windows XP, how does one open a file with its default application from the command line?

As far as I know, this should work from a command prompt or batch file:

start "path to my file"

Unfortunately in my case, this only opens a new command prompt window for most file types. (It does work for .exe file though...)

20

Try this.

START "" "path to my file"

The START command treats the first set of "" as the text to use for the title of the window, so just include an empty pair.

  • How can I make this work for opening PowerShell via a command in batch file? Right now, nothing happens when it hits the line powershell or powershell.exe. when I make it start powershell or start powershell.exe nothing happens. – Ungeheuer Jul 13 '17 at 1:41
  • Does this work on all versions of Windows or is there a minimum version? – binki May 22 '18 at 20:09
  • It works on all versions I believe...as far back as Windows 95 any way. I'm not sure about versions before that. – aphoria May 23 '18 at 11:42
9
explorer "filename"

works for xp and other windows (95 or higher) If it does not work, you haven't associated that extention type with a program.

  • 1
    This also works well if you use Bash on Windows: explorer.exe "filename" – Daniel Arthur May 28 '18 at 18:55
  • This is what I came looking to do. It works nicely with some alias too, e.g. alias open="explorer.exe" lets you just call open file.txt. – Nathan Feb 18 at 17:38
9

Don't use START. Just type the name of the file. readme.txt opens readme.txt in Notepad (or in whatever default .txt handler you have in place).

Note that if there are spaces in the name, you must handle them. A good way is to use double quotes. "read me.txt"

  • 1
    Under windows 7, you need the START command. – Gerrit Jun 17 '14 at 8:08
  • 2
    @Gerrit No, you don't. If the program in question is in your path and your default handlers are set up properly, all you have to do it provide the path and file name and it will open. – kmort Jun 17 '14 at 11:46
3

Using PowerShell

Start-Process "<fullname>"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.