mirror of
https://github.com/JDM170/win_update_script
synced 2025-12-10 05:57:17 +07:00
Initial commit
This commit is contained in:
7
executionpolicies.txt
Normal file
7
executionpolicies.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
- 0 Unrestricted
|
||||
- 1 RemoteSigned
|
||||
- 2 AllSigned
|
||||
- 3 Restricted
|
||||
- 4 Bypass
|
||||
- 5 Undefined
|
||||
173
main.py
Normal file
173
main.py
Normal file
@@ -0,0 +1,173 @@
|
||||
from sys import exit
|
||||
from os import getcwd, remove
|
||||
from os.path import isfile, exists
|
||||
import ctypes
|
||||
import subprocess
|
||||
|
||||
|
||||
properties = {
|
||||
"wim": {
|
||||
"message": "\nВведите путь до wim-файла:\n",
|
||||
"path": "",
|
||||
"func": isfile
|
||||
},
|
||||
"mnt": {
|
||||
"message": "\nВведите путь до папки монтирования:\n",
|
||||
"path": "",
|
||||
"func": exists
|
||||
},
|
||||
"upd": {
|
||||
"message": "\nВведите путь до папки с обновлениями:\n",
|
||||
"path": "",
|
||||
"func": exists
|
||||
}
|
||||
}
|
||||
|
||||
ps1_script_path = getcwd() + "\\ps1_script.tmp.ps1"
|
||||
# ps1_script_raw = r"""Set-ExecutionPolicy -ExecutionPolicy Undefined -Scope Process
|
||||
ps1_script_raw = r"""{appslist}
|
||||
|
||||
Remove-WindowsImage -ImagePath {wimpath} -Index 3
|
||||
Remove-WindowsImage -ImagePath {wimpath} -Index 2
|
||||
Remove-WindowsImage -ImagePath {wimpath} -Index 1
|
||||
|
||||
Mount-WindowsImage -ImagePath {wimpath} -Index 1 -Path {mntpath}
|
||||
|
||||
reg load HKLM\onedrive_delete {mntpath}\Users\default\ntuser.dat
|
||||
reg delete HKLM\onedrive_delete\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\ /v OneDriveSetup /f
|
||||
reg unload HKLM\onedrive_delete
|
||||
|
||||
Get-AppxProvisionedPackage -Path {mntpath} | ForEach-Object {{
|
||||
if ($apps -contains $_.DisplayName) {{
|
||||
Write-Host Removing $_.DisplayName...
|
||||
Remove-AppxProvisionedPackage -Path {mntpath} -PackageName $_.PackageName | Out-Null
|
||||
}}
|
||||
}}
|
||||
|
||||
Add-WindowsPackage -Path {mntpath} -PackagePath {updpath}
|
||||
"""
|
||||
|
||||
bat_script_path = getcwd() + "\\bat_script.tmp.bat"
|
||||
bat_script_raw = r"""@echo off
|
||||
|
||||
dism /cleanup-image /image:"{mntpath}" /startcomponentcleanup /resetbase /scratchdir:"C:\Windows\Temp"
|
||||
|
||||
dism /unmount-wim /mountdir:"{mntpath}" /commit
|
||||
|
||||
dism /export-image /sourceimagefile:"{wimpath}" /sourceindex:1 /destinationimagefile:"{wimpath}.esd" /Compress:recovery
|
||||
|
||||
dism /cleanup-wim
|
||||
"""
|
||||
|
||||
apps = [
|
||||
"Microsoft.BingWeather",
|
||||
"Microsoft.GetHelp",
|
||||
"Microsoft.Getstarted",
|
||||
"Microsoft.Messaging",
|
||||
"Microsoft.Microsoft3DViewer",
|
||||
"Microsoft.MixedReality.Portal",
|
||||
"Microsoft.MicrosoftOfficeHub",
|
||||
"Microsoft.MicrosoftSolitaireCollection",
|
||||
"Microsoft.MicrosoftStickyNotes",
|
||||
"Microsoft.MSPaint",#Paint 3D (Windows 10)
|
||||
"Microsoft.Office.OneNote",
|
||||
"Microsoft.OneConnect",
|
||||
"Microsoft.People",
|
||||
"Microsoft.ScreenSketch",#Скриншоты (Windows 10 1809+)
|
||||
"Microsoft.YourPhone",#Ваш телефон (Windows 10 1809+)
|
||||
"Microsoft.Print3D",
|
||||
"Microsoft.SkypeApp",
|
||||
"Microsoft.ZuneMusic",
|
||||
"Microsoft.ZuneVideo",#Кино и ТВ
|
||||
"Microsoft.XboxApp"#Xbox (Windows 10)
|
||||
# "Microsoft.Windows.Cortana" # ?????
|
||||
]
|
||||
|
||||
w11_apps = [
|
||||
"Microsoft.WindowsAlarms",
|
||||
"Microsoft.WindowsCamera",
|
||||
"microsoft.windowscommunicationsapps",
|
||||
"Microsoft.WindowsFeedbackHub",
|
||||
"Microsoft.WindowsMaps",
|
||||
"Microsoft.WindowsSoundRecorder",
|
||||
"Microsoft.GamingApp",#Xbox (Windows 11)
|
||||
"Microsoft.PowerAutomateDesktop",#(Windows11)
|
||||
"Microsoft.Todos",#(Windows11)
|
||||
"Microsoft.BingNews",#Новости (Windows 11)
|
||||
"MicrosoftWindows.Client.WebExperience",#Виджеты (Windows 11)
|
||||
"Microsoft.Paint"#Paint (Windows11)
|
||||
]
|
||||
|
||||
|
||||
def is_admin():
|
||||
return ctypes.windll.shell32.IsUserAnAdmin() != 0
|
||||
|
||||
|
||||
def ask_input(message, checking_func):
|
||||
user_input = input(message)
|
||||
if not user_input or len(user_input) == 0 or not checking_func(user_input):
|
||||
ask_input(message, checking_func)
|
||||
else:
|
||||
return user_input
|
||||
|
||||
|
||||
def do_cleanup():
|
||||
if isfile(ps1_script_path):
|
||||
remove(ps1_script_path)
|
||||
if isfile(bat_script_path):
|
||||
remove(bat_script_path)
|
||||
mntpath = properties.get("mnt").get("path")
|
||||
if mntpath:
|
||||
subprocess.Popen("dism /unmount-wim /mountdir:\"{}\" /discard".format(mntpath)).wait()
|
||||
subprocess.Popen("dism /cleanup-wim").wait()
|
||||
|
||||
|
||||
def convert_applist_to_string():
|
||||
global apps
|
||||
result = "$apps = @(\n"
|
||||
for app in apps:
|
||||
result += "\t'{}',\n".format(app)
|
||||
return result[:-2] + "\n)"
|
||||
|
||||
|
||||
def main():
|
||||
global apps
|
||||
for keys, value in properties.items():
|
||||
if isinstance(value, dict):
|
||||
value["path"] = ask_input(value.get("message"), value.get("func"))
|
||||
if bool(input("\nWindows 10 (0) или Windows 11 (1) ?\n")):
|
||||
apps += w11_apps
|
||||
app_list = convert_applist_to_string()
|
||||
with open(ps1_script_path, mode="w") as f:
|
||||
f.write(ps1_script_raw.format(
|
||||
appslist=app_list,
|
||||
wimpath=properties.get("wim").get("path"),
|
||||
mntpath=properties.get("mnt").get("path"),
|
||||
updpath=properties.get("upd").get("path")
|
||||
)
|
||||
)
|
||||
with open(bat_script_path, mode="w") as f:
|
||||
f.write(bat_script_raw.format(
|
||||
mntpath=properties.get("mnt").get("path"),
|
||||
wimpath=properties.get("wim").get("path")
|
||||
)
|
||||
)
|
||||
# subprocess.Popen("powershell Unblock-File -Path {}".format(ps1_script_path)).wait()
|
||||
subprocess.Popen("powershell {}".format(ps1_script_path)).wait()
|
||||
subprocess.Popen("{}".format(bat_script_path)).wait()
|
||||
properties.get("wim")["path"] = ""
|
||||
properties.get("mnt")["path"] = ""
|
||||
properties.get("upd")["path"] = ""
|
||||
do_cleanup()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
if not is_admin():
|
||||
print("Запустите программу от имени администратора!")
|
||||
raise KeyboardInterrupt
|
||||
else:
|
||||
main()
|
||||
except KeyboardInterrupt:
|
||||
do_cleanup()
|
||||
exit()
|
||||
37
src/add_updates.ps1
Normal file
37
src/add_updates.ps1
Normal file
@@ -0,0 +1,37 @@
|
||||
# Добавление обновлений в образ
|
||||
|
||||
write-host ""
|
||||
write-host "Введите полный путь до wim-файла:"
|
||||
$wimpath = read-host
|
||||
|
||||
write-host ""
|
||||
write-host "Введите полный путь до папки монтирования:"
|
||||
$mntpath = read-host
|
||||
|
||||
write-host ""
|
||||
write-host "Введите полный путь до папки с обновлениями:"
|
||||
$updpath = read-host
|
||||
|
||||
write-host ""
|
||||
write-host "Нажмите Enter для запуска"
|
||||
read-host
|
||||
|
||||
$start_of_changes = [int](Get-Date -UFormat %s -Millisecond 0)
|
||||
|
||||
write-host ""
|
||||
write-host "Монтируем образ..."
|
||||
Mount-WindowsImage -ImagePath $wimpath -Index 1 -Path $mntpath
|
||||
|
||||
write-host ""
|
||||
write-host "Интегрируем обновления..."
|
||||
Add-WindowsPackage -Path $mntpath -PackagePath $updpath
|
||||
|
||||
write-host ""
|
||||
write-host "Сохраняем изменения..."
|
||||
Dismount-WindowsImage -Path $mntpath -Save
|
||||
Clear-WindowsCorruptMountPoint
|
||||
|
||||
$end_of_changes = [int](Get-Date -UFormat %s -Millisecond 0)
|
||||
write-host "Затраченное время (в минутах): " (($end_of_changes - $start_of_changes) / 60)
|
||||
|
||||
[gc]::Collect()
|
||||
24
src/finish.bat
Normal file
24
src/finish.bat
Normal file
@@ -0,0 +1,24 @@
|
||||
@echo off
|
||||
|
||||
set /P wim="Введите путь до wim-файла: "
|
||||
set /P mnt="Введите путь до папки монтирования: "
|
||||
|
||||
echo
|
||||
echo Mounting...
|
||||
dism /mount-wim /wimfile:%wim% /index:1 /mountdir:%mnt%
|
||||
|
||||
echo
|
||||
echo Starting cleanup image...
|
||||
dism /cleanup-image /image:%mnt% /startcomponentcleanup /resetbase /scratchdir:"C:\Windows\Temp"
|
||||
|
||||
echo
|
||||
echo Unmounting...
|
||||
dism /unmount-wim /mountdir:%mnt% /commit
|
||||
|
||||
echo
|
||||
echo Exporting complete image...
|
||||
dism /export-image /sourceimagefile:%wim% /sourceindex:1 /destinationimagefile:%wim%+".fin"
|
||||
|
||||
echo
|
||||
echo Cleaning up...
|
||||
dism /cleanup-wim
|
||||
98
src/update_wim-file_w10.ps1
Normal file
98
src/update_wim-file_w10.ps1
Normal file
@@ -0,0 +1,98 @@
|
||||
# Скрипт для внесения изменений в WIM-Файл (W10)
|
||||
|
||||
# Список приложений для удаления
|
||||
$apps = @(
|
||||
"Microsoft.BingWeather",
|
||||
"Microsoft.GetHelp",
|
||||
"Microsoft.Getstarted",
|
||||
"Microsoft.Messaging",
|
||||
"Microsoft.Microsoft3DViewer",
|
||||
"Microsoft.MixedReality.Portal",
|
||||
"Microsoft.MicrosoftOfficeHub",
|
||||
"Microsoft.MicrosoftSolitaireCollection",
|
||||
"Microsoft.MicrosoftStickyNotes",
|
||||
"Microsoft.MSPaint",#Paint 3D (Windows 10)
|
||||
"Microsoft.Office.OneNote",
|
||||
"Microsoft.OneConnect",
|
||||
"Microsoft.People",
|
||||
"Microsoft.ScreenSketch",#Скриншоты (Windows 10 1809+)
|
||||
"Microsoft.YourPhone",#Ваш телефон (Windows 10 1809+)
|
||||
"Microsoft.Print3D",
|
||||
"Microsoft.SkypeApp",
|
||||
"Microsoft.ZuneMusic",
|
||||
"Microsoft.ZuneVideo",#Кино и ТВ
|
||||
"Microsoft.XboxApp"#Xbox (Windows 10)
|
||||
# "Microsoft.Windows.Cortana" # ?????
|
||||
)
|
||||
|
||||
|
||||
write-host ""
|
||||
write-host "Введите полный путь до wim-файла:"
|
||||
$wimpath = read-host
|
||||
|
||||
write-host ""
|
||||
write-host "Введите полный путь до папки монтирования:"
|
||||
$mntpath = read-host
|
||||
|
||||
write-host ""
|
||||
write-host "Введите полный путь до папки с обновлениями:"
|
||||
$updpath = read-host
|
||||
|
||||
write-host ""
|
||||
write-host "Нажмите Enter для запуска"
|
||||
read-host
|
||||
|
||||
$start_of_changes = [int](Get-Date -UFormat %s -Millisecond 0)
|
||||
|
||||
write-host ""
|
||||
write-host "Удаляем лишние образы систем..."
|
||||
Remove-WindowsImage -ImagePath $wimpath -Index 3
|
||||
Remove-WindowsImage -ImagePath $wimpath -Index 2
|
||||
Remove-WindowsImage -ImagePath $wimpath -Index 1
|
||||
|
||||
write-host ""
|
||||
write-host "Монтируем образ..."
|
||||
Mount-WindowsImage -ImagePath $wimpath -Index 1 -Path $mntpath
|
||||
|
||||
write-host ""
|
||||
write-host "Удаляем установщик OneDrive из автозапуска..."
|
||||
# Remove-Item "$mntpath\Windows\SysWOW64\OneDrive.ico" -Force
|
||||
# Remove-Item "$mntpath\Windows\SysWOW64\OneDriveSetup.exe" -Force
|
||||
# Remove-Item "$mntpath\Users\Default\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk" -Force
|
||||
reg load HKLM\onedrive_delete $mntpath\Users\default\ntuser.dat
|
||||
reg delete HKLM\onedrive_delete\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\ /v OneDriveSetup /f
|
||||
reg unload HKLM\onedrive_delete
|
||||
|
||||
write-host ""
|
||||
write-host "Удаляем лишние системные приложения..."
|
||||
Get-AppxProvisionedPackage -Path $mntpath | ForEach-Object {
|
||||
if ($apps -contains $_.DisplayName) {
|
||||
Write-Host Removing $_.DisplayName...
|
||||
Remove-AppxProvisionedPackage -Path $mntpath -PackageName $_.PackageName | Out-Null
|
||||
}
|
||||
}
|
||||
|
||||
# write-host "Пытаемся удалить Cortana..."
|
||||
# Remove-AppxProvisionedPackage -Path $mntpath -PackageName Microsoft.549981C3F5F10
|
||||
|
||||
write-host ""
|
||||
write-host "Интегрируем обновления..."
|
||||
Add-WindowsPackage -Path $mntpath -PackagePath $updpath
|
||||
|
||||
# write-host ""
|
||||
# write-host "Сканируем здоровье образа..."
|
||||
# Repair-WindowsImage -Path $mntpath -ScanHealth
|
||||
|
||||
# write-host ""
|
||||
# write-host "\nПробуем запустить очистку образа от старых файлов..."
|
||||
# Dism.exe /image:%mntpath% /cleanup-image /startcomponentcleanup /resetbase
|
||||
|
||||
write-host ""
|
||||
write-host "Сохраняем изменения..."
|
||||
Dismount-WindowsImage -Path $mntpath -Save
|
||||
Clear-WindowsCorruptMountPoint
|
||||
|
||||
$end_of_changes = [int](Get-Date -UFormat %s -Millisecond 0)
|
||||
write-host "Затраченное время (в минутах): " (($end_of_changes - $start_of_changes) / 60)
|
||||
|
||||
[gc]::Collect()
|
||||
109
src/update_wim-file_w11.ps1
Normal file
109
src/update_wim-file_w11.ps1
Normal file
@@ -0,0 +1,109 @@
|
||||
# Скрипт для внесения изменений в WIM-Файл (W11)
|
||||
|
||||
# Список приложений для удаления
|
||||
$apps = @(
|
||||
"Microsoft.BingWeather",
|
||||
"Microsoft.GetHelp",
|
||||
"Microsoft.Getstarted",
|
||||
"Microsoft.Messaging",
|
||||
"Microsoft.Microsoft3DViewer",
|
||||
"Microsoft.MixedReality.Portal",
|
||||
"Microsoft.MicrosoftOfficeHub",
|
||||
"Microsoft.MicrosoftSolitaireCollection",
|
||||
"Microsoft.MicrosoftStickyNotes",
|
||||
"Microsoft.MSPaint",#Paint 3D (Windows 10)
|
||||
"Microsoft.Office.OneNote",
|
||||
"Microsoft.OneConnect",
|
||||
"Microsoft.People",
|
||||
"Microsoft.ScreenSketch",#Скриншоты (Windows 10 1809+)
|
||||
"Microsoft.YourPhone",#Ваш телефон (Windows 10 1809+)
|
||||
"Microsoft.Print3D",
|
||||
"Microsoft.SkypeApp",
|
||||
"Microsoft.WindowsAlarms",
|
||||
"Microsoft.WindowsCamera",
|
||||
"microsoft.windowscommunicationsapps",
|
||||
"Microsoft.WindowsFeedbackHub",
|
||||
"Microsoft.WindowsMaps",
|
||||
"Microsoft.WindowsSoundRecorder",
|
||||
"Microsoft.ZuneMusic",
|
||||
"Microsoft.ZuneVideo",#Кино и ТВ
|
||||
"Microsoft.XboxApp",#Xbox (Windows 10)
|
||||
"Microsoft.GamingApp",#Xbox (Windows 11)
|
||||
"Microsoft.PowerAutomateDesktop",#(Windows11)
|
||||
"Microsoft.Todos",#(Windows11)
|
||||
"Microsoft.BingNews",#Новости (Windows 11)
|
||||
"MicrosoftWindows.Client.WebExperience",#Виджеты (Windows 11)
|
||||
"Microsoft.Paint"#Paint (Windows11)
|
||||
)
|
||||
|
||||
|
||||
write-host ""
|
||||
write-host "Введите полный путь до wim-файла:"
|
||||
$wimpath = read-host
|
||||
|
||||
write-host ""
|
||||
write-host "Введите полный путь до папки монтирования:"
|
||||
$mntpath = read-host
|
||||
|
||||
write-host ""
|
||||
write-host "Введите полный путь до папки с обновлениями:"
|
||||
$updpath = read-host
|
||||
|
||||
write-host ""
|
||||
write-host "Нажмите Enter для запуска"
|
||||
read-host
|
||||
|
||||
$start_of_changes = [int](Get-Date -UFormat %s -Millisecond 0)
|
||||
|
||||
write-host ""
|
||||
write-host "Удаляем лишние образы систем..."
|
||||
Remove-WindowsImage -ImagePath $wimpath -Index 3
|
||||
Remove-WindowsImage -ImagePath $wimpath -Index 2
|
||||
Remove-WindowsImage -ImagePath $wimpath -Index 1
|
||||
|
||||
write-host ""
|
||||
write-host "Монтируем образ..."
|
||||
Mount-WindowsImage -ImagePath $wimpath -Index 1 -Path $mntpath
|
||||
|
||||
write-host ""
|
||||
write-host "Удаляем установщик OneDrive из автозапуска..."
|
||||
# Remove-Item "$mntpath\Windows\SysWOW64\OneDrive.ico" -Force
|
||||
# Remove-Item "$mntpath\Windows\SysWOW64\OneDriveSetup.exe" -Force
|
||||
# Remove-Item "$mntpath\Users\Default\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk" -Force
|
||||
reg load HKLM\onedrive_delete $mntpath\Users\default\ntuser.dat
|
||||
reg delete HKLM\onedrive_delete\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\ /v OneDriveSetup /f
|
||||
reg unload HKLM\onedrive_delete
|
||||
|
||||
write-host ""
|
||||
write-host "Удаляем лишние системные приложения..."
|
||||
Get-AppxProvisionedPackage -Path $mntpath | ForEach-Object {
|
||||
if ($apps -contains $_.DisplayName) {
|
||||
Write-Host Removing $_.DisplayName...
|
||||
Remove-AppxProvisionedPackage -Path $mntpath -PackageName $_.PackageName | Out-Null
|
||||
}
|
||||
}
|
||||
|
||||
# write-host "Пытаемся удалить Cortana..."
|
||||
# Remove-AppxProvisionedPackage -Path $mntpath -PackageName Microsoft.549981C3F5F10
|
||||
|
||||
write-host ""
|
||||
write-host "Интегрируем обновления..."
|
||||
Add-WindowsPackage -Path $mntpath -PackagePath $updpath
|
||||
|
||||
# write-host ""
|
||||
# write-host "Сканируем здоровье образа..."
|
||||
# Repair-WindowsImage -Path $mntpath -ScanHealth
|
||||
|
||||
# write-host ""
|
||||
# write-host "\nПробуем запустить очистку образа от старых файлов..."
|
||||
# Dism.exe /image:%mntpath% /cleanup-image /startcomponentcleanup /resetbase
|
||||
|
||||
write-host ""
|
||||
write-host "Сохраняем изменения..."
|
||||
Dismount-WindowsImage -Path $mntpath -Save
|
||||
Clear-WindowsCorruptMountPoint
|
||||
|
||||
$end_of_changes = [int](Get-Date -UFormat %s -Millisecond 0)
|
||||
write-host "Затраченное время (в минутах): " (($end_of_changes - $start_of_changes) / 60)
|
||||
|
||||
[gc]::Collect()
|
||||
Reference in New Issue
Block a user