Bei Kompilieren weiß ich jetzt nicht, wie das Helfer-Skript funktioniert, um es auch separat zu kompilieren und es zu kompilieren Zeit zu verweisen (--add-binär "restart_Service_helper.exe ;."). Hilfe würde geschätzt
Hauptcode - zu lang für hier
https://pastebin.com/kvj1kj5m
restart_Service_Helper.py Code
Code: Select all
import ctypes
import subprocess
import sys
SERVICE_NAME = "dnscrypt-proxy"
def is_admin():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
def restart_service():
subprocess.check_call(["sc", "stop", SERVICE_NAME], shell=True)
subprocess.check_call(["sc", "start", SERVICE_NAME], shell=True)
print(f"Service '{SERVICE_NAME}' restarted successfully.")
if __name__ == "__main__":
if not is_admin():
# Relaunch the script with admin rights
ctypes.windll.shell32.ShellExecuteW(
None, "runas", sys.executable, f'"{__file__}"', None, 1
)
sys.exit()
try:
restart_service()
except subprocess.CalledProcessError as e:
print(f"Failed to restart service: {e}")
sys.exit(1)