LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can LabVIEW "read" Microsoft Windows Environment Variables?

 

Here is yet another simplification. Hopefully I have not changed the way it works.  Smiley Happy

 

 

Yet, another version :)

0 Kudos
Message 11 of 32
(3,430 Views)

It just occured to me that since a % sign is allowed to be used in an Environment Variable name, removing leading and trailing % signs (or not adding them if present) could cause errors. Windows does not complain if I use a leading and/or a trailing % sign in a name. It is best just to note on the front panel and in the documentation to enter the name wothout % signs. The only other solution is to try to recover the variable using various combinations and look for errors. Even this is questionable since there could be two like names, one with a % sign and one without.

0 Kudos
Message 12 of 32
(3,418 Views)

Here is some more info. There are three ways to do this: Use the System Exec.vi to go through the DOS shell (As shown above); Use the Registry VIs; Use a CLN with the kernal32 DLL. Mychal at NI sent me a VI using the CLN method. I reorganized it to my liking, and this is shown in the snippet. His uses a smaller icon without error terminals. I've added error terminals, even though they really are not needed since the DLL will always be there. Only mine is attached here because I accidently overwrote his in the Outlook Temp folder.

 

Get Environment Variable Diagram.png

 

Get Environment Variable, CLN Function Tab.PNG

 

Get Environment Variable, CLN Parameters Tab.PNG

0 Kudos
Message 13 of 32
(3,403 Views)

My apologies if I have Mychal's gender wrong in the above post. I mentally transliterated Mychal to the English Michael.

0 Kudos
Message 14 of 32
(3,398 Views)

Why make this so hard, just use .net method?

 

get_env.JPG

Message 15 of 32
(3,066 Views)

Cool! No one I spoke with at NI suggested this, and I wasn't familiar with .NET at the time.

0 Kudos
Message 16 of 32
(3,038 Views)

Holy Cow.  Yes.  Kudo'ed

0 Kudos
Message 17 of 32
(3,031 Views)

It's a convenient way, but could you explain the way to find this GetEnvironmentVariable object?

 

Thanks.

0 Kudos
Message 18 of 32
(2,972 Views)
Since I asked this question NI has added palette VIs for working wit Environment Variables.
0 Kudos
Message 19 of 32
(2,954 Views)

@guangdew1 wrote:

It's a convenient way, but could you explain the way to find this GetEnvironmentVariable object?

 

Thanks.


1) Invoke Node (.NET)

2) Right Click >> Select Class >> .NET >> Browse
3) Select mscorlib

4) Browse to System

5) Expand to select Environment

6) Select Method "[S]GetEnvironmentVariable(String variable)"

Info on this is found here:

http://msdn.microsoft.com/en-us/library/77zkk0b6(v=vs.110).aspx

 

Message 20 of 32
(2,921 Views)