Link to home
Start Free TrialLog in
Avatar of chadmanvb
chadmanvb

asked on

program files dir with with Windows 7 using .net

I'm testing some of my software to make sure it works with Windows 7.  My current software uses a command like:

Process.Start("C:\Program Files\myapp\myapp.exe", "test", pwd, "mydomain")

I can I code this to work with both XP and Windows 7.  Currently it fails on Windows 7 because it's looking in the x86 folder.
ASKER CERTIFIED SOLUTION
Avatar of BuggyCoder
BuggyCoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In .NET 4.0 you can do this:

Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86)

In previous versions:
VS2008-2010
Dim path As String = If(Environment.GetEnvironmentVariable("ProgramFiles(x86)"), Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles))

Open in new window


VS2005
       
Dim path As String = If(Environment.GetEnvironmentVariable("ProgramFiles(x86)") Is Nothing, _
                                Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), _
                                Environment.GetEnvironmentVariable("ProgramFiles(x86)"))

Open in new window

well i thought i should share this as well, here is the code to tell you if you are running your app on 64 bit windows or not:-

http://stackoverflow.com/questions/336633/how-to-detect-windows-64-bit-platform-with-net

probably then you can decide to look for in program files(86) folder for you app.exe
Avatar of Nasir Razzaq
Another thing to keep in mind is that Win 7 wont allow your program to access program files folder unless its running in admin mode.
Avatar of chadmanvb
chadmanvb

ASKER

This worked great.
That will work as long as the user hasn't got Program Files folder set up on an alternate drive, like D: