Reputation: 2784
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?
Upvotes: 0
Views: 159
Reputation: 64218
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.
Upvotes: 1