# Running a bat script as a different user

**URL:** <https://community.jenkins.io/t/running-a-bat-script-as-a-different-user/6548>\
**Category:** Using Jenkins\
**Created:** [March 29, 2023, 7:58pm UTC](https://community.jenkins.io/t/running-a-bat-script-as-a-different-user/6548 "2023-03-29T19:58:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![marbda](https://avatars.discourse-cdn.com/v4/letter/m/6bbea6/32.png) [@marbda](https://community.jenkins.io/u/marbda)\
**Post date:** [March 29, 2023, 7:58pm UTC](https://community.jenkins.io/t/running-a-bat-script-as-a-different-user/6548/1 "2023-03-29T19:58:00Z")

</div>

I configured jenkins in windows 2019  
It starts as domain\jenkins service  
I have configured WindowsServer1 node  
What should I do to make the \*.bat script on WindowsServer1 run as a different user?

Should the agent on WindowsServer1 be run under the user under which the script is to run?

curl -sO [http://node1:8080/jnlpJars/agent.jar](http://node1:8080/jnlpJars/agent.jar)  
java -jar agent.jar -jnlpUrl [http://node1:8080/manage/computer/node1/jenkins-agent.jnlp](http://node1:8080/manage/computer/node1/jenkins-agent.jnlp) -secret cb19\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* \*\*\*\*c7f06b71da61 -workDir “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:** [March 29, 2023, 7:59pm UTC](https://community.jenkins.io/t/running-a-bat-script-as-a-different-user/6548/2 "2023-03-29T19:59:52Z")

</div>

Yes, you would want the agent to run as the user you want things to run as on the agent.

---

<div class="post-metadata">

**Author:** ![marbda](https://avatars.discourse-cdn.com/v4/letter/m/6bbea6/32.png) [@marbda](https://community.jenkins.io/u/marbda)\
**Post date:** [March 29, 2023, 8:03pm UTC](https://community.jenkins.io/t/running-a-bat-script-as-a-different-user/6548/3 "2023-03-29T20:03:13Z")

</div>

I don’t know if we understand each other  
I run Jenkins on node1 as domain\jenkins

On WindowsServer1 (agent) I want to run script.bat as WindowsServer1\users1

Do I have an agent  
curl -sO [http://node1:8080/jnlpJars/agent.jar](http://node1:8080/jnlpJars/agent.jar)  
java -jar agent.jar -jnlpUrl [http://node1:8080/manage/computer/node1/jenkins-agent.jnlp](http://node1:8080/manage/computer/node1/jenkins-agent.jnlp) -secret cb19\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* \*\*\*\*c7f06b71da61 -workDir “c:\jenkins”

Run as WindowsServer1\users1 ?

---

<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:** [March 29, 2023, 8:23pm UTC](https://community.jenkins.io/t/running-a-bat-script-as-a-different-user/6548/4 "2023-03-29T20:23:38Z")

</div>

Yes, that is exactly what I was saying. You need to launch the agent as the user you want stuff to run as. So, as you said in your case, run the java command as WindowsServer1\users1, then all processes/scripts/etc. will run as that user on the agent.
