Pregunta

I have an shared office add-in that uses a separate process to delete files using the following code:

string currentDir = System.Reflection.Assembly.GetExecutingAssembly().Location;
currentDir = Path.GetDirectoryName(currentDir);
Process.Start(Path.Combine(currentDir, "process.exe"), "/d \"" + file + "\"");

This seems to randomly be unable to find the process even though it is in the same directory as the add-in. I would like to avoid having to add the directory to the PATH variable.

Any ideas?

¿Fue útil?

Solución

I would like to avoid having to add the directory to the PATH variable.

That will not help, Process.Start must be provided the fully-qualified path.

I would recommend updating the installer to write the install directory into the registry. Make sure to grant everyone read access on the key/value. Using assembly.Location and/or AppDomain.CurrentDirectory can be very problematic from within another application. Just avoid it and use a well-known value storage.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top