Jump to content

System Variables in Windows


Recommended Posts

Here are some other ways.

First, the system-wide environment variables are stored in the registry, so you can use the registry VIs that come with LabVIEW to get and set them. Here is a simple example to get all the environment variables.

Download File:post-192-1141691097.vi

When an application is running, it can also set environment variables, but the changes are only for that instance of that application. You can get and set these application specific variables using these two VIs (which make calls to Kernel32.dll).

Why would this be useful? Imagine you have a LabVIEW program that relies on Perl. Instead of calling "c:\Perl\bin\perl.exe script.pl", you'd rather just use "perl script.pl". This will work if "c:\Perl\bin" is part of the PATH environment variable. If you don't (or can't) change the registry settings (user doesn't have permission, security mandate, etc), then you can change the application environment variable each time you start the application up.

Download File:post-192-1141691193.viDownload File:post-192-1141691210.vi

Pat

Link to comment
Here is another KERNEL32.dll call that Rolf Kalbermatter pointed out.

Download File:post-192-1141750763.vi

Pat

On WinXP Pro, w/LV 7.1.1 using the above call to kernel32.dll:

If I set the buffer size to below the required size output by the call, I get nothing in my value string, as expected. Nothing abnormal happens when I close the VI and shutdown LV after this.

If I set the buffer size to above the required size output by the call, I get the desired variable expansion in my string indicator (I'm just using %PATH% by itself which expands to be a 271 character string), however when I close the VI I always get a LabView crash (LabView needs to shut down error 10x out of 10x I tried), and also sometimes (4x out of 10) I get memory overflow errors (not enough memory to perform this operation) with every mouse click after running the VI until I shut LabView down, then I get the LabView crash again.

Has anyone else seen this behavior, and what can I do about it? :headbang:

Joe (orko)

Link to comment

Joe,

I was being sloppy. It was working on my PC, so I didn't bother cleaning it up. Basically, we're telling the DLL the we are passing in a pointer to a string that is a certain length. Problem is, I wasn't actually passing in a string. I thought LabVIEW was taking care of it for me, but I guess I was just getting lucky.

Here is a new version that should work.

Download File:post-192-1141769510.vi

Link to comment
  • 2 months later...

Maybe I'm missing something, but when I download the last version of the VI above, it still doesn't preallocate the buffer for the return string. I've modified it to do this, and added a connector pane and icon.

However, as described in a recent Info-LabVIEW post, I wanted to get the path to the All Users application data folder which isn't available as an environment variable. With a little digging I found that the approved way to do this is to call the SHGetFolderPath function in shfolder.dll and I've created a pair of VI's to do this.

I've only tested them on my system (LV 7.1.1 on Windows XP SP1) so any feedback on how they work on other configurations is welcome...

Tom

Download File:post-1157-1149604122.vi

Download File:post-1157-1149604138.llb

Link to comment
...any feedback on how they work on other configurations is welcome...

First of all, welcome! :)

I'm on LV 8.0.1 with XP and SP2, and your examples are fine. I especially like the Special Folders VI. :thumbup: Keep it coming!

This is the first place I come to when I'm trying to solve a coding problem. I monitor the forums by subscribing to the RSS feeds using Firefox with Sage. With the loss of some of the Info-LabVIEW archive sites, I hope more Info-LabVIEW folks come to LAVA for things like this.

When you need a break from wireworking, The Lounge is a fun place to unwind.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.