1

I have a Windows Service with a task to run an .exe file when its scheduled time arrives. This program has worked under all devices that I have installed my program in. The user who runs the service has all the required administrative rights.

This is the code where the program runs the .exe file. The Log() function writes the message in a log file.

Log("About to run the file...");
try
{
    Process.Start(filePath, args);
    Log("File Triggered!");
}
catch (Exception ex)
{
    Log("Error.");
}

What happens is that the program works up until logging "About to run the file..." and then nothing happens and nothing is logged. This is very strange knowing the exact same program works fine in all other environments I have tested.

Is it possible that Process.Start() silently and without an error refuses to run my .exe file? The target .exe file is placed in the exact same folder as the running service so that cannot be a problem.

Does the Log On user of my service lack the authority to run this file? If so, why don't we receive the "Error" message in the log? Would appreciate any help!

Update 1: The target OS is Windows 8 and I have developed my program under Windows 7.

Update 2: I tried the program on another machine running Windows 8.1 and it was working fine.

disasterkid
  • 6,948
  • 25
  • 94
  • 179
  • The same question I have asked few years back http://stackoverflow.com/questions/12953148/show-a-windows-form-from-a-window-service – Mohammad Arshad Alam Apr 21 '15 at 11:37
  • @oleksii I cannot do what exactly? I have done it before with the same program. – disasterkid Apr 21 '15 at 11:42
  • @oleksii But as I have written, it is working on all other machines. As we are speaking I asked a colleague of mine to run the program on his machine (Windows 8.1) and the program was run fine. This is the only machine in which the scenario does not work. So please do not mark this question as a duplicate because I still haven't found my answer. – disasterkid Apr 21 '15 at 11:47
  • Couple of relevant questions: http://stackoverflow.com/q/1369236/706456 and http://stackoverflow.com/q/5307968/706456 – oleksii Apr 21 '15 at 11:53
  • @oleksii I really have nothing to lie about when I say it works on all other machines. Thanks for unmarking the question anyway. – disasterkid Apr 21 '15 at 11:53
  • @oleksii apart from the main question, another part of my question is still unanswered. Even if `Process.Start()` does not work why I only get the first log message and not the second one that tells me there has been an error? – disasterkid Apr 21 '15 at 12:01
  • 1
    Because the process actually starts and the call returns successful message as far as I remember. However, Windows immediately determines that this application requires a GUI, but the context that it was started from doesn't provide GUI capabilities and Windows terminates your process. If you debug it on that machine, you would see that there are no errors on the process start line. You would see your `File Triggered!` message, but the process will be terminated by that line. It's just Windows implementation details. – oleksii Apr 21 '15 at 12:06
  • @oleksii you mean the process will be terminated right after `Process.Start()` and will not reach the "File Triggered!" log message? – disasterkid Apr 21 '15 at 12:10
  • Oh, no. The other process. You Windows Service process should be running happily, but the process that you start by `Process.Start()` will report as started and will be terminated immediately. Is this what you see? – oleksii Apr 21 '15 at 12:15
  • @oleksii all I am seeing is that nothing is logged after the first "About to run the file..." message. Even if the other process is started and terminated immediately as you say, I should receive the "File Triggered!" message right? But I don't see anything in my log. – disasterkid Apr 21 '15 at 12:47

1 Answers1

0

Windows Server 2012 blocks all the files copied from other places. So I unblocked all the program files. Thanks for your help.

disasterkid
  • 6,948
  • 25
  • 94
  • 179