Example Code

Use user32.dll and shell32.dll to Open, Edit, Print, Explore, and Find Files Based on Windows Defaults

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

The example demonstrates how to open the default program in Windows for a specified file.

 

Description

This application calls the user32.dll and shell32.dll in Microsoft Windows to open, edit, print, explore, and find files based on the default application for that file type.
For example, if you open a *.avi file Windows will open that file with the default application for that file type. On many computers that may be the Windows Media Player.
 

Requirements

 Software

  • LabVIEW 2012 Base Development System (or compatible) (Windows operating system)
  • Windows 7 (32bit or 64bit) (or compatible)

 Hardware

  • No hardware is necessary to use this example VI

 

Steps to Implement or Execute Code

  1. Open the attached file
  2. Select the path of the file you want to open, edit, ...
  3. Select the operation to be performed
  4. (Optional) Specify parameters for the action to be executed. Refer to the Microsoft MSDN whether and which parameters are necessary
  5. (Optional) Select the 'Flag' on how the window that is going to be opened is displayed
  6. Run the VI
  7. Depending on your Windows settings the program that is registered as the default program for a certain operation is being opened

 

Additional Information or References

Execute default Windows operation for specified file - Front Panel.png

 

Execute default Windows operation for specified file - Block Diagram.png

 

This example works on windows operating systems only. The call library function node is calling Microsoft Windows specific libraries that do not exist on other operating systems.

 

Microsoft MSDN: ShellExecute function (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/bb762153(v=vs.85).aspx

 

**The code for this example has been edited to meet the new Community Example Style Guidelines. The edited copy is marked with the text 'NIVerified'. Read here for more information about the new Example Guidelines and Community Platform.**

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
MikeS81
Proven Zealot
Proven Zealot
on

Nice code,

thanks for posting it.

Bruno_Cesar
NI Employee (retired)
on

Useful example. Tested in LabVIEW 2015 and Windows 7 x64 and still works fine. Please keep this post live.