Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

seperate windows update and winget py #5

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}")