LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I manipulate Windows environment variables in LabView?

Solved!
Go to solution
I want to create a new windows environment variable that I can manipulate using a LabView executable and then check the variable after the LV.exe completes.  Can I do this and if so, how?
0 Kudos
Message 1 of 10
(11,212 Views)

Normally you use the command "set" to set an environment variable through the command line. You can use System Exec to call "set". However, the problem you're going to have is that the existence of the variable is limited to the existence of the command window in which you run the command. This means that once you complete the execution of System Exec that sets the variable it's gone. If there's another application which is supposed to manipulate this environment variable (and it sounds like that's what you're trying to have available), then that app won't find it. You would need to set the variable as a system environment variable. The command setx can do that, though setx is not normally distributed with Windows. You need to get the Windows Resource Kit to use it. Basically what that command does is add/remove keys from the registry (specifically HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment). Thus you can use the registry VIs to add/remove keys from there.

 

 

EDIT: You can get setx from here.

Message Edited by smercurio_fc on 10-21-2008 01:26 PM
Message 2 of 10
(11,204 Views)

Be aware that the solution by smercurio_fc is restricted to users having enough rights to set system variables. Normally you need to have administrator rights to do that. Restricted users are not allowed to make changes in HKLM of the registry.

 

There is another set of environment variables which are related to the current user. These environment variables are located under HKEY_CURRENT_USER\Environment. On the other hand you need to logoff and logon until this setting will be seen (tested with the command prompt).

Message Edited by waldemar.hersacher on 10-21-2008 08:56 PM
Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
Message 3 of 10
(11,198 Views)

After a second test I wanted to edit my previous post, but time has passed.

 

The previous test was made with regedit and the command prompt. Next I used the control panel to set the environment variable and it will take effect immediatly without the need to logoff/logon. I think there is a Windows API call to set and propagate the environment variable.

Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
Message 4 of 10
(11,189 Views)

Thanks to both smercurio_fc and Waldemar.

 

Summary:

Yes, a system variable is what I want to use and I want to set it with a LV.exe which will then complete and close, and then check said variable with a separate program.  It sounds like I can use the registry VIs to set system level variables (or create a key to check, then remove) but there may be a restriction based on user privileges.  

 

I think I can get around the user privileges but I've never used the registry VIs.  Does anyone know of literature on this subject?

 

phy508

0 Kudos
Message 5 of 10
(11,177 Views)
Solution
Accepted by phyoung508
Go to Help>Find Examples... and in the Example Finder switch to the Search tab. Type in Registry and you will see three examples on how to use the registry functions.
Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
Message 6 of 10
(11,162 Views)
Thanks Waldemar, this is going to work.
0 Kudos
Message 7 of 10
(11,132 Views)
In a related question, I'm also having to write to the registry, having a serial card that can be used in either RS232 or RS422, the switch being done in the windows registry before the port is opened. I have, nervously, tried to update the registry from the info in the examples. The examples work fine, but when I try to modify the entry I need to I get errors. I say I do it nervously because when you open the help entries for the registry vi's there are warning about making Windows unstartable if you goof up the registry and that isn't something I want to do. One difference is in what I am trying to do is the "depth" into the registry, the examples only being a couple of "levels" down in the registry, also I don't know if which root Key I'm trying to write to makes a difference, in the permissions, for instance.

The entry I'm trying to make is:



HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\
ULTRAPSI\ULTRAPSI&10PINDB9\PCI&0000&00090000&0000\
Control
Device Parameters
PortName
PollingPeriod
TxFiFoLimit
TxFiFoTrigger
RxFiFoTrigger
LoFlowCtrlThreshold
HiFlowCtrlThreshold
IFProtocol            
AutoRS485BitDelay        
BaudMultiplier        
ConfigLog

IFProtocol  would change the protocol, the definition is as follows:

DWORD    0x00000003    /* Bits 0:1 - Protocol RS interface mask */
DWORD    0x0000        /* RS-232 mode */
DWORD    0x0001        /* RS-422 mode */

DWORD    0x0002        /* RS-485 full-duplex mode */
DWORD    0x0003        /* RS-485 half-duplex mode */

DWORD    0x0004        /* Bit 2 - Enable slew rate limitting */
DWORD    0x0008        /* Bit 3 - Enable RS422/R485 Termination for RXD+ and RXD- */
DWORD    0x0010        /* Bit 4 - Enable Auto RS485 direction control */
DWORD    0x0020        /* Bit 5 - Disable RS485 half-duplex local echo */


I have gotten "-603 Specified key or value does not exist." error, suggesting that my attempt was incorrectly constructed, but I am a little nervous "playing around" in an area that my render the computer non-functioning.

 

Any help/suggestions are appreciated. A comment made in an earlier post has already raised a red flag, regarding user privledges, I suspect that I am at administrator privledges (this is an out of the box, industrial computer, no password, etc.) and so I'm not sure what will happen if it is out on the "floor" with a lower privledge log. But that isn't important until I get it to work at all!
Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 8 of 10
(11,052 Views)
Check out the attached VI this may also help you.
Message Edited by akshath on 10-23-2008 06:52 AM
Regards
Aks

(Appreciate answers by giving KUDOS)
Hit the stars.............. sky is not the limit.
Message 9 of 10
(11,048 Views)

I guess, in my fatigue clouded brain, I focused on only the registry related part of the thread, seeing now that the primary question asked was regarding Windows enviroment variables. Sorry. I will repost with my own Subject, and not further hijack this thread.

 

Putnam

Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 10 of 10
(11,044 Views)