views:

36

answers:

3

I see how to launch many other programs from a batch file, but I can't find a command like open on Mac OS X. Does such a tool exist on Windows? Powershell, or a Windows API call from an executable would also work.

+1  A: 

In Windows you can open Explorer with the following command:

C:\Users\Leniel>start %windir%\explorer.exe

If you want it to open a specific folder, do this for example:

C:\Users\Leniel>start %windir%\explorer.exe "C:\Users\Leniel\Desktop"
Leniel Macaferi
whooooo exactly what i needed. right under my nose, too. :)
Robert Karl
You can usually omit the explorer entirely: `start "c:\mydir"`
the_mandrill
Also when launching a GUI program `start` is entirely unneeded. Furthermore, `explorer` is in the `%PATH%`, so `explorer someDir` suffices in any case.
Joey
@mandrill: That would launch another console window with `c:\mydir` as its title ;-)
Joey
A: 

explorer.exe path/to/folder ?

jeroenh
Correct, just put quotes around the path - in case of spaces within... and it works with just 'explorer' too.
djn
+1  A: 

The direct equivalent of OS X's open is start in cmd.

start foo.txt

would launch Notepad (or whatever text editor you're using),

start http://example.com

would launch your browser,

start \someDirectory

will launch Explorer, etc.

Care has to be taken with arguments in quotes, as start will interpret the first quoted argument as the window title to use, so something like

start "C:\Users\Me\Folder with spaces\somedocument.docx"

will not work as intended. Instead prepend an empty quoted argument in that case:

start "" "C:\Users\Me\Folder with spaces\somedocument.docx"

Note that start isn't a separate program but a shell-builtin. So to invoke this from an external program you have to use something like

cmd /c start ...

The equivalent in PowerShell is either Start-Process or Invoke-Item. The latter is probably better suited for this task.

Invoke-Item foo.txt  # launches your text editor with foo.txt
Invoke-Item .        # starts Explorer in the current directory

As for the Windows API, you're looking for ShellExecute with the open verb.

Joey