11-20-2024 02:54 PM
I wrote a function that finds the value of an environment variable.
Do you think there is a better way? Sorry for the mess.
Same as you write in the cmd:
"echo My PC is %COMPUTERNAME% and user is %USERNAME%".
11-20-2024 04:18 PM
@maxnoder1995 wrote:
I wrote a function that finds the value of an environment variable.
Do you think there is a better way?
Of course there is a better solution, The windows API function ExpandEnvironmentStrings.
11-21-2024 01:11 AM
Hi Max,
@maxnoder1995 wrote:
I wrote a function that finds the value of an environment variable.
Do you think there is a better way? Sorry for the mess.
Unfortunately you forgot to downconvert your VI. (I prefer LV2019, others may be happy with "LV2021 or older".)
In your image I don't see anything that reads the value of an environment variable. All you seem to do is to parse/format predefined strings…
11-21-2024 05:14 AM
@maxnoder1995 wrote:
I wrote a function that finds the value of an environment variable.
Do you think there is a better way? Sorry for the mess.
Same as you write in the cmd:
"echo My PC is %COMPUTERNAME% and user is %USERNAME%".
I will have to look at the Windows API way that was mentioned. But the .NET API that I mentioned about 10 years ago in this thread is really the easiest and cleanest way to do it.
02-04-2025 08:08 PM
@Martin_Henz wrote:
@maxnoder1995 wrote:
I wrote a function that finds the value of an environment variable.
Do you think there is a better way?Of course there is a better solution, The windows API function ExpandEnvironmentStrings.
Just tried this, at least for me it did not work at all.
02-05-2025 12:23 AM
@MikeMesolella wrote:
@Martin_Henz wrote:
@maxnoder1995 wrote:
I wrote a function that finds the value of an environment variable.
Do you think there is a better way?Of course there is a better solution, The windows API function ExpandEnvironmentStrings.
Just tried this, at least for me it did not work at all.
Probably you using it in wrong way, for me it works:
02-05-2025 04:05 AM
Hello Martin,
thank you very much for the VIs.
My first try of "GetEnvironmentVariables" failed with "PATH", so I had to set the initial string buffer size to 4096. Now it works with this long value string.
Btw. i didn't know that the LABVIEW- dll contains these cstr - functions. Thank you for the hint.
02-05-2025 05:19 AM
@daveTW wrote:
My first try of "GetEnvironmentVariables" failed with "PATH", so I had to set the initial string buffer size to 4096.
The VI GetEnvironmentVariable.vi is actually not perfect. If the buffer is not large enough, the Windows API function returns the needed buffer size. It should be implemented similar to ExpandEnvironmentStrings.vi
Here it is: