# Windows Agent does not want to stay active

**URL:** <https://community.jenkins.io/t/windows-agent-does-not-want-to-stay-active/5890>\
**Category:** Ask a question\
**Tags:** question, windows\
**Created:** [February 21, 2023, 8:08am UTC](https://community.jenkins.io/t/windows-agent-does-not-want-to-stay-active/5890 "2023-02-21T08:08:49Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lokutus25](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@Lokutus25](https://community.jenkins.io/u/Lokutus25)\
**Post date:** [February 21, 2023, 8:08am UTC](https://community.jenkins.io/t/windows-agent-does-not-want-to-stay-active/5890/1 "2023-02-21T08:08:49Z")

</div>

I have two Windows 10 machines on which I want to run the agent. The first machine works without problems, but on the second machine the agent does not want to stay active.

I have set up the start of the agent via a batch in the task scheduler. On the first machine the batch starts when the machine is started, on the second machine the batch is also started, but is immediately closed as successful again. (action “C:\Windows\SYSTEM32\cmd.exe” with return code 0.)

Does anyone know this phenomenon? The machines are set up identically and also the tasks in the scheduler are set up identically.

---

<div class="post-metadata">

**Author:** ![slide\_o\_mix](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/slide_o_mix/32/20977_2.png) [@slide\_o\_mix](https://community.jenkins.io/u/slide_o_mix)\
**Post date:** [February 21, 2023, 12:41pm UTC](https://community.jenkins.io/t/windows-agent-does-not-want-to-stay-active/5890/2 "2023-02-21T12:41:10Z")

</div>

Have you checked the logs on the agent that is not working? It should be in the working directory setup in the agent config in the controller UI

---

<div class="post-metadata">

**Author:** ![Lokutus25](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@Lokutus25](https://community.jenkins.io/u/Lokutus25)\
**Post date:** [February 21, 2023, 1:14pm UTC](https://community.jenkins.io/t/windows-agent-does-not-want-to-stay-active/5890/3 "2023-02-21T13:14:09Z")

</div>

Unfortunately, there is no log.  
I only have the message from the task scheduler that the task was successfully completed.  
If I start the batch manually everything works. Only the Task Scheduler does not leave it open but simply closes it.  
The batch is configured identically as on machine 1. Of course, the name and the secret key is adjusted.

That’s my Batch:  
`"C:\Program Files\Java\jdk-11\bin\java.exe" -jar "c:\jenkins\agent.jar" -jnlpUrl http://xxx.de:8082/manage/computer/WindowsAgent02/jenkins-agent.jnlp -secret @secret-file`

---

<div class="post-metadata">

**Author:** ![slide\_o\_mix](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/slide_o_mix/32/20977_2.png) [@slide\_o\_mix](https://community.jenkins.io/u/slide_o_mix)\
**Post date:** [February 21, 2023, 2:31pm UTC](https://community.jenkins.io/t/windows-agent-does-not-want-to-stay-active/5890/4 "2023-02-21T14:31:59Z")

</div>

Is the scheduled task setup under the same user account on both machines? Does that user have write access to the C:\Jenkins directory?

---

<div class="post-metadata">

**Author:** ![Lokutus25](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@Lokutus25](https://community.jenkins.io/u/Lokutus25)\
**Post date:** [February 21, 2023, 2:33pm UTC](https://community.jenkins.io/t/windows-agent-does-not-want-to-stay-active/5890/5 "2023-02-21T14:33:57Z")

</div>

yes to both. I’ve added the Tasks on both mashines with the same User-credentials.  
The User is an Admin User and have full access on C:\Jenkins

---

<div class="post-metadata">

**Author:** ![slide\_o\_mix](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/slide_o_mix/32/20977_2.png) [@slide\_o\_mix](https://community.jenkins.io/u/slide_o_mix)\
**Post date:** [February 21, 2023, 3:09pm UTC](https://community.jenkins.io/t/windows-agent-does-not-want-to-stay-active/5890/6 "2023-02-21T15:09:57Z")

</div>

What about Java version on each machine? You say there is not a log, but the scheduled task succeeds? Does your bat file `exit /b %ERRORLEVEL%` after the java line?

---

<div class="post-metadata">

**Author:** ![slide\_o\_mix](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/slide_o_mix/32/20977_2.png) [@slide\_o\_mix](https://community.jenkins.io/u/slide_o_mix)\
**Post date:** [February 21, 2023, 3:12pm UTC](https://community.jenkins.io/t/windows-agent-does-not-want-to-stay-active/5890/7 "2023-02-21T15:12:50Z")

</div>

It might be good to join the gitter for jenkins, could get more realtime help. [https://app.gitter.im/#/room/#jenkinsci\_jenkins:gitter.im](https://app.gitter.im/#/room/#jenkinsci_jenkins:gitter.im)

---

<div class="post-metadata">

**Author:** ![mawinter69](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/mawinter69/32/1625_2.png) [@mawinter69](https://community.jenkins.io/u/mawinter69)\
**Post date:** [February 21, 2023, 11:00pm UTC](https://community.jenkins.io/t/windows-agent-does-not-want-to-stay-active/5890/8 "2023-02-21T23:00:01Z")

</div>

1. Add some echo steps before the java call and redirect them to a file. If the file exists you know that the batch is called properly.
2. redirect the output of the java call to a log file. The task scheduler is not capturing the output so if there is a problem in starting up java itself you will never find out what the cause is.

```auto
echo "Starting Jenkins agent" > c:\jenkins\agent.log
"C:\Program Files\Java\jdk-11\bin\java.exe" -jar "c:\jenkins\agent.jar" -jnlpUrl http://xxx.de:8082/manage/computer/WindowsAgent02/jenkins-agent.jnlp -secret @secret-file >> c:\jenkins\agent.log

```

---

<div class="post-metadata">

**Author:** ![Lokutus25](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@Lokutus25](https://community.jenkins.io/u/Lokutus25)\
**Post date:** [February 22, 2023, 7:32am UTC](https://community.jenkins.io/t/windows-agent-does-not-want-to-stay-active/5890/9 "2023-02-22T07:32:23Z")

</div>

I’ve edited the batch and got a agent.log. But there ist only 1 Line:  
“Starting Jenkins agent”

Even when I start the batch by hand.

I’ve deleted the first line “echo Start Jenkins…”, but the redirect to the log for the java line is still there.  
When I restart the machine, the logfile will created but it is empty

---

<div class="post-metadata">

**Author:** ![Lokutus25](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@Lokutus25](https://community.jenkins.io/u/Lokutus25)\
**Post date:** [February 22, 2023, 7:34am UTC](https://community.jenkins.io/t/windows-agent-does-not-want-to-stay-active/5890/10 "2023-02-22T07:34:22Z")

</div>

Both machines are new and I installed the same Java-Version on both.

---

<div class="post-metadata">

**Author:** ![Lokutus25](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@Lokutus25](https://community.jenkins.io/u/Lokutus25)\
**Post date:** [February 22, 2023, 8:08am UTC](https://community.jenkins.io/t/windows-agent-does-not-want-to-stay-active/5890/11 "2023-02-22T08:08:17Z")

</div>

I’ve got it!

I made a complete new batch-file with the following content:

```auto
cd C:\jenkins\
java -jar agent.jar -jnlpUrl http://xxx:8082/manage/computer/WindowsAgent02/jenkins-agent.jnlp -secret a8...

```

This file starts with Task Scheduler and is still running.

Thanks a lot for your help.

---

<div class="post-metadata">

**Author:** ![poddingue](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/poddingue/32/985_2.png) [@poddingue](https://community.jenkins.io/u/poddingue)\
**Post date:** [February 23, 2023, 8:23am UTC](https://community.jenkins.io/t/windows-agent-does-not-want-to-stay-active/5890/12 "2023-02-23T08:23:06Z")

</div>

Thanks a lot for your feedback @Lokutus25 .
