LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Setting system enviroment variables

Is there a way to set or read the XP enviroment variables

I thought the getenv ("Path") would return the current path variable but not quite right...

 

The system () command could load a .bat file but I was looking for something more interactive... to see if I needed to load the required variables... Ideas?

0 Kudos
Message 1 of 5
(3,854 Views)

About reading system variables you can use SDK instruction ExpandEnvironmentStrings () passing the specific variable to read from in the form %"variableName%". Here an example of reading the system path and displaying it in a string indicator:

 

    if (ExpandEnvironmentStrings ("%PATH%", msg, 1024))
        SetCtrlVal (panelHandle, PANEL_STRING, msg);
 

I'm not aware of a method to change such variables (apart using the System command or calling a batch file as you already told).



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 5
(3,840 Views)

Using system() or its equivalents in an attempt to change environment variables may not have the desired effect. system() will spawn a new shell, which inherits a copy of its whole environment from the calling process. Changes to environment variables will then be made to the local copies of the parents' variables. Once the shell ends and execution returns from the system() call, the changes will be lost.

 

There is probably a way to do it properly, but I never found it.

 

JR

0 Kudos
Message 3 of 5
(3,836 Views)

A bit more info needed Roberto... on the SDK instruction, in looking in the SDK directory, it is not obvious what to include or how to fine the prototype/callback. although I can't do any system variable commands, at least I can check for the ones that will break my progams if not in place.

 

Cheers!

ChipB

0 Kudos
Message 4 of 5
(3,814 Views)

If you have the full version of CVI you should have installed the SDK on your system and you should find it in the Help menu. If you haven't maybe you could try running the setup program to add it to the system. In any case, here you can find the definition of the command on MSDN. I only needed to add windows.h to the list of include files and that's all: I suppose kernel32.lib is already linked to the system since is the core base library of the OS.

On the SDK or MSDN you can find also a discussion on GetEnvironmentVariable () and SetEnvironmentVariable () that should suit your need for changing some system variable for the process. However, I never used them so I cannot give you any experience on them.

An explicit note on the description of these commands specify that they operate on the environment for the active process: this should be in the line of JR comments; using them programmatically from within the program should permit you to get and set the variables your application actually needs and operate with.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 5 of 5
(3,808 Views)