0

trying to create a dll which opens a file, originally i was trying to open batch file but it seems the process isnt executed when the dll is used by other program.
The code was tested in console application project and is working.

in the dll i put some logging but even though the logs are written the process does nothing.

I tried this simple code for example:

System.Diagnostics.Process.Start("C:\\QcOSD.txt\\");

tried other code like:

Process p = new Process();

p.StartInfo.FileName = "cmd.exe";

p.StartInfo.Arguments = @"/C D:\test.bat";

p.Start();

p.WaitForExit();

not working when using the dll file on other program but working well on console application project.

EDIT:
possible solution that worked for me: allowing the service that runs the dll to interact with the desktop.
windows services > properties of the service running the dll > Log on > check "Allow service to interact with desktop".

avi.tavdi
  • 305
  • 2
  • 4
  • 17
  • How is this DLL being run, is it from inside a service? – Scott Chamberlain Feb 19 '14 at 17:19
  • what you mean inside service? its local service on the computer which has admin rights – avi.tavdi Feb 19 '14 at 17:25
  • First example looks wrong: should probably be `System.Diagnostics.Process.Start("@C:\QcOSD.txt");` (no trailing back-slash). Also not sure if `Process.Start` does shell execute, so it may not be able to "run" .txt files. So better test (combining your two examples is `System.Diagnostics.Process.Start(@"D:\test.bat");` – LB2 Feb 19 '14 at 17:39
  • @LB2 the escape chars, the double '\' is used for escaping and the code is working well on console application like i mentioned, but still i tried what you suggested and still not working – avi.tavdi Feb 19 '14 at 17:43
  • @noobcoder, then back to @Scott's question. If it is working from console, then how is DLL being used when it is not working. Can you put a test of some sort to see if your function in that context is being called (e.g. `MessageBox.Show`)? – LB2 Feb 19 '14 at 17:49
  • @LB2 the dll is used as plugin to program which i dont have access to its code, the function is running entirely since i put logs during its run and all logs are written, in addition if i add `p.waitForExit()` after the `p.Start();` then it waits forever and nothing happens and the external program is waiting for the proces to finish which never happans, i also tried different kind of plugin which writes to file and another which sends email and both working. – avi.tavdi Feb 20 '14 at 07:49
  • solution that worked for me: i went to the local service that runs the dll and in properties->Log On i checked **"Allow Service to interact with desktop"**, the file now opens in the environment of the service, it is actually related to the other post mentioned here but not duplicate in my opinion – avi.tavdi Feb 20 '14 at 08:08

0 Answers0