Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

program files dir with with Windows 7 using .net

Posted on 2012-03-28
6
Medium Priority
?
332 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 2000 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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

636 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