[PB 5.31] GetEnvironmentVariable gives faulty results

Just starting out? Need help? Post your questions and find answers here.
Poltergeist
User
User
Posts: 26
Joined: Fri Jul 14, 2006 10:27 pm

[PB 5.31] GetEnvironmentVariable gives faulty results

Post 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
User avatar
mhs
Enthusiast
Enthusiast
Posts: 101
Joined: Thu Jul 02, 2015 4:53 pm
Location: Germany
Contact:

Re: [PB 5.31] GetEnvironmentVariable gives faulty results

Post by mhs »

That is an Windows characteristic for x86 programs. Try the x64 Compiler and it should work...
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: [PB 5.31] GetEnvironmentVariable gives faulty results

Post 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
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Poltergeist
User
User
Posts: 26
Joined: Fri Jul 14, 2006 10:27 pm

Re: [PB 5.31] GetEnvironmentVariable gives faulty results

Post 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?
Post Reply