Page 1 of 1

[PB 5.31] GetEnvironmentVariable gives faulty results

Posted: Tue Jul 28, 2015 3:40 pm
by Poltergeist
Debug GetEnvironmentVariable("ProgramFiles(x86)")
Debug GetEnvironmentVariable("ProgramFiles")

both give c:\program files (x86) back.

Also

Debug GetEnvironmentVariable("Commonprogramfiles(x86)")
Debug GetEnvironmentVariable("commonprogramfiles")

both C:\Program Files (x86)\Common Files

Checked in cmdprompt: Values are different. So why not in PB?

ProgramFiles(x86)=C:\Program Files (x86)
ProgramFiles=C:\Program Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramFiles=C:\Program Files\Common Files

Testing with Windows 10 (don't have a win8 machine at hand at the moment), with PB 5.31 X86

Re: [PB 5.31] GetEnvironmentVariable gives faulty results

Posted: Tue Jul 28, 2015 3:44 pm
by mhs
That is an Windows characteristic for x86 programs. Try the x64 Compiler and it should work...

Re: [PB 5.31] GetEnvironmentVariable gives faulty results

Posted: Wed Jul 29, 2015 2:32 am
by Thunder93
No PB bug.

The %ProgramFiles% itself depends on whether the process requesting the environment variable is itself 32-bit or 64-bit (this is caused by Windows-on-Windows 64-bit redirection).

32bit CMD.exe
  • ProgramData=C:\ProgramData
    ProgramFiles=C:\Program Files (x86)
    ProgramFiles(x86)=C:\Program Files (x86)
    ProgramW6432=C:\Program Files
64bit CMD.EXE
  • ProgramData=C:\ProgramData
    ProgramFiles=C:\Program Files
    ProgramFiles(x86)=C:\Program Files (x86)
    ProgramW6432=C:\Program Files

Re: [PB 5.31] GetEnvironmentVariable gives faulty results

Posted: Wed Jul 29, 2015 7:41 am
by Poltergeist
Thank you. That's clear and logical. Is there any (purebasic) way around it, expect for using the 64bit purebasic, or runprogram(Getenvironmentvariable("comspec"),"/c echo %programfiles(x86)% > sometext.txt") (something like that)and parsing that output? The program needs to run on both 32 and 64 bit platforms, but I need to be able to access those directories.. And I don't want to hardcode them...

I don't think that runprogram is gonna work either, right?