LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to programmatically detect whether my application is an executable?

I wrote an application that I would like to run both as an executable and directly in LabVIEW. When the program runs, I need to load a .cfg file from the directory in which the .vi or .exe file resides. I used the "Current VI's Path" block to detect this location. For the non-.exe execution mode, the Current VI's Path is the folder path and "/VIName.vi" (c:\path\VIName.exe), so I simply strip off one section add the .cfg file name and everything is happy. When I built an executable, the file would not load. I soon discovered it was because for an executable, the Current VI's Path returns the folder path and "\Application.exe\VIName.vi" (c:\path\Application.exe\VIName.vi) so I would need to strip it down twice and add the .cfg file name to have the program work correctly.

I did consider deleting everything from ".exe\" to the end of the path. This would work fine under most circumstances because it would not detect any ".exe\" when I am running the .vi file in LabVIEW(leaving c:\path\VIName.vi), and it would strip off the VIName when I am running as an executable (leaving c:\path\Application). In either of these circumstances, I would simply Strip Path once and add my .cfg file name. The problem is that Windows allows periods in its folder names, so if someone sees fit end a folder name in the path of the .vi or .exe in ".exe", neither the .vi or the .exe will work properly.

Is there any way to programmatically detect whether my program running as a .vi in LabVIEW or as a .exe?

Thanks for the help
Russ
Message 1 of 8
(3,041 Views)
Hi,

I think you can use the VI property node and select Application>>Kind - If it is a Run time system, it means it is an EXE. Look at the attachment file.

Hope it helps you.

Thanks,
Logic
Message 2 of 8
(3,035 Views)
Hello,

If I may, I would like to give you a little tip even with my bad English.
I very often need the "Application directory" but don't want to bother if I'm in an executable or not. What I recommend you is to put your VI in an llb so that you always need to strip path twice from the "Current VI's path".

Example : C:\path\Myllb.llb\MyVI.vi becomes in an executable C:\path\MyEXE.exe\MyVI.vi if you strip the path twice you always get the application directory.

Hope this helps !
Julien
0 Kudos
Message 3 of 8
(2,986 Views)
I'm not so sure that's a good tip. An entire llb can get corrupted by a bad VI. It's not common but I have seen it happen. When it does happen, you better hope that you have a recent backup.
Message 4 of 8
(2,982 Views)
I agree. Doesn't happen very often, but it happened to me last night. About 10 hours worth of work went south. That is the first time it has ever happened to me. How frustrating!!! LV just chokes when I try to load it.

The property node works like a champ, though.
Thanks
0 Kudos
Message 5 of 8
(2,972 Views)
Let me second Dennis' comment.

"And now for something completely different" (M. Python circa 1970)

I use a different approach to getting the folder spec.

See attached jpg.

This sub-VI repeatedly strips a path until it finds the folder spec.

This approach works in all environments including dynamically loaded VI in exe's.

It should also be cross platform compatible, but alas I can not say that I have ever tried it outside a Windows environment.

This method does not require any property nodes which can affect the thread the VI runs in.

Offering another approach,

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 6 of 8
(2,960 Views)
That is a cool idea. I have a question, though. How do property nodes affect the thread?
Message 7 of 8
(2,917 Views)
So you noticed the fine print did you?

Property nodes execute in the User Interface Thread.

I never heard of an exception, nor have I noticed anything to contradict this statement.

If anyone can enlighten me otherwise, please do so!

Personal desire:
To be able to dictate which thread a call by reference will execute in.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 8 of 8
(2,908 Views)