Restart Windows service with a script

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?

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

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.

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.

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.

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.

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.

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?

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.

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

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

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?

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?

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