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 :)

David Grucza, CLD
Message 11 of 44
(4,640 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.

David Grucza, CLD
0 Kudos
Message 12 of 44
(4,628 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

David Grucza, CLD
Message 13 of 44
(4,613 Views)

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

David Grucza, CLD
0 Kudos
Message 14 of 44
(4,608 Views)

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

 

get_env.JPG

Message 15 of 44
(4,276 Views)

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

David Grucza, CLD
0 Kudos
Message 16 of 44
(4,249 Views)

Holy Cow.  Yes.  Kudo'ed

0 Kudos
Message 17 of 44
(4,242 Views)

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

 

Thanks.

0 Kudos
Message 18 of 44
(4,183 Views)
Since I asked this question NI has added palette VIs for working wit Environment Variables.
David Grucza, CLD
0 Kudos
Message 19 of 44
(4,165 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 44
(4,132 Views)