S
Shawn Campbell
I'm having a problem setting environment variables with a large
string. According to the MSDN documentation, an environment variable
can be up to 32k. I'm well under this value, but it's not being set.
Following is the code I'm using.
sub SetEnvVar
{
my($Variable)=shift(@_);
my($VarValue)=shift(@_);
# Load the function from the KERNEL32 library. If we can't, let it
be
# known...
#
$Win32_SetEnvVar = new Win32::API("kernel32",
"SetEnvironmentVariable", [P, P], N);
if (!(defined $Win32_SetEnvVar))
{
&StatusOut ("Unable to load SetEnvironmentVariable!\n");
exit;
}
# Now let's make the call..
#
$rtn = $Win32_SetEnvVar->Call($Variable, $VarValue);
return;
}
To test this I used a call to get the PATH variable and then write the
path value to a new environment variable (FOO) and then did a
GetEnvVar of FOO. This worked and I received the entire value back.
Then I doubled the size of the path value ($Val="$Val;$Val") and wrote
it out to FOO and did a GetEnvVar of FOO again. The second time it
failed to write out the path value and I received nothing back.
Is there some max limit on what Win32::API allows to be passed into
it?
-Shawn
string. According to the MSDN documentation, an environment variable
can be up to 32k. I'm well under this value, but it's not being set.
Following is the code I'm using.
sub SetEnvVar
{
my($Variable)=shift(@_);
my($VarValue)=shift(@_);
# Load the function from the KERNEL32 library. If we can't, let it
be
# known...
#
$Win32_SetEnvVar = new Win32::API("kernel32",
"SetEnvironmentVariable", [P, P], N);
if (!(defined $Win32_SetEnvVar))
{
&StatusOut ("Unable to load SetEnvironmentVariable!\n");
exit;
}
# Now let's make the call..
#
$rtn = $Win32_SetEnvVar->Call($Variable, $VarValue);
return;
}
To test this I used a call to get the PATH variable and then write the
path value to a new environment variable (FOO) and then did a
GetEnvVar of FOO. This worked and I received the entire value back.
Then I doubled the size of the path value ($Val="$Val;$Val") and wrote
it out to FOO and did a GetEnvVar of FOO again. The second time it
failed to write out the path value and I received nothing back.
Is there some max limit on what Win32::API allows to be passed into
it?
-Shawn