Click here to Skip to main content
15,894,460 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

I have a problem with path wich contains Environment Variables "%%ProgramFiles%% ...

"%%ProgramFiles%%\\test\\filename.exe"

I used Environment.ExpandEnvironmentVariables(Path) function to convert it, the result was "Program Files" but the result should be "Program Files (x86)" because the target path is found in "Program Files (x86)" folder !!

How can i get the right folder ??

sorry for my poor english !!
Posted
Comments
[no name] 3-Aug-13 11:02am    
http://stackoverflow.com/questions/194157/c-sharp-how-to-get-program-files-x86-on-windows-vista-64-bit

 
Share this answer
 
Have a look at this answer: http://stackoverflow.com/questions/194157/c-sharp-how-to-get-program-files-x86-on-windows-vista-64-bit/194223#194223[^]

Quote:
The function below will return the x86 Program Files directory in all of these three Windows configurations:

32 bit Windows
32 bit program running on 64 bit Windows
64 bit program running on 64 bit windows
C#
static string ProgramFilesx86()
{
    if( 8 == IntPtr.Size
        || (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432"))))
    {
        return Environment.GetEnvironmentVariable("ProgramFiles(x86)");
    }

    return Environment.GetEnvironmentVariable("ProgramFiles");
}
 
Share this answer
 
Comments
Abdulla0991 3-Aug-13 11:11am    
thanks :( but my question is :

if i have path like:
"%%ProgramFiles%%\\test\\filename.exe"

how i can know the right folder ?? "ProgramFiles (x86)" or "Program Files" ??
André Kraak 3-Aug-13 11:19am    
That depends on whether it is a 32-bit or 64-bit program.

On a 32-bit Windows it can only be a 32-bit program and the correct folder is "Program Files". On 64-bit Windows it will be in "Program Files" if it is a 64-bit program and in the "Program Files (x86)" folder when it is a 32-bit program.

Windows will not solve this for you. The ExpandEnvironmentVariables function does it suppose to and expand to the standard folder, which is "Program Files" on both versions of Windows.
Abdulla0991 3-Aug-13 11:30am    
so, there isn't way to solve this problem ???
André Kraak 3-Aug-13 13:15pm    
If you do not know the architecture of the program you will need to check both paths for the presence of the program.
Abdulla0991 3-Aug-13 13:53pm    
I was thinking the same thing ,, i will use it until i find more dynamic code

thank you friend

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900