문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top