0

Process.Start() only seems to work on a shortcut whose the target is located in the Program Files (x86) folder and not in the Program Files folder.

If the target is in the Program Files folder I get the fallowing error

"The system cannot find the file specified" (run-time error)

Why does this happen, and is there any way to fix this so I can open shortcuts whose targets are in the Program Files folder.

If it matters - I have Windows 7 Ultimate

Edit

Here is my code

public class MainClass
{
    static void Main()
    {
    Process.Start(Path.Combine(Directory.GetCurrentDirectory(), "Blender") );
    Console.ReadLine();
}
}

Edit 2 - My Solution

I've come to suspect the problem was with my IDE(Xamarin Studio). So I installed Visual studio, turned off prefer 32 bit and set it to AnyCPU and it worked. I don't know why Xamarin Studio was doing to cause this problem, but I know visual studio made it go away.

JackBarn
  • 635
  • 1
  • 6
  • 18

1 Answers1

2

This is a 32-bit issue OR a file location issue.

What have you tried so far?

What code do you use?

I have created a very basic app and it runs just fine, though If I use the wrong path will throw your error. Also using the "prefer 32-bit" will.

Since there's 2 most likely causes you need to do these:

  1. Check your project properties.

Under "Build" there is a "Platform Target". Be sure it is set to Any CPU and uncheck the "Prefer 32-bit" box.

That will most likely be your issue.

  1. If it still fails, you have the wrong path.

Though you may be saying "I most certainly do not! It's on my desktop! I can see it!" You'd be wrong.

The shortcut can be placed in everyone's desktop by placing it in the public location. For example I have a shortcut on my dessktop but it's not found under my desktop. It appears on my desktop because it's in the public folder.

So Right click the shortcut and use the path listed beside "Location". This is its true location.

Example:

Process.Start(new ProcessStartInfo()
            {
                FileName = @"C:\Users\Public\Desktop\Oracle VM VirtualBox"
            });

Or simply:

Process.Start(@"C:\Users\Public\Desktop\Oracle VM VirtualBox");
Jeremy Styers
  • 497
  • 5
  • 23
  • There is no way that the path can be wrong because the shortcut I want to open is located in the `current directory`. I've tried changing Platform Target to Any CPU but that did not work. The only thing that has worked so far is the using the full path such as `C:\Program Files\Blender Foundation\Blender`, but this will not do – JackBarn Feb 25 '15 at 02:02
  • Your code works. How are you seeing that it doesn't? Are you running it via VS? If so, do you have the shortcut in the debug or release folder? If you take the compiled exe and place it next to the shortcut, then run it, what happens? I think you're running it via VS, in which case the path IS wrong unless you have the shortcut in your debug/release folder (as that's what the "current directory" is). Your code runs as is on my system without error, so make sure the path you pass is the path you want. – Jeremy Styers Feb 25 '15 at 07:13
  • The shortcut is in the Debug folder right next to the compiled exe. I've set it to Any CPU. It still gives me that error. I'm using Xarmine studio wich is prety the same as Visusl Studio – JackBarn Feb 25 '15 at 14:00
  • Try sending me the entire code in a zip folder as I can't reproduce the error in my code. My email is jeremys18@gmail.com. – Jeremy Styers Feb 25 '15 at 17:32
  • I've come to suspect the problem was with my IDE(Xamarin Studio). So I installed Visual studio, turned off `prefer 32` bit and set it to `AnyCPU` and it worked. Thanks – JackBarn Feb 25 '15 at 21:38
  • Unticking "Prefer 32-bit" solved this problem for me, thanks! – darx Jan 28 '17 at 14:45