Solved

program files dir with with Windows 7 using .net

Posted on 2012-03-28
6
301 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now