GetEnvVar>Path not working on 64 bit Win 7

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

sarver311
Pro Scripter
Posts: 84
Joined: Tue Jun 17, 2008 6:37 pm

GetEnvVar>Path not working on 64 bit Win 7

Post by sarver311 » Wed Jun 09, 2010 9:43 pm

I noticed that I can't seem to grab the path environment variable on 64 bit version of windows 7. To make sure I wasn't crazy I compiled the following script and ran it on a 32bit version and 64 bit version of windows 7. The 32 bit version echos the path just fine whereas the 64 bit is just blank.

Here is the code

Can anyone else confirm this issue or point out if I'm doing something incorrect?

Code: Select all

getenvvar>path,VarResult
messagemodal>%varresult%

tbrahmer
Newbie
Posts: 15
Joined: Thu May 06, 2010 10:14 pm

Post by tbrahmer » Tue Jul 20, 2010 3:26 pm

I've run the same two lines and get nothing back as well.
I'm running Windows 7 (32 bit however) and MS 12.0.5.
I can retrieve other environment variables (OS, ComSpec, PathExt ...) but for some reason, not PATH - just comes back blank.
FWIW, my actual path contains:

Code: Select all

D:\Programs\Cisco\Unified Communications Manager Attendant Console\jre1.4\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\Microsoft SQL Server\90\DTS\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\;d:\Programs\IBM\CLIENT~1;d:\Programs\IBM\CLIENT~1\Shared;d:\Programs\IBM\CLIENT~1\Emulator;d:\code

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Wed Jan 12, 2011 11:01 pm

tbrahmer wrote:I've run the same two lines and get nothing back as well.
I'm running Windows 7 (32 bit however) and MS 12.0.5.
I can retrieve other environment variables (OS, ComSpec, PathExt ...) but for some reason, not PATH - just comes back blank.
Hi Marcus,

I have the same issue. With MS 12.1.3 on XP SP3 running the following two lines returns nothing:

Code: Select all

GetEnvVar>Path,VarResult
MDL>%VarResult%
Is there a way to make this work or an alternative way to get this value from within MS?
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

User avatar
JRL
Automation Wizard
Posts: 3531
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Jan 12, 2011 11:18 pm

...or an alternative way to get this value from within MS
Try this.

Code: Select all

RegistryReadKey>HKEY_LOCAL_MACHINE,SYSTEM\CurrentControlSet\Control\Session Manager\Environment,Path,var

MDL>Var
Or, substitute any other environment variable name for "path" and you can get other environment variable values

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Wed Jan 12, 2011 11:27 pm

Hi JRL,

Thanks, your alternative method does work, but is it possible that a program changes the Path environment variable and does not update that registry entry? If so then it is important to be able to pull what the Path environment variable is set to "now" verses what is stored in the registry.

And either way, I'd still like to know why this simple command does not work for path:

Code: Select all

GetEnvVar>Path,VarResult
MDL>%VarResult%
Marcus, if this is a bug, can it be fixed? If not, can you please update the documentation to say that this command works on all environment variables... except path.

Thanks and please keep up the great work on the dialog videos... well done!
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

User avatar
JRL
Automation Wizard
Posts: 3531
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Jan 13, 2011 6:05 am

And either way, I'd still like to know why this simple command does not work for path:
I can't explain why the GetEnvVar> function does not get the path variable value. But I do know that he "Path" variable has always been the odd duck of the common environment variables. As far as I know its the only one that has its own DOS command. If you type "Temp" at a command line you don't get a proper response.
Thanks, your alternative method does work, but is it possible that a program changes the Path environment variable and does not update that registry entry? If so then it is important to be able to pull what the Path environment variable is set to "now" verses what is stored in the registry.
"alternative method"? Funny how many perfectly good ANSWERS I've provided here that get called "Work arounds". Of course, now that I've said that, this "answer" will probably get blown out of the water. :wink:

In any ase, as far as I've been able to tell, Windows stores the path value in the registry. The value of "Path" is what the registry says it is. No program can globally alter "path" without changing the registry value. So taking the registry value should be safe.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Jan 13, 2011 8:29 am

All our Win7 machines are x64 and your code works fine for me, returning the path correctly:

getenvvar>path,VarResult
messagemodal>%varresult%

I do not know why it doesn't for you but guess it must be something to do with the environment.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
JRL
Automation Wizard
Posts: 3531
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Jan 13, 2011 2:00 pm

getenvvar>path,VarResult Does not return a result for me on four different XP computers and I also tried it on one 64 bit win 7 computer and it did not return a result there either. As far as I can tell, all other environment variables are returned but for some reason "path" is not.

I can do testing if you have something you'd like me to try. Otherwise, if I needed to know the value of "path" (which in close to 2000 scripts I've never had a need) I would just poll the registry.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Jan 13, 2011 2:17 pm

Weird. What does this return:

Code: Select all

VBSTART
Function GetEnvVar(varname)
  Set oShell = CreateObject( "WScript.Shell" )
  GetEnvVar=oShell.ExpandEnvironmentStrings(varname)
End Function
VBEND
VBEVal>GetEnvVar("%PATH%"),strPath
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
JRL
Automation Wizard
Posts: 3531
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Jan 13, 2011 2:33 pm

The vbscript returns the path value.

the path is
C:\PVSW\bin\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\NTRU Cryptosystems\NTRU TCG Software Stack\bin\;C:\Program Files\Wave Systems Corp\Gemalto\Access Client\v5\;C:\Util;C:\Program Files\Macro Scheduler 12;C:\Program Files\QuickTime\QTSystem\

Except for the PVSW which is Pervasive Database software and of course the Macro Scheduler bit. most of the rest of this came with the Dell computer.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Jan 13, 2011 3:24 pm

Now try:

Let>buffer_SIZE=10000
LibFunc>Kernel32,GetEnvironmentVariableA,gev,PATH,str:buffer,1024
MessageModal>gev_2

http://msdn.microsoft.com/en-us/library ... s.85).aspx

Would expect the same result as the native GetEnvVar function which just calls the above API function.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
JRL
Automation Wizard
Posts: 3531
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Jan 13, 2011 3:42 pm

Yup. That worked too.

So I thought the libfunc might set something such that GetEnvVar would work so I tried:

Code: Select all

Let>buffer_SIZE=10000
LibFunc>Kernel32,GetEnvironmentVariableA,gev,PATH,str:buffer,1024
MessageModal>gev_2


GetEnvVar>path,test
mdl>test
MessageModal>gev_2 displays the path

mdl>test displays a blank message window.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Jan 13, 2011 3:48 pm

Tres interessant. Hmmm. Ok, a period of head scratching will commence.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
JRL
Automation Wizard
Posts: 3531
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Jan 13, 2011 4:08 pm

Just for curiosity sake I came up with this

Code: Select all

IfFileExists>%temp_dir%env_var_list.txt
  DeleteFile>%temp_dir%env_var_list.txt
EndIf
IfFileExists>%temp_dir%GetEnvVar_list.txt
  DeleteFile>%temp_dir%GetEnvVar_list.txt
EndIf

Let>rp_wait=1
Let>rp_windowmode=0

Run>cmd /c set > %temp_dir%env_var_list.txt

ReadFile>%temp_dir%env_var_list.txt,data
Separate>data,%CRLF%,line
DeleteFile>%temp_dir%env_var_list.txt

Let>kk=0
Repeat>kk
  add>kk,1
  Let>value=line_%kk%
  Separate>value,=,var
  GetEnvVar>%var_1%,Env_Var
  WriteLn>%temp_dir%GetEnvVar_list.txt,wres,%var_1%%tab%=%tab%%Env_Var%
Until>kk=%line_count%

ReadFile>%temp_dir%GetEnvVar_list.txt,data
MDL>data
DeleteFile>%temp_dir%GetEnvVar_list.txt
Which creates a list of the environment variables on a computer then runs that list through the GetEnvVar> function and displays the results. Below are the results from my computer.

It appears all of the env vars on my computer are resolved by the GetEnvVar> function except for "path" and "prompt". Oddly they are both also command line programs.

ALLUSERSPROFILE = C:\Documents and Settings\All Users
APPDATA = C:\Documents and Settings\dickl\Application Data
CLASSPATH = .;C:\Program Files\Java\jre6\lib\ext\QTJava.zip
CommonProgramFiles = C:\Program Files\Common Files
COMPUTERNAME = DELL014
ComSpec = C:\WINDOWS\system32\cmd.exe
FP_NO_HOST_CHECK = NO
HOMEDRIVE = C:
HOMEPATH = \Documents and Settings\dickl
LOGONSERVER = \\DELL014
NUMBER_OF_PROCESSORS = 2
OS = Windows_NT
Path =
PATHEXT = .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE = x86
PROCESSOR_IDENTIFIER = x86 Family 6 Model 23 Stepping 6, GenuineIntel
PROCESSOR_LEVEL = 6
PROCESSOR_REVISION = 1706
ProgramFiles = C:\Program Files
PROMPT =
SESSIONNAME = Console
SystemDrive = C:
SystemRoot = C:\WINDOWS
TEMP = C:\DOCUME~1\dickl\LOCALS~1\Temp
TMP = C:\DOCUME~1\dickl\LOCALS~1\Temp
USERDOMAIN = DELL014
USERNAME = dickl
USERPROFILE = C:\Documents and Settings\dickl
windir = C:\WINDOWS
windir = C:\WINDOWS

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Thu Jan 13, 2011 5:16 pm

Hi Marcus and JRL,

Code: Select all

VBSTART
Function GetEnvVar(varname)
  Set oShell = CreateObject( "WScript.Shell" )
  GetEnvVar=oShell.ExpandEnvironmentStrings(varname)
End Function
VBEND

//Thx Marcus
VBEVal>GetEnvVar("%PATH%"),path_via_VBScript_function_call

//Thx JRL
RegistryReadKey>HKEY_LOCAL_MACHINE,SYSTEM\CurrentControlSet\Control\Session Manager\Environment,Path,path_via_registry_read

MDL>These two methods return different data for Path:%CRLF%%CRLF%via read of Registry:%CRLF%Path = %path_via_registry_read%%CRLF%%CRLF%via VBScript function:%CRLF%Path = %path_via_VBScript_function_call%
Run the script above and you'll notice that the Path returned by the two methods is actually different... and I don't just mean the %SystemRoot% substitution, my results appear below:
above script on my PC wrote:These two methods return different data for Path:

via read of Registry:
Path = %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Windows Imaging\;C:\ORACLE\Ora92\bin;C:\SVC;C:\progra~1\ibm\cicsun~1\bin;C:\Program Files\Microsoft Application Virtualization Client;C:\Program Files\Common Files\Roxio Shared\DLLShared\;C:\Program Files\Common Files\Roxio Shared\10.0\DLLShared\;C:\Program Files\Intel\DMIX;C:\progra~1\e!oc

via VBScript function:
Path = C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Windows Imaging\;C:\ORACLE\Ora92\bin;C:\SVC;C:\progra~1\ibm\cicsun~1\bin;C:\Program Files\Microsoft Application Virtualization Client;C:\Program Files\Common Files\Roxio Shared\DLLShared\;C:\Program Files\Common Files\Roxio Shared\10.0\DLLShared\;C:\Program Files\Intel\DMIX;C:\progra~1\e!oc;C:\Program Files\IDM Computer Solutions\UEStudio\
So for my purposes, I'll be using the VBScript method of getting the Path... until GetEnvVar> can be made to work... :D

Edit - Fri Jan 14, 2011 9:48 PM:

By the way JRL, since you asked, yes when I go in with regedit and look at this registry key, I see exactly what is displayed above under "via read of Registry:".

And then I open a DOS window and type "set" and for path, it displays exactly what is displayed above under "via VBScript function:" and yes they are different.


Thank you both for your continuing efforts... much appreciated as always.
Last edited by jpuziano on Sat Jan 15, 2011 3:38 am, edited 1 time in total.
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts