LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

running exe opening associated extension

Solved!
Go to solution

My LabVIEW built application is associated with a specific file type in Windows:

http://social.msdn.microsoft.com/Forums/vstudio/en-US/630ed1d9-73f1-4cc0-bc84-04f29cffc13b/what-regi...

and opens double clicked file using command line argument:

http://forums.ni.com/t5/LabVIEW/passing-files-into-labview-vi-by-opening-the-file/m-p/138968/highlig...

This allows me to _launch_ my application, when user double clicks file with specified extension and process this file.

 

But it happens only if application is not running.

What should I do if I want to open the double clicked file while my program is running? 

 

Any system event happening that I can register and process?

The only way I see now is to build an intermediate  application that will be associated with extension, check if main application is running and pass arguments to it.

0 Kudos
Message 1 of 8
(5,742 Views)

Hi Alex,

 

this has been discussed before…

 

One idea is to provide an additional small executable that just takes the command line argument and sends it (by network functions) to your big, regular executable. If the big executable doesn't provide it's service (aka is not running) the small exe will start it before sending the arguments. After the argument is handed over to your exe the small exe quits…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 8
(5,731 Views)

GerdW,

This is exactly my workaround idea.

 

There was a 2003 discussion, nothing newer.

http://forums.ni.com/t5/LabVIEW/Open-executable-exe-vi-at-windows-with-specific-file/m-p/101474/high...

linking to 

http://openg.org/tiki/tiki-index.php?page=File+Handling+Guidelines:

 

"When the user double-clicks on a document, the Registration Database is checked for an entry that associates the file extension with a particular application. If an entry does not specify Dynamic Data Exchange (DDE) command, the application specified in the registry is launched. If the registry specifies to use DDE commands, an attemp is made to establish a DDE communication with that application using the application topic. If an application responds to the DDE connection, a DDE Execute command is sent to the application, as specified in the registry. However, if attempts to establish the DDE conversation fail, the specified application is launched and the DDE connection is tried again".

 

It was not possible in LabVIEW 11 years ago, Jim Kring used intermediate VB Script.  May be it can be done (has been done by) now?

VBScript and example VIs in the article are not available for download.

0 Kudos
Message 3 of 8
(5,716 Views)
Solution
Accepted by topic author Alexander_Sobolev

Alexander_Sobolev

Well, there were many discussions about it, e.g. 1, 2, 3 and in early days I have tried some ways of DDE implementation in my apps. Maybe, you could use private property of LabVIEW which is named "OS Open Document" (needs SuperSecretPrivateSpecialStuff=True string in Labview.ini for it to be visible in Events' configuration window). More info is presented here and here, and it worked for me... Also I've been searching for more elegant way and have found this article. LabVIEW has already built-in DDE server and your application may receive WM_DDE_EXECUTE message with the help of system API calls. So, I made an example of such receiver - it works when you have registered some file extension in Windows (HKEY_CLASSES_ROOT branch in the registry) and is double-clicking your file. It also works when you double-click a shortcut to your application and when you double-click your app's exe, even when it is already running. It isn't working if you registered your file extension with ddeexec key (equals to open(%1)) together with command key (equals to "Path to your app\App.exe" "%1"). But in this case the private property "OS Open Document" works! And you may even use both methods or may choose one of them.

 

For the simplicity look at these registry keys. If you registered *.ton file extension you should have

[HKEY_CLASSES_ROOT\.ton]
@="ton_auto_file"

 and

[HKEY_CLASSES_ROOT\ton_auto_file\shell\open\command]
@="\"C:\\Test\\Application.exe\" \"%1\""

 keys in the registry. In this case method 1 will work. If you add this key

[HKEY_CLASSES_ROOT\ton_auto_file\shell\open\ddeexec]
@="open(%1)"

 then method 1 won't work but method 2 ("OS Open Document") will work.

 

My test program is in the attachment (LV 2011). It requires Windows Message Queue Library (second link is for LV 2009 and greater) for DDE message interception. You may integrate message listener loop in parallel thread in your app and stop it with notifier or similar mechanism.

Message 4 of 8
(5,670 Views)

Hello,

I'm trying to open associated files with my standalone application.

 

I used the OS Open Document condition to get the file content and it works very well on my development PC (where is installed LabVIEW). But that doesn't work on another PC where I proceeded to the installation of my standalone application.

 

I generated the application with LabVIEW 2011 and I tried to add SuperSecretPrivateSpecialStuff=True in my application INI file without any change. The application is opened and focused at each double clic on an associated file.

 

Do you have any idea to solve my problem? Is there any "instruction line" to add to my INI file?

 

Thanks in advance and best regards,
Gerald

0 Kudos
Message 5 of 8
(5,358 Views)

"SuperSecretPrivateSpecialStuff=True" key in LabVIEW.ini just enables OS Open Document visibility in LabVIEW's Events config window, so it has no influence to your exe program. If your file associations don't work with exe, then double check your registry keys. It should be somewhere about the following:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.ton]
@="ton_auto_file"

[HKEY_CLASSES_ROOT\ton_auto_file\shell\open\command]
@="\"C:\\Application.exe\" \"%1\""

[HKEY_CLASSES_ROOT\ton_auto_file\shell\open\ddeexec]
@="open(%1)"

 First key sets your file extension, second one sets Open command with full path to your exe and third one sets the action to do when your files are double-clicked. You may copy the text from code block, alter it in accordance with your needs and paste to new *.reg file, then save it and execute. After that these three keys will be set in the Windows registry.

 

I have just built test exe in LV 2011 and registered my file extension. When I double-click on *.ton file I then have full path to it in my test LV application, so it seems to be successfully working.

0 Kudos
Message 6 of 8
(5,340 Views)

Thanks for your response.

It was a mistake in my registry eidtion: I wrote "ddexec" in place of "ddeexec". Now it is working perfectly.

Best regards,
Gerald

0 Kudos
Message 7 of 8
(5,299 Views)

I have found out one more way to receive WM_DDE_EXECUTE message without the need of Windows Message Queue Library. It's based on DDEML callback mechanism and looks more compact than previous variant. As it uses a callback function I have wrote one and placed it into a DLL. It's written in Delphi 7 (just for a change) and I've put the code in archive below.

And here's the LabVIEW block diagram of test app:

2015-03-01_16-19-21.jpg

Brief description:

The program registers its own callback function as DDE messages handler instead of LV's standard one. When new DDE communication is about to be established, "DDE_Callback" function is executed. It receives the message, extracts string data and sends it to LabVIEW with PostLVUserEvent function. LV application receives the message string as it is running the event structure and displays the string on the front panel. Additionally, LV app's window is brought to the screen when "activate" message arrives.

That simple algorithm works pretty well in VI and in EXE. Messages are received in all cases: when you have registered some file extension with your LV app, when you double-click a shortcut to your app or when you double-click exe file of your app when it's already running.

Note: when new callback is registered, "OS Open Document" property in Event structure is no more working! You have to restart LabVIEW to get it working with your other VIs.

 

0 Kudos
Message 8 of 8
(5,176 Views)