Skip to content

Commit

Permalink
Merge pull request #5 from grubyhs/feature/placzykowski/move-winget-a…
Browse files Browse the repository at this point in the history
…nd-windows-update-to-seperate-py

seperate windows update and winget py
  • Loading branch information
piotrlaczykowski authored Jun 14, 2024
2 parents 7a53e98 + 72979eb commit 8db8b7f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 29 deletions.
2 changes: 2 additions & 0 deletions update-pc-script-auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from utilities import *
from motherboard import *
from chocolatey import *
from winget import *
from windows_update import *

if __name__ == "__main__":
if run_as_admin():
Expand Down
2 changes: 2 additions & 0 deletions update-pc-script.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from motherboard import *
from utilities import *
from chocolatey import *
from winget import *
from windows_update import *

if __name__ == "__main__":
if run_as_admin():
Expand Down
30 changes: 1 addition & 29 deletions utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,32 +74,4 @@ def install_program(installer_path, program_name):
except subprocess.CalledProcessError as e:
print(f"Error installing {program_name}: {e}")
else:
print("Error: Installer not found.")

def winget_upgrade():
# Upgrade all installed packages using winget
try:
subprocess.run(["winget", "upgrade", "--all", "--accept-source-agreements", "--accept-package-agreements", "--allow-reboot"], check=True,)
print("All installed packages upgraded successfully.")
except subprocess.CalledProcessError as e:
print(f"Error upgrading packages with winget: {e}")

def windows_update():
try:
print("Checking for Windows updates...")

# Install the PSWindowsUpdate module if not already installed
ps_install_command = (
"Install-Module PSWindowsUpdate -Force -AllowClobber -Scope AllUsers; "
"Set-ExecutionPolicy Bypass -Scope Process -Force; "
"Import-Module PSWindowsUpdate -Force;"
"$serviceManager = New-Object -ComObject 'Microsoft.Update.ServiceManager';"
"$serviceManager.AddService2('7971f918-a847-4430-9279-4a52d1efe18d',7,'');"
"Install-WindowsUpdate -AcceptAll -AutoReboot -IgnoreUserInput;"
)

subprocess.run(["powershell", "-ExecutionPolicy", "Bypass", "-Command", ps_install_command], check=True)

print("Windows updates checked and installed successfully.")
except subprocess.CalledProcessError as e:
print(f"Error checking or installing Windows updates: {e}")
print("Error: Installer not found.")
21 changes: 21 additions & 0 deletions windows_update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import subprocess

def windows_update():
try:
print("Checking for Windows updates...")

# Install the PSWindowsUpdate module if not already installed
ps_install_command = (
"Install-Module PSWindowsUpdate -Force -AllowClobber -Scope AllUsers; "
"Set-ExecutionPolicy Bypass -Scope Process -Force; "
"Import-Module PSWindowsUpdate -Force;"
"$serviceManager = New-Object -ComObject 'Microsoft.Update.ServiceManager';"
"$serviceManager.AddService2('7971f918-a847-4430-9279-4a52d1efe18d',7,'');"
"Install-WindowsUpdate -AcceptAll -AutoReboot -IgnoreUserInput;"
)

subprocess.run(["powershell", "-ExecutionPolicy", "Bypass", "-Command", ps_install_command], check=True)

print("Windows updates checked and installed successfully.")
except subprocess.CalledProcessError as e:
print(f"Error checking or installing Windows updates: {e}")
9 changes: 9 additions & 0 deletions winget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import subprocess

def winget_upgrade():
# Upgrade all installed packages using winget
try:
subprocess.run(["winget", "upgrade", "--all", "--accept-source-agreements", "--accept-package-agreements", "--allow-reboot"], check=True,)
print("All installed packages upgraded successfully.")
except subprocess.CalledProcessError as e:
print(f"Error upgrading packages with winget: {e}")

0 comments on commit 8db8b7f

Please sign in to comment.