ni.com is currently experiencing unexpected issues.

Some services may be unavailable at this time.

取消
显示结果 
搜索替代 
您的意思是: 

programmatically launching a file with the default windows application

已解决!
转到解答

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 项奖励
1 条消息(共 10 条)
8,598 次查看

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 项奖励
2 条消息(共 10 条)
8,590 次查看

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 项奖励
3 条消息(共 10 条)
8,578 次查看
解答
已被主题作者 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.

4 条消息(共 10 条)
8,567 次查看

@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 项奖励
5 条消息(共 10 条)
8,565 次查看

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 项奖励
6 条消息(共 10 条)
8,553 次查看

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
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
7 条消息(共 10 条)
8,524 次查看

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.

8 条消息(共 10 条)
8,488 次查看

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 项奖励
9 条消息(共 10 条)
7,783 次查看
解答
接受人 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.

10 条消息(共 10 条)
7,763 次查看