V
V
vadimeasy2021-10-26 15:29:42
Python
vadimeasy, 2021-10-26 15:29:42

How can I set the program to Automatic mode on a Windows service?

I can't find any information on how to edit Windows "Services" settings. At work, I need to install OpenVPN on clients' computers, it is installed with "manual" control and I need to change it to "Automatic", I want to automate this process in order to, for example, write a script and set up the VPN client, the client himself launched the following file and all the settings were applied to him , also, ideally, it would be in the same file with a change in the Widnows "Services" settings to push the code that opens a specific port in the Firewall, so far it was possible to automate this action only through PyAutiGUI.

import pyautogui as pg 
import time
import os 
from key import command, command1, command2 

os.startfile('powershell', 'runas')
time.sleep(3)
pg.typewrite(command)
pg.typewrite(command1, 0.01)
pg.typewrite(command2, 0.01)

time.sleep(1)

pg.hotkey("enter")


File "Key.py"

command = ('New-NetFirewallRule -DisplayName "UTM_transport"')
command1 = (' -Profile @("Domain", "Private") ')
command2 = ("-Direction Inbound -Action Allow -Protocol TCP -LocalPort @('8228')")

Maybe with Firewaller you can somehow come up with a friend so that it is programmatically, through EXE in some way or in some other way, please advise which library to turn to or is there some kind of software so that it can be easily automated?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MaxKozlov, 2021-10-26
@vadimeasy

If I understand you correctly, then through powershell you can specify the startup type for the service like this

Get-Service openvpn | Set-Service -StartupType Automatic

I don’t remember exactly how the openvpn service is called, so tighten up
the powershell script itself, you can run it like
powershell -file filename.ps1
and write all the necessary commands in filename.ps1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question