From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Quiting applications gracefully from within LV

Hello,

 

Attached is an example VI that can be used to open and close a third party application. It does this using the System Exec vi and the windows comand line 'tskill'. The VI will prompt the user to go back to the application and save any changes.

 

Is there an alternative comand line or method which will close the application gracefully, so it asks the user to save changes directly (the same as when the application is quit manually or it is closed by windows shutting down)?

 

I am using XP sp3 and LV 8.6 (not very familiar with Windows comand lines etc though).

 

Thanks,

 

Blue 

0 Kudos
Message 1 of 10
(3,068 Views)

Help! Anyone any suggestions/advice?

 

Thx, Blue 

0 Kudos
Message 2 of 10
(3,025 Views)
There is no alternative command line. As far as an alternative method, that depends on the application. If the application has an ActiveX interface (like Excel) then you should use that method. If it does not then you can simulate sending keystrokes to emulate selecting menu options. You can also simulate pressing mouse buttons. Search this forum, as this question comes up a lot. There's a lot of examples on simulating keystrokes and mouse buttons using the Windows API.
Message 3 of 10
(3,012 Views)

Thanks for the reply and the pointers.

After looking at sample VIs i have managed to get simulated key strokes to the required application. However this approach requires the intended recipient of the simulated keystrokes to be the 'top', active window.

 

It would appear to be possible to select the application/window using the user32.dll functions, 'GetWindow' or 'FindWindowA' or 'BringWindowToTop? I would prefer to send it to a known window, rather than just sending it off to the top window and hoping it is still the correct one.

 

Does anyone have any worked examples or tutorials of using these or similar commands? I've ploughed through several of the NI documents, and can see how it works in theory, but currently i am lost with the syntax... function prototypes etc.

 

Cheers,  Blue 

Message 4 of 10
(2,985 Views)
You can use the lvwutil32 library. That contains, among others, a function to bring a window to the top. You can find them if you search, or you can just get them from this post.
Message 5 of 10
(2,972 Views)

Hello smercurio thanks for that link, very welcome! i have spent the last couple of days searching for something like that with no success. It contains the building blocks to do what i need.

 

The comments below are so that hopefully some other nubie will come across the solution more easily than i did... (as search terms are easy once you know them - eg searching the forum for user32 and lvutil32 gives me no hits).

 

How to begin to interact and manipulate with third party applications and windows from a LabView VI.

The 'Call Library Function Node' alows LV to communicate with .dll (dynamic link library) files.

The Windows API .dll for interacting with desktop windows is called 'user32.dll'

Examples of LabView VIs calling user32.dll can be found in Lvutil32 at:

 

http://zone.ni.com/devzone/cda/epd/p/id/2556 

 

The VIs in Lvutil32 use both user32.dll and lvutil32.dll.

User32.dll is part of Windows.

Lvutil32.dll is not part of windows and will need to be included with any VIs that call it. 

 

For VIs using windows command lines to launch applications it is necessary to include the full path to the application. Obviously moving the application from the path will cause an error. Alternatively you can edit the 'Path' entry in Control Panel > System Properties > Advanced > Environmental Variables > System Variables > Path to include the path to the application to be launched. This will mean that only the name of the application executable is needed.

 

A great VI for experimenting sending simulated key strokes to the active application is Virtual Keyboard.vi posted at the link below by Peter (though you may need to reduce the 'Delay' input).

 

http://forums.ni.com/ni/board/message?board.id=270&message.id=839&query.id=2019#M839 

 

Comments, additions and corrections welcomed.:smileyhappy:

 

Thanks again for the support, Blue 

Message 6 of 10
(2,946 Views)

Attached is a slightly modified version of the Virtual Keyboard VI (mentioned in the previous post), called Simulated Keystroke.VI (LV8.6).  It allows simulated keystroke sequences to be generated, saved to file, and sent to the active window. The active window can be created by starting a new application, or be an already open window, made active by bringing it to the front (from within the VI). 

 

At present it is possible for user interaction to change the active window during the sending of the simulated keystrokes. This could be overcome by implementing the 'Make Window Always on Top' and 'Revoke Window Always on Top' VIs in Lvutil32.

 

Edit: (adjusted default delay timing in VI)
Message Edited by BlueTwo on 10-01-2008 07:17 AM
0 Kudos
Message 7 of 10
(2,935 Views)

Also attached is the original example VI modified to operate as i wanted, just in case it is of any interest. It uses the Lvwutil32 dll though i think someone who understands the user32 dll would be able to use just that one. Beyond me at the moment though! :smileyhappy:

thx, Blue 

0 Kudos
Message 8 of 10
(2,889 Views)

The original one is better since it doesn't use simulate key press.

 

In your previous post, you said

> I would prefer to send it to a known window, rather than just sending it off to the top window and hoping it is still the correct one.

 

 

There is another problem:

Applications like Notepad will change the window title if user saves to a file (and then keep working on it).

Without knowing the window title, you can't bring it to front, and close it using simulate key press or simulate click.

 

 There is a demo, Close External Application Window (in LabVIEW 8.6), takes care of this issue:

http://www.geocities.com/gzou999/demo.htm

 

 

George Zou

 

George Zou
0 Kudos
Message 9 of 10
(2,874 Views)

Hello George, thanks for the link to the demo. 

 

The application i want to open close  does not change it's window title, so this is not an issue in this instance, though presumably you could use the handle instead of the window name?

 

As far as i could see the Quit Application VI  (in Lvwutil32) doesn't use simulated keystrokes. Is this correct? The last posted example uses the the Quit application vi, rather than explicit simulated key strokes.

Thanks, 

Blue 

0 Kudos
Message 10 of 10
(2,852 Views)