Hallo,
ich hab mal ein paar Sachen zusammengeworfen und mit Chatgpt etwas aufhübschen lassen.
Herausgekommen ist ein Windows Imaging-Vorbereitungsskript, das die Windows Installation und die Festplatte auf Fehler prüft, aufräumt und am Ende Windows ordentlich herunterfährt.
Anschließend sollte ein ordentliches Image mit Linbo ohne dirty bit oder ähnlichen Ärgernissen erzeugt werden.
Viele Grüße
Christian
Als prepare-for-image.bat abspeichern und als Admin starten.
@echo off
:: ==========================================
:: Windows Imaging-Vorbereitungsskript (modern)
:: ==========================================
:: Admin-Rechte prüfen
net session >nul 2>&1
if %errorlevel% neq 0 (
echo [FEHLER] Bitte fuehre dieses Skript mit Administratorrechten aus!
pause
exit /b
)
echo ================================
echo Pruefe Windows-Update-Aktivitaet...
echo ================================
:checkUpdates
tasklist | findstr /I "TiWorker.exe" >nul
if %errorlevel%==0 (
echo [*] Windows Update wird noch verarbeitet...
timeout /t 30 >nul
goto checkUpdates
)
echo [*] Keine aktive Updateverarbeitung erkannt.
:: Prüfen, ob ein Neustart nach Update erforderlich ist
echo [*] Pruefe, ob ein Neustart erforderlich ist...
PowerShell -NoProfile -Command "if ((Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired' -ErrorAction SilentlyContinue)) { exit 1 }"
if %errorlevel% neq 0 (
echo.
echo ========================================
echo [WARNUNG] Windows-Update erfordert einen Neustart!
echo Der Neustart wird jetzt automatisch ausgefuehrt.
echo ========================================
timeout /t 10 >nul
shutdown /r /t 60 /c "System wird neu gestartet, um Updates abzuschliessen"
exit /b
)
echo ================================
echo Pruefe Fast Boot (Schnellstart)...
echo ================================
PowerShell -NoProfile -Command "if ((Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Power').HiberbootEnabled -eq 1) { exit 1 }"
if %errorlevel% neq 0 (
echo.
echo ========================================
echo [HINWEIS] Fast Boot ist noch aktiviert.
echo Der Registry-Wert wird jetzt deaktiviert.
echo Ein Neustart ist erforderlich, damit die Aenderung wirksam wird.
echo ========================================
timeout /t 5 >nul
PowerShell -NoProfile -Command "Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Power' -Name HiberbootEnabled -Value 0"
shutdown /r /t 60 /c "System wird neu gestartet zur Anwendung der Fast Boot-Aenderung"
exit /b
)
echo ================================
echo Pruefe Systemintegritaet...
echo ================================
PowerShell -NoProfile -Command "if ((Get-Volume | Where-Object { $_.DriveLetter -ne $null -and $_.HealthStatus -ne 'Healthy' }).Count -gt 0) { Write-Host '[FEHLER] Mindestens ein Volume ist nicht gesund!'; exit 1 }"
if %errorlevel% neq 0 (
echo.
echo ========================================
echo [WARNUNG] Mindestens ein Volume ist nicht gesund.
echo CHKDSK wird automatisch geplant und beim Neustart ausgefuehrt.
echo ========================================
timeout /t 5 >nul
chkntfs /d
echo y | chkdsk C: /F /R
echo.
echo [HINWEIS] Neustart in 60 Sekunden zur Dateisystempruefung...
shutdown /r /t 60 /c "System wird neu gestartet zur Dateisystempruefung"
exit /b
)
echo [*] Starte SFC Systemdatei-Pruefung...
sfc /scannow
echo [*] Starte DISM Health Check...
DISM /Online /Cleanup-Image /ScanHealth
echo ================================
echo Starte Systembereinigung...
echo ================================
echo [*] Loesche temporaere Dateien...
del /f /s /q "%TEMP%\*" >nul 2>&1
del /f /s /q "C:\Windows\Temp\*" >nul 2>&1
echo [*] Loesche Prefetch-Daten...
del /f /q "C:\Windows\Prefetch\*" >nul 2>&1
echo [*] Leere Papierkorb fuer alle Benutzer...
PowerShell -NoProfile -Command "Get-CimInstance Win32_UserProfile | Where-Object { $_.Loaded -eq $false -and $_.LocalPath -like 'C:\\Users\\*' } | ForEach-Object { $recyclePath = Join-Path $_.LocalPath 'Recycle.Bin'; if (Test-Path $recyclePath) { Remove-Item -Path $recyclePath -Recurse -Force -ErrorAction SilentlyContinue } }; try {Clear-RecycleBin -Force -ErrorAction SilentlyContinue} catch {}"
echo [*] Bereinige Windows Update Cache...
net stop wuauserv >nul 2>&1
rd /s /q "C:\Windows\SoftwareDistribution\Download" >nul 2>&1
net start wuauserv >nul 2>&1
echo [*] Starte DISM Komponentenbereinigung...
DISM /Online /Cleanup-Image /StartComponentCleanup
echo [*] Starte Storage Sense manuell...
PowerShell -NoProfile -Command "Start-StorageSense -Verbose" >nul 2>&1
echo [*] Bereinige Benutzerprofile...
for /d %%i in (C:\Users\*) do (
del /f /s /q "%%i\AppData\Local\Temp\*" >nul 2>&1
del /f /s /q "%%i\AppData\Local\Microsoft\Windows\INetCache\*" >nul 2>&1
del /f /s /q "%%i\AppData\Roaming\Microsoft\Windows\Recent\*" >nul 2>&1
)
echo [*] Loesche Event Logs...
for /f %%x in ('wevtutil el') do (
echo Loesche %%x...
wevtutil cl "%%x" 2>nul
)
echo [*] Entferne alte Windows-Installationsreste...
rd /s /q "C:\$WINDOWS.~BT" >nul 2>&1
rd /s /q "C:\$WINDOWS.~WS" >nul 2>&1
rd /s /q "C:\$GetCurrent" >nul 2>&1
echo [*] Erzwinge Dateisystem-Flush...
PowerShell -NoProfile -Command "Get-Volume | ForEach-Object { if ($_.DriveLetter) { try { $path = $_.DriveLetter + ':\flush.tmp'; [System.IO.File]::WriteAllText($path, 'flush'); Remove-Item $path -Force } catch {} } }"
echo.
echo ================================
echo Bereinigung abgeschlossen
echo System wird heruntergefahren
echo ================================
timeout /t 5 >nul
shutdown /s /t 0 /f