Solved

program files dir with with Windows 7 using .net

Posted on 2012-03-28
6
313 Views
Last Modified: 2012-04-03
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.
0
Comment
Question by:chadmanvb
6 Comments
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 500 total points
ID: 37777795
use this:-

if File.Exists(@"C:\Program Files\myapp\myapp.exe")
{
Process.Start(@"C:\Program Files\myapp\myapp.exe", "test", pwd, "mydomain")
}
else
{
Process.Start(@"other path", "test", pwd, "mydomain")
}
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 37778044
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

0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37778068
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
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37779539
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.
0
 

Author Closing Comment

by:chadmanvb
ID: 37795790
This worked great.
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 37803041
That will work as long as the user hasn't got Program Files folder set up on an alternate drive, like D:
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question