LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

programmatically launching a file with the default windows application

Solved!
Go to solution

I had assumed this would be a trivial task, but I can't seem to be able to find anything on it.  I would like to be able to open any file in the native application - as if the user had double clicked on it.  Any suggestions?

0 Kudos
Message 1 of 10
(6,061 Views)

What do you mean by "open any file"?  Do you mean a word document for instance?  Or just running an exe?

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``

 

You can likely use a call to System Exec VI.  (May need some parameters depending on what file/task you want to run.)

 

Executes a system command. Use the System Exec VI to execute or launch other Windows–based applications or Linux command-line applications from within VIs. With the System Exec VI, you execute a system-level command line that can include any parameters supported by the application you want to launch.

 

 

If you need a more advanced call to a program, I would just wrap all your commands in a .bat (batch file) and just call that vis System Exec.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
0 Kudos
Message 2 of 10
(6,053 Views)

I don't mean open a file. I also don't mean running a simple dos command.  I mean finding the default windows application for a specified file extension, and telling windows to load up that file in that default application. There is a function that is part of the Windows API, ShellExecute, that would do it - but I was hoping there was something more native to LV.

 

Edit: To be more clear, the reason I don't want to rely on the ShellExecute is that the function parameters require me to feed in a pointer to a structure ... and that gets messy.

0 Kudos
Message 3 of 10
(6,041 Views)
Solution
Accepted by topic author BowenM

Attached is a VI I use that does what you want.  If the path given is a folder then it opens a file explorer window to that folder.  If the path is a file then it opens the file as if the user double clicked on it.  It uses the command line function mentioned earlier.

Message 4 of 10
(6,030 Views)

@BowenM wrote:

I don't mean open a file. I also don't mean running a simple dos command.  I mean finding the default windows application for a specified file extension, and telling windows to load up that file in that default application. There is a function that is part of the Windows API, ShellExecute, that would do it - but I was hoping there was something more native to LV.


ShellExecute functionality can be accomplished via DOS 😛  But that is beside the point.

 

I do not know of a native way in LabVIEW to do something similar without using the System Exec VI, so perhaps wait for a more elegant answer from someone with more insight than I, but you could always just call the .dll and actually use ShellExecute if you like that better than my earlier suggestion.

 

EDIT:

 


@Hooovahh wrote:

Attached is a VI I use that does what you want.  If the path given is a folder then it opens a file explorer window to that folder.  If the path is a file then it opens the file as if the user double clicked on it.  It uses the command line function mentioned earlier.


 

I would recommend changing the front panel Folder Browser object to allow both Files and Folders.  But this is exactly what I was trying to describe above.  Kudos for the nifty VI implementation 😄

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
0 Kudos
Message 5 of 10
(6,028 Views)

Oh!  I figured there may be a DOS command that did it, which is what i was looking for. I was dreading calling the API directly because it always seems to be a pain in labview.  That works perfectly, Hooovahh - thank you.

0 Kudos
Message 6 of 10
(6,016 Views)

vi.lib\Platform\browser.llb\Open URL in Default Browser.vi opens any file in whatever is the default application for that file ending.

Rolf Kalbermatter
My Blog
Message 7 of 10
(5,987 Views)

Thank you, Rolf.  One thing to ntoe:  That VI will change any space character in the string to "%20".  The VI you actually want to call is the "Open URL in Default Browser core.vi".  Still a nice solution.

Message 8 of 10
(5,951 Views)

Thanks Brother 

 

That vi just made me look good!  You should fix the browse options on the file path control.


"Should be" isn't "Is" -Jay
0 Kudos
Message 9 of 10
(5,246 Views)
Solution
Accepted by JÞB

Oh how right you are.  Attached is a new version with the browse button selecting folders or files, and a new feature which allows for opening an explorer window to a folder where a file is located, and selecting that file.  I think I've only ever used this feature once but I like it for feature parity with the folder selecting option.

Message 10 of 10
(5,226 Views)