Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Touch Panel Registry Access Reference Library

1 ratings | 5.00 out of 5
Print

Overview

The Windows registry is a repository which stores settings and options for the operating system on Microsoft Windows targets. The LabVIEW Touch Panel Module does not include a native API for reading and writing the Windows registry. This example provides a basic API for reading and writing keys and values in the registry on a Touch panel target.

Table of Contents

  1. Theory of Operation
  2. API Description
  3. Example

Downloads

Filename: tpc_registry_install.zip
Requirements: View

Filename: tpc_registry.zip
Requirements: View

tpc_registry.zip contains the reference library described in this tutorial as well as examples of its use. Unzip the file into your <LabVIEW>\user.lib directory.

tpc_registry_install.zip contains a Windows installer that will automatically install the reference library into your LabVIEW user.lib directory. Unzip the file into an empty folder and run setup.exe.  This option is recommended for users unfamiliar with custom palettes and user.lib.

The reference library contained in these two zip files is identical.

Theory of Operation

Certain tasks which are common in touch panel applications, such as modifying the appearance of the OS or supporting multiple languages require access to the Windows Registry.  This example uses the Inline C node, which was introduced in LabVIEW 8.5, to call Windows API functions that access the registry.

API Description

The API is delivered as a LabVIEW Library which contains the following subVIs.

  • Create or Open Key
  • Delete Key
  • Set Key Value
  • Get Key Value
  • Delete Key Value
  • Close Key

Create or Open Key

This VI creates a new registry key or opens an existing key. Note that this API does not implement the registry Open function, so you must use this VI to open a reference to existing keys.

The Parent Key input determines the base key that the new subkey will be created in. The parent key can be one of the predefined values listed in the enumeration, or can be a handle to a key opened or created by a previous call to this VI.

The New Key Handle output is a handle to the newly created or opened key, while the Key Handle Out output is a replication of the Key Handle input (if any). The New Key Handle should be closed when it is no longer needed by calling the Close Registry Key VI.

Delete Key

Removes a key from the registry. Deleting a key will also remove any subkeys or values that the key contains.

The Parent Key input determines a base key that is a parent key of the subkey to be deleted. The parent key can be one of the predefined values listed in the enumeration, or can be a handle to a key opened or created by a call to the Create Registry Key VI.

Note that this VI always deletes a subkey of the parent key, and cannot delete the parent key itself. Therefore, any handle you wire to the key input must be at a higher level in the registry hierarchy than the key you want to delete.

Set Key Value

This polymorphic VI sets or creates a value on a registry key.

The Key input determines the key on which the value will be set. The key can be one of the predefined values listed in the enumeration, or more commonly, is a handle to a key opened or created by a call to the Create Registry Key VI and passed through the Key Handle input.

The Value Name input determines the name for the new value. Registry keys do not support default values, but each registry key can have one "unnamed" value. To set the unnamed value for a registry key, pass an empty string to the Value Name input.

This VI has three polymorphic instances, which are selected based upon the type of the Data input.

Set Registry Key (INT) - This VI sets an integer value in the registry. The registry generally uses DWORDs for all integers, therefore, no version of this VI is available for smaller integer types.

Set Registry Key (STR) - This VI sets a string value in the registry. This version of the function should not be used to store paths which include environment variables, such as %SystemRoot%.

Set Registry Key (PATH) - This VI also sets a string in the registry, but uses the REG_EXPAND_SZ data type, which allows the use of environment variables such as %SystemRoot%. Because environment variables are most commonly used for defining file paths, and to allow a meaningful differentiation for selecting the polymorphic type, this version of the function accepts a Path data type. However, this instance can be used to store normal strings and the STR instance can be used to store paths. Use the String to Path and Path to String functions as necessary.

Get Key Value

This polymorphic VI retrieves a value previously defined on a registry key.

The Key input determines the key on which the value resides. The key can be one of the predefined values listed in the enumeration, or more commonly, is a handle to a key opened or created by a call to the Create Registry Key VI and passed through the Key Handle input.

The Value Name input determines the name of the value to retrieve. Registry keys do not support default values, but each registry key can have one "unnamed" value. To get the unnamed value for a registry key, pass an empty string to the Value Name input.

This VI has two polymorphic instances, which must be manually selected by right-clicking on the VI or by showing the polymorphic VI selector.

Get Registry Key (INT) - This VI gets an integer value from the registry. The registry generally uses DWORDs for all integers, therefore, no version of this VI is available for smaller integer types.

Get Registry Key (STR) - This VI gets a string value from the registry. This API does not automatically expand environment variables, therefore, this VI should be used to retrieve both strings stored with the REG_SZ type and paths stored with the REG_EXPAND_SZ type. The user of this VI is responsible for resolving any environment variables returned as part of the string or path.

Delete Key Value

This polymorphic VI removes an existing value from a registry key.

The Key input determines the key which contains the value to be removed. The key can be one of the predefined values listed in the enumeration, or more commonly, is a handle to a key opened or created by a call to the Create Registry Key VI and passed through the Key Handle input.

The Value Name input determines the name of the value to remove. Registry keys do not support default values, but each registry key can have one "unnamed" value. To delete the unnamed value for a registry key, pass an empty string to the Value Name input.

Close Key

This VI closes a registry key handle opened by the Create Registry Key VI. All calls to Create Registry Key should have a corresponding Close Registry Key call.

Example


[+] Enlarge Image

This example demonstrates the use of the API to create or open keys and get or set values.  The two instances of the Create or Open Key VI create the "SOFTWARE\Microsoft\Shell" key and the "SOFTWARE\Microsoft\Shell\AutoHide" keys.  If either of these keys exists before the call, the Create Or Open Key VI returns a reference to the existing key.  Note that the first Create or Open Key VI uses the HKEY_LOCAL_MACHINE key as its parent key, whereas the second Create or Open Key VI instead uses the key reference returned by the first Create or Open Key VI as its parent key.

If either of the keys were created by this example, the example uses the Set Key Value VI to create a string value called "CreatedBy" inside of the key and to set the value to "Autohide Taskbar.vi", which is the name of the example.  Creating this value allows subsequent programs, such as the Undo Autohide Taskbar.vi example, to determine what program created this key.  This is a useful practice for reverting changes to the registry.  The reason the program creates the two keys separately, rather than just creating the "SOFTWARE\Microsoft\Shell\Autohide" key directly is so that it can maintain these CreatedBy values.  The example assumes that the "SOFTWARE" and "Microsoft" keys already exist, as they are part of a standard Windows installation.

If the AutoHide key previously existed, this example calls the Get Key Value VI to retrieve the existing value.  In the context of the example, the existing value is displayed to the user for reference, but no further action is taken with it.

Once the example has finished creating the necessary key and has performed the necessary steps to enable subsequent programs to undo its actions, it uses the Set Key Value to set the unnamed key value to 1.  Note that a registry key may have multiple values and does not have a "default" value.  However, each registry key can have an "unnamed" value.  Use an empty string for the value name to set the unnamed value.  Setting the "AutoHide" key's unnamed value to 1 hides the Windows taskbar, which is the overall purpose of the code.  This screen shot is one part of the Autohide Taskbar.vi, which is included with the Reference Library.

After Setting the value of the "AutoHide" Key, the example closes the reference to the "AutoHide" key using the Close Key VI.  The example leaves the reference to the "SOFTWARE\Microsoft\Shell" key open for the time being because it uses it to create an additional key not shown in the screen shot.

Feedback and Questions

This reference design was created by the NI Systems Engineering group. 

We do not regularly monitor Reader Comments posted on this page.

Please post your questions and comments for this reference design in the Touch Panel Registry Access discussion forum.

Please direct support questions to NI Technical Support.

Requirements


Filename: tpc_registry_install.zip

Software Requirements


Application Software: LabVIEW Professional Development System 8.5.1
Language(s): LabVIEW

Hardware Requirements


Hardware Group: HMI and Industrial PC

 
Filename: tpc_registry.zip

Software Requirements


Application Software: LabVIEW Professional Development System 8.5.1
Language(s): LabVIEW

Hardware Requirements


Hardware Group: HMI and Industrial PC

 
1 ratings | 5.00 out of 5
Print

Reader Comments | Submit a comment »

 

Legal
This example program (this "program") was developed by a National Instruments ("NI") Applications Engineer. Although technical support of this program may be made available by National Instruments, this program may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this program with each new revision of related products and drivers. THIS EXAMPLE PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).