# Restart Windows service with a script

**URL:** <https://forum.inductiveautomation.com/t/restart-windows-service-with-a-script/3226>\
**Category:** Ignition\
**Created:** [August 27, 2011, 1:00pm UTC](https://forum.inductiveautomation.com/t/restart-windows-service-with-a-script/3226 "2011-08-27T13:00:00Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex.ferrell](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@alex.ferrell](https://forum.inductiveautomation.com/u/alex.ferrell)\
**Post date:** [August 27, 2011, 1:00pm UTC](https://forum.inductiveautomation.com/t/restart-windows-service-with-a-script/3226/1 "2011-08-27T13:00:00Z")

</div>

I am looking for some direction writing a script. Basically, I need to rename a couple of \*.ini files and then restart a Windows service. I found some information using the Python os library to do the renaming. I also ran across some information using the Python for Windows extension which adds a win32serviceutil library, but I’d rather use something already built into Ignition. Does anyone out there have experience with this?

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [August 27, 2011, 1:38pm UTC](https://forum.inductiveautomation.com/t/restart-windows-service-with-a-script/3226/2 "2011-08-27T13:38:26Z")

</div>

could you write a batch file to do this and then make ignition call the batch file in a script?

---

<div class="post-metadata">

**Author:** ![alex.ferrell](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@alex.ferrell](https://forum.inductiveautomation.com/u/alex.ferrell)\
**Post date:** [August 27, 2011, 1:40pm UTC](https://forum.inductiveautomation.com/t/restart-windows-service-with-a-script/3226/3 "2011-08-27T13:40:45Z")

</div>

Sure, that’s one option. I would like to keep it “invisible” if possible instead of launching a separate command window, but that would work.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 29, 2011, 1:01pm UTC](https://forum.inductiveautomation.com/t/restart-windows-service-with-a-script/3226/4 "2011-08-29T13:01:51Z")

</div>

So far, the only way I can seem to get this to work is through a batch file. On the bright side, the command prompt window does not pop up, even for an instant.

Also, I could get NET START and NET STOP to work in the playground, but no SC commands. As another head-banging-on-wall experience, the script I used in the playground, I can’t get to work in a project.

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [August 29, 2011, 2:58pm UTC](https://forum.inductiveautomation.com/t/restart-windows-service-with-a-script/3226/5 "2011-08-29T14:58:29Z")

</div>

Just wanted to make a note. If you are calling a batch file from the client or designer (script playground) you may have different permissions than if you call it from a gateway side script. When you call it from the client you are running it in the same user account as who is logged in. When you run it on the gateway you ca running it under the user set to logon by default on the Windows service. By default it is the local system account which doesn’t have a lot of privileges.

Also, if you are running Windows 7 you may have to run the client as an administrator before running the script. Hope this helps.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 29, 2011, 7:19pm UTC](https://forum.inductiveautomation.com/t/restart-windows-service-with-a-script/3226/6 "2011-08-29T19:19:21Z")

</div>

Yeah, I figured it was a permissions issue. Giving the Ignition Service to a Power User account solved it for running on a Gateway Script.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 29, 2011, 7:40pm UTC](https://forum.inductiveautomation.com/t/restart-windows-service-with-a-script/3226/7 "2011-08-29T19:40:24Z")

</div>

Well, almost, anyway. Running as a power user broke the OPC-DA connection to Kepware.

Everything does work when logging the service in as an admin, long enough to figure out the DCOM permissions. Definitely a bit of trial and error to get all the permissions set to lock things down.

---

<div class="post-metadata">

**Author:** ![alex.ferrell](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@alex.ferrell](https://forum.inductiveautomation.com/u/alex.ferrell)\
**Post date:** [September 19, 2011, 1:41pm UTC](https://forum.inductiveautomation.com/t/restart-windows-service-with-a-script/3226/8 "2011-09-19T13:41:43Z")

</div>

Well, I created a batch file that does exactly what I want and works well. The trouble I am having now is that the batch file needs to be run locally on the server, not on the client computer. I tried using the openURL command in a script module but it runs on the client PC. I then put the openURL command on a gateway script and couldn’t get it to do anything. How can I launch a batch file on the server from a client connection?

---

<div class="post-metadata">

**Author:** ![nathan](https://avatars.discourse-cdn.com/v4/letter/n/c5a1d2/32.png) [@nathan](https://forum.inductiveautomation.com/u/nathan)\
**Post date:** [September 19, 2011, 3:18pm UTC](https://forum.inductiveautomation.com/t/restart-windows-service-with-a-script/3226/9 "2011-09-19T15:18:29Z")

</div>

Alex, did you get the permissions issue sorted out? That is, try manually starting Ignition with “run as administrator” then having a gateway script periodically poll for some condition (like a DB SQLtag) to run the script. If this works, it’s an issue of the permission that the Ignition user account has.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 19, 2011, 4:03pm UTC](https://forum.inductiveautomation.com/t/restart-windows-service-with-a-script/3226/10 "2011-09-19T16:03:57Z")

</div>

One of the thing I found is that on a reststart of the server, Ignition wouldn’t start back up on an admin  
user 👿

So, secret option ‘B’ could be to set a scheduled task on the server to run once and then run it.

```auto
set machine=targetMachine
set file=\\path\to\the\file.bat
set user=myUserName
set userPwd=myPassword
set executeAs=%user%
set executeAsPwd=%userPwd%
schtasks /Create /S %machine% /U %user% /P %userPwd% /RU %executeAs% /RP %executeAsPwd% 
         /SC ONCE /TN install /TR %file% /ST 00:00:00
schtasks /Run /S %machine% /U %user% /P %userPwd% /TN install
```

Anyone got a cat to skin?

---

<div class="post-metadata">

**Author:** ![Automate](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@Automate](https://forum.inductiveautomation.com/u/Automate)\
**Post date:** [July 15, 2020, 11:49am UTC](https://forum.inductiveautomation.com/t/restart-windows-service-with-a-script/3226/11 "2020-07-15T11:49:47Z")

</div>

Also need to start / stop a Windows service from a Gateway script. Have any changes to Ignition been made in the last 9 years to accomplish this better than running a batch file?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 15, 2020, 1:41pm UTC](https://forum.inductiveautomation.com/t/restart-windows-service-with-a-script/3226/12 "2020-07-15T13:41:32Z")

</div>

> [@Automate](#):
>
> changes to Ignition been made in the last 9 years

If you want manageability, the change you are looking for is to replace Windows with Linux, in my not-so-humble opinion. {/snark}

---

<div class="post-metadata">

**Author:** ![Dustin\_VanKeuren](https://avatars.discourse-cdn.com/v4/letter/d/b782af/32.png) [@Dustin\_VanKeuren](https://forum.inductiveautomation.com/u/Dustin_VanKeuren)\
**Post date:** [February 27, 2025, 3:15pm UTC](https://forum.inductiveautomation.com/t/restart-windows-service-with-a-script/3226/13 "2025-02-27T15:15:41Z")

</div>

If only it were that easy!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 27, 2025, 4:57pm UTC](https://forum.inductiveautomation.com/t/restart-windows-service-with-a-script/3226/14 "2025-02-27T16:57:38Z")

</div>

It is _ **technically** _ that easy. The non-easy parts are _cultural_ and _political_.

---

<div class="post-metadata">

**Author:** ![Dustin\_VanKeuren](https://avatars.discourse-cdn.com/v4/letter/d/b782af/32.png) [@Dustin\_VanKeuren](https://forum.inductiveautomation.com/u/Dustin_VanKeuren)\
**Post date:** [February 27, 2025, 7:47pm UTC](https://forum.inductiveautomation.com/t/restart-windows-service-with-a-script/3226/15 "2025-02-27T19:47:55Z")

</div>

Yep, those last two are always a pain.
