Error launching Service on Windows Server 2019

Anonymous
2024-04-12T19:42:07+00:00

OS :Windows Server 2019

Issue: Services

Hi wondering if you could assist me with the following error, i have a .jar file that runs POST services i need that jar file to run as a service on Microsoft server 2019, then I have the .exe but when I create a new service "sc \SERVER Service_Name path=C:\XXX" and then try to run the service from Services console said

the "service Name" on the Local Computer started and then stopped

just to add the jar file run fine doing manually "java -jar XXXX.jar" and I'm adding the event log where the file is properly located, i changed the location several times

Event Log :

Service cannot be started. System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified

   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)

   at winsw.Util.ProcessHelper.StartProcessAndCallbackForExit(Process processToStart, String executable, String arguments, Dictionary2 envVars, String workingDirectory, Nullable1 priority, ProcessCompletionCallback callback, Boolean redirectStdin, LogHandler logHandler)

   at winsw.WrapperService.StartProcess(Process processToStart, String arguments, String executable, LogHandler logHandler, Boolean redirectStdin)

   at winsw.WrapperService.OnStart(String[] _)

   at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)

Windows Server | Identity and access

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question. To protect privacy, user profiles for migrated questions are anonymized.

0 comments No comments
{count} votes
Accepted answer
  1. Anonymous
    2024-04-18T14:03:58+00:00

    Dear Daisy Zhou

    thanks for the information above, unfortunately, none of those help my issue since as soon nobody logs into the system the process just die, but I found the solution the error was because the JAVA_HOME was set with the wrong path, for some reason the command works but when the service wanted to start the java program retrieved a timeout, the solution was set the JAVA_HOME till JRE and then on the PATH add the Bin folder

    again thanks for your help

    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Anonymous
    2024-04-15T11:33:04+00:00

    Hello ldiego900,

    Thank you for posting in Microsoft Community forum.

    Based on the event log description "Service cannot be started. System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified", it seems it did not locate the correct file "java -jar XXXX.jar".

    Please check if you have more than one version of the Java.

    Please check if you change the file to another path and change the path in services console ("sc \SERVER Service_Name path=C:\XXX"), check if it helps.

    Here are two threads with the same error message, but not similar threads. You can read them.

    Jenkins fails to start on Windows Server after Java Runtime update uninstalled older version of JRE - Server Fault

    how to fix System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified in C# - Microsoft Q&A

    I hope the information above is helpful.

    If you have any question or concern, please feel free to let us know.

    Best Regards,
    Daisy Zhou

    0 comments No comments
  2. Anonymous
    2024-04-15T14:52:58+00:00

    Dear Daisy Zhou,

    Thank you for your ongoing support. I’ve reviewed the resources you provided, but it seems they don’t quite match my setup. I’m not utilizing a Jenkins server, and the Java code path definition in the second link differs from my requirements. Despite altering the file path as you suggested, the issue persists.

    However, the .jar file executes without issues when run manually or via a batch job. With this in mind, I’m seeking your expertise on two fronts:

    1. Service Creation: I aim to create a service from a batch file or a .jar file on Windows Server 2019, but I’m struggling to find comprehensive documentation for this process.
    2. Background Execution: I’m looking for a method to ensure the .jar file executes in the background as soon as the server starts. Currently, the batch file I placed in the startup folder only initiates upon user login.

    Any assistance or pointers you could provide on these matters would be greatly appreciated.

    Best regards,

    0 comments No comments
  3. Anonymous
    2024-04-16T08:22:34+00:00

    Hello ldiego900,

    Good day!

    *I aim to create a service from a batch file or a .jar file on Windows Server 2019.*A1: You can read this article.
    Creating A Batch File To Stop And Start A Windows Service (jackworthen.com)

    the .jar file executes in the background as soon as the server starts.
    A2: If you can run the .jar file as a script, you can deploy Startup script via local group policy below.

    If you have any question or concern, please feel free to let us know.

    Best Regards,
    Daisy Zhou

    0 comments No comments
  4. Anonymous
    2024-04-18T14:46:42+00:00

    Hello ldiego900,

    Good day!

    Thank you for your update and sharing.

    I am so glad that the problem has been resolved.

    Have a nice day!

    Best Regards,
    Daisy Zhou

    0 comments No comments