2

I would like to open programmaticaly an application.

First i used System.Diagnostics.Process.Start(@"C:\Program Files (x86)\Program1.exe") works fine, but the application always needs to be on the same path (not always true because different computer)

And a simple way to find it (with mouse & click, not programmaticaly though) is to use the windows file explorer, i enter the title of my application and i find it instantly.

I would like to code that.

I thought i could use the keyboard shortcut "Home + F" and simulate the word with SendKeys.Send("blabla") but the "Home key" doesn't seem to exist with c# (at least not here https://msdn.microsoft.com/fr-fr/library/ms127847(v=vs.110).aspx)

It's a little program for children i can't expect them to find manually the path (so forget the OpenFileDialog..)

Maybe thats a very bad idea and there are another solution to find a program without knowing his path, i don't know have you got better idea?!

jsls
  • 251
  • 3
  • 16
  • Instead of automating Windows File Explorer, just use the built-in C# methods to find the file: http://stackoverflow.com/q/1225294/87698 – Heinzi May 31 '16 at 13:43
  • Works almost fine but make my computer freeze... like a lot. – jsls May 31 '16 at 13:54
  • 1
    You could use Heinzi's solution. WITH application.config to write the path in there. So the first time you show a loading dialog. and after that you just read from the application.config file – Donald Jansen May 31 '16 at 13:59
  • Is it just "Program Files" with or without the "(x86)" (depending on 32 or 64 bit os + application), or could that "Program1.exe" have been installed anywhere? – Hans Kesting May 31 '16 at 14:32
  • that's the issue, it can be anywhere... it's installed by usb key ... – jsls May 31 '16 at 14:50

1 Answers1

0

You're trying to solve the problem the wrong way. What you're trying to "program" is the setting oft the working directory when the program is run using Explorer. The right way to do that is to use Process.Start by passing it all of the necessary info to start the process:

var startInfo = new ProcessStartInfo("Program1.exe");
startInfo.WorkingDirectory = @"C:\Program Files (x86)\";

Process proc = Process.Start(startInfo);
D Stanley
  • 149,601
  • 11
  • 178
  • 240