title: Jenkins windows slave offline
body: <p>I have Jenkins 2.164.3 on a CentOS 7 server.<br>
  I have a Windows Server 2003 slave with Java version 1.8.0.<br>
  I have 3 x linux slaves working successfully.<br>
  The windows service on the slave is installed and running.<br>
  The windows slave is setup with the following with Launch Method "Let jenkins control this Windows salve as a Windows server"  </p>
  
  <p>This Jenkins server is a new server that replaced an older jenkins server (debian wheezy from turnkey linux ~3 years ago). This windows slave used to connect to that old server.  To remove the connection on this slave to the old server, I did the following: 
  1. sc  delete<br>
  2. deleted the files in folder c:\jenkins<br>
  3. rebooted server<br>
  4. from new jenkins server, launched slave which copied files to c:\jenkins folder and installed service.  </p>
  
  <p>On my new jenkins server, I setup the windows slave and when I connect, the log has the following:</p>
  
  <pre><code>[2019-05-27 12:24:07] [windows-slaves] Connecting to 192.168.1.152
  Checking if Java exists
  java -version returned 1.8.0.
  [2019-05-27 12:24:16] [windows-slaves] Copying jenkins-slave.xml
  [2019-05-27 12:24:16] [windows-slaves] Copying slave.jar
  [2019-05-27 12:24:16] [windows-slaves] Starting the service
  [2019-05-27 12:24:16] [windows-slaves] Waiting for the service to become ready
  ERROR: [2019-05-27 12:24:52] [windows-slaves] The service did not respond. Perhaps it failed to launch?
  [2019-05-27 12:36:00] [windows-slaves] Connecting to 192.168.1.152
  Checking if Java exists
  java -version returned 1.8.0.
  [2019-05-27 12:36:08] [windows-slaves] Copying jenkins-slave.xml
  [2019-05-27 12:36:08] [windows-slaves] Copying slave.jar
  [2019-05-27 12:36:08] [windows-slaves] Starting the service
  ERROR: Unexpected error in launching an agent. This is probably a bug in Jenkins
  org.jinterop.dcom.common.JIException: Service Already Running
      at org.jvnet.hudson.wmi.Win32Service$Implementation.start(Win32Service.java:149)
  Caused: java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.kohsuke.jinterop.JInteropInvocationHandler.invoke(JInteropInvocationHandler.java:140)
  Caused: java.lang.reflect.UndeclaredThrowableException
      at com.sun.proxy.$Proxy90.start(Unknown Source)
      at hudson.os.windows.ManagedWindowsServiceLauncher.launch(ManagedWindowsServiceLauncher.java:342)
      at hudson.slaves.SlaveComputer$1.call(SlaveComputer.java:294)
      at jenkins.util.ContextResettingExecutorService$2.call(ContextResettingExecutorService.java:46)
      at jenkins.security.ImpersonatingExecutorService$2.call(ImpersonatingExecutorService.java:71)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      at java.lang.Thread.run(Thread.java:748)
  </code></pre>
  
  <p>The windows slave is Windows Server 2003, the service is installed and running.</p>
  
  <p>In the log file C:\Jenkins\jenkins-slave.wrapper.log, it has the following:</p>
  
  <pre><code>2019-05-27 12:19:32,644 INFO  - Starting ServiceWrapper in the service mode
  2019-05-27 12:19:32,659 INFO  - Starting javaw.exe -Xrs  -jar "C:\Jenkins\slave.jar" -tcp "C:\Jenkins\port.txt"
  2019-05-27 12:19:32,675 INFO  - Extension loaded: killOnStartup
  2019-05-27 12:19:32,675 DEBUG - Checking the potentially runaway process with PID=1408
  2019-05-27 12:19:32,675 DEBUG - No runaway process with PID=1408. The process has been already stopped.
  2019-05-27 12:19:32,675 INFO  - Starting javaw.exe -Xrs  -jar "C:\Jenkins\slave.jar" -tcp "C:\Jenkins\port.txt"
  2019-05-27 12:19:32,691 INFO  - Started process 4084
  2019-05-27 12:19:32,691 DEBUG - Forwarding logs of the process System.Diagnostics.Process (javaw) to winsw.SizeBasedRollingLogAppender
  2019-05-27 12:19:32,691 INFO  - Recording PID of the started process:4084. PID file destination is C:\Jenkins\jenkins_agent.pid
  2019-05-27 12:23:56,529 INFO  - Stopping jenkinsslave-C__Jenkins
  2019-05-27 12:23:56,529 DEBUG - ProcessKill 4084
  2019-05-27 12:23:56,561 INFO  - Stopping process 4084
  2019-05-27 12:23:56,561 INFO  - Send SIGINT 4084
  2019-05-27 12:23:56,561 WARN  - SIGINT to 4084 failed - Killing as fallback
  2019-05-27 12:23:56,561 INFO  - Finished jenkinsslave-C__Jenkins
  2019-05-27 12:23:56,561 DEBUG - Completed. Exit code is 0
  2019-05-27 12:24:16,374 INFO  - Starting ServiceWrapper in the service mode
  2019-05-27 12:24:16,390 INFO  - Starting javaw.exe -Xrs  -jar "C:\Jenkins\slave.jar" -tcp "C:\Jenkins\port.txt"
  2019-05-27 12:24:16,405 INFO  - Extension loaded: killOnStartup
  2019-05-27 12:24:16,405 DEBUG - Checking the potentially runaway process with PID=4084
  2019-05-27 12:24:16,405 DEBUG - No runaway process with PID=4084. The process has been already stopped.
  2019-05-27 12:24:16,405 INFO  - Starting javaw.exe -Xrs  -jar "C:\Jenkins\slave.jar" -tcp "C:\Jenkins\port.txt"
  2019-05-27 12:24:16,421 INFO  - Started process 364
  2019-05-27 12:24:16,421 DEBUG - Forwarding logs of the process System.Diagnostics.Process (javaw) to winsw.SizeBasedRollingLogAppender
  2019-05-27 12:24:16,421 INFO  - Recording PID of the started process:364. PID file destination is C:\Jenkins\jenkins_agent.pid
  </code></pre>
  
  <p>The error on the jenkins server shows the service is not running. On the windows slave machine, the service is running. What is the problem and how do I fix?  </p>
  
  <p>Thanks.</p>