06-04-2014 08:23 AM
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?
Solved! Go to Solution.
06-04-2014 08:35 AM - edited 06-04-2014 08:37 AM
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.
06-04-2014 08:45 AM - edited 06-04-2014 08:52 AM
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.
06-04-2014 08:51 AM
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.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
16 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
06-04-2014 08:52 AM - edited 06-04-2014 08:58 AM
@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 😄
06-04-2014 08:57 AM
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.
06-04-2014 09:34 PM
vi.lib\Platform\browser.llb\Open URL in Default Browser.vi opens any file in whatever is the default application for that file ending.
06-05-2014 09:00 AM
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.
01-02-2018 06:37 PM
Thanks Brother
That vi just made me look good! You should fix the browse options on the file path control.
01-03-2018 07:32 AM
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.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
16 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord