Reputation: 63
I have a form with the code:
private void msconfigButton_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("msconfig.exe");
}
The idea is I click a button and it starts msconfig for me. Problem is when I run it on a x64 machine it crashes with a Win32Excpetion
was unhandled error saying it can not find the file. I know the file exists in C:\Windows\System32\ and I believe this is related to my project being compiled for a x86
CPU type.
How can I rewrite the code so that it starts msconfig.exe on a 64 bit computer? I do not want to change the CPU type for building it. The idea is that I can run this program on either a 32 or 64 bit Window 7 machine and it works just the same.
Upvotes: 1
Views: 2017
Reputation: 3014
One way around this would be to write a simple x64 application that started msconfig.
Your application then stays as x86 and your Process.Start would start your wrapper application, which would in turn start msconfig.
For example, create a new console app (lets call it 'msconfigstarter') with the following:
class Program
{
private static void Main(string[] args)
{
System.Diagnostics.Process.Start("c:\\windows\\system32\\msconfig.exe");
}
}
Set it's build platform to x64.
Now you can add that exe ('msconfigstarter.exe') to your application project as a content file that gets copied to your output folder, or include it in your installer as an output file.
Then change your button click code to:
private void msconfigButton_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("msconfigstarter.exe");
}
This works around the problem that the file system redirector swaps the System32 folder for x86 apps because you start an x64 app that you do know exists 'msconfigstarter.exe' which can then access msconfig.exe because the system32 folder is not redirected for it.
Upvotes: 1
Reputation: 572
It seems that the only way to avoid this issue is by changing the build type. See http://social.msdn.microsoft.com/Forums/pl/csharplanguage/thread/ad97bb81-0566-4eb9-b1e1-c591476a4958 If anything it seems that maybe looking into the File System Redirector could provide some insight or a workaround!
Best of luck!
Upvotes: 1