Solved

program files dir with with Windows 7 using .net

Posted on 2012-03-28
6
303 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Code works but I need to redo it and assign values to Model 7 32
VB.Net How to Exit Sub - Exit Form??? 5 50
Connection String 16 43
Help with AsEnumerable(), LINQ 4 22
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

910 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

21 Experts available now in Live!

Get 1:1 Help Now