0

I have a really strange situation.

In our company we develop big web application which consist of several modules. Each module is divided in separate folders on server. There is one module which launches application mapped on users L:\app.exe disk.

My goal is update the invoking method which first will start the switcher.exe file INSIDE the module and after will start L:\app.exe as it was before.

The problem is that when i build this module on my local it works perfectly fine but when i downloading the content from my bin\Debugg on server-including swither.exe (say on Dev environment) the application fails to find "switcher.exe" in folder on server. It throws an exception which says {"The system cannot find the file specified"}.

The code behind is pretty simple:

private void LaunchSwitherExe()
        { 
            string executionPath = System.IO.Path.GetDirectoryName(
               System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
            MessageBox.Show(executionPath);  

            Process themeSwitchProc = new Process();

            themeSwitchProc.StartInfo.FileName = "Switcher.exe";
            themeSwitchProc.StartInfo.WorkingDirectory = executionPath;


            themeSwitchProc.Start();
         }

The messagebox shows(for test purposes) the path to swither.exe. And this path is absolutely correct. It has swither.exe inside.

Do you have any ideas?

---UPDATE---

The problem way in the string to the path. This:

string executionPath = System.IO.Path.GetDirectoryName(
               System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);

Chould be changed to:

string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
Directory.SetCurrentDirectory(exeDir);

Thanks to all folks who answered and especially to "Rick S."

AngryBoy
  • 4,627
  • 2
  • 15
  • 10

1 Answers1

1

Have you considered it might be permissions issue? What process Id is the code running under and does it have access to that folder?

I also found this:

When the UseShellExecute property is false, gets or sets the working directory for the
process to be started. When UseShellExecute is true, gets or sets the directory that
contains the process to be started.

And maybe try this: Defining a working directory for executing a program (C#)

Community
  • 1
  • 1
Rick S
  • 6,476
  • 5
  • 29
  • 43
  • Thank you very much. Your link helped. The problem was in string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); Directory.SetCurrentDirectory(exeDir); – AngryBoy Feb 10 '14 at 21:30
  • Thank you so much! You link helped. The problem was in string to the path, I changed it to the one from this link and it worked (see an update). – AngryBoy Feb 10 '14 at 21:37