LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can LabVIEW "read" Microsoft Windows Environment Variables?

 
Can LabVIEW "read" Microsoft Windows Environment Variables out of the box?

Using the Registry functions, I can get LabVIEW to read the Registry settings that determine certain Environment Variables, like %HOMEPATH%:

HKEY_CURRENT_USER\Volatile Environment\HOMEPATH

However, the "dynamic" Environment variables, like %USERPROFILE%, or %SYSTEMDRIVE%, that don't [as far as I know] reside in the registry, appear to be beyond LabVIEW's ability to read. Furthermore, "String To Path" does not correctly translate "%USERPROFILE%" to e.g. "C:\Documents and Settings\Joe User". See the attached "UserProfile.vi".

Have I overlooked any built-in VIs, or is this the sort of thing that needs to make direct calls to system DLLs?

Also, if you purchase the "LabVIEW Enterprise Connectivity Toolkit", do you gain this sort of functionality?

http://sine.ni.com/apps/we/nioc.vp?cid=10697〈=US

Thanks!!!
0 Kudos
Message 1 of 32
(9,571 Views)
For anyone who is interested, I've attached a "Miscellaneous Registry Stuff.vi" to play around with.
Message 2 of 32
(9,561 Views)
Also, does anyone know whether LabVIEW [out of the box, with no further purchases, and no homemade DLL calls] is capable of determining whether it was loaded using the "Shift | Right Click on Shortcut | Run as..." trick [that allows you to launch a program as a different user]?

On the other hand, if anyone knows what those further purchases would be, or what the homemade DLL calls would look like, do tell.

Thanks again!!!
0 Kudos
Message 3 of 32
(9,559 Views)
Hello,

LabVIEW can access any type of Windows information that you can access through the command prompt. You can use the System Exec.vi to send commands to Windows and receive the response. The use of the System Exec.vi is discussed in these discussion forum posting:
http://forums.ni.com/ni/board/message?board.id=170&message.id=1033&requireLogin=False
http://forums.ni.com/ni/board/message?board.id=170&message.id=37803&requireLogin=False

Thanks,
Caroline
National Instruments
Thanks,
Caroline Tipton
Data Management Product Manager
National Instruments
Message 4 of 32
(9,514 Views)
With the property node class Application and property Application>>user you can get the user name in which context LV is running. There is no chance to determine if this is the interactive logged in user or startet by Run as.

Waldemar
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
0 Kudos
Message 5 of 32
(9,500 Views)
Thanks everybody.

I've attached a little VI that ought to return environment variable values for any Microsoft operating system based on the NT kernel.

[Older systems might have to use COMMAND.COM instead of CMD.EXE, but I haven't used one of those kernels in years and years.]
Message 6 of 32
(9,486 Views)

Thanks  tarheel_hax0r (if you are still reading this !).   I benefited from your quick little utility to do what I was after and I was then compelled to tidy it up.  So I compacted your code by utilising dataflow rather than local variables and a sequence structure. Instead of being 2 screens wide it is now about 2/3 of a screen wide.

 

I'm attaching the updated version saved for LV 2009.

 

regards

Peter
Message 7 of 32
(8,720 Views)

Thanks to both of you. 

I have tidied up a bit more. Attached is a LV2010 snippet.

Enclose it in error detection if you need to.

 

 GetEnvironment Variable.png 

 

 

For what it's worth, you can SET an environment variable too, but it seems to be pointless, as the environment lasts only as long as the SYSTEM EXEC call.  

 

IOW, the value is forgotten when the shell closes.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

Message 8 of 32
(8,679 Views)

Hi,

I've just found this useful, however I'm wondering something.  Why the "cmd /c" at the beginning of the command, "echo <variable>" seems to work fine.  Just curious.

 

Thanks

David J.

 

Update...Nevermind I see now.  I was using the actual command line to test this command, when using sysexec tool in labview it doesn't like the "echo" command alone.

Returning to my regularly scheduled coding...:)

 

Cheers

Dave

0 Kudos
Message 9 of 32
(8,598 Views)

The key thing to remember is that System Exec is equivalent to you doing Start -> Run and entering a command there. echo <variable> is not a valid program to run. That's why it has to be run within the context of a command window.

0 Kudos
Message 10 of 32
(8,595 Views)