@echo off

REM Step 1: Generate Test.txt
ShowKeyPlus.exe WinKey.txt

REM Step 2: Get serial number
for /f "skip=1 tokens=2 delims=," %%S in ('wmic bios get serialnumber /format:csv') do (
    if not "%%S"=="" set "serial=%%S"
)

REM Step 3: Get product key from Test.txt
for /f "tokens=*" %%A in ('findstr /B /C:"Installed Key:" WinKey.txt') do set "line=%%A"
setlocal enabledelayedexpansion
set "key=!line:~-29!"
endlocal & set "key=%key%"

REM Step 4: Upload to server using PowerShell
powershell -Command ^
    "$serial='%serial%'; $key='%key%'; $body = @{serial=$serial; key=$key}; $response = Invoke-RestMethod -Uri 'https://apis.gramadigivikasana.in/trackers/winproc/uploadkey.php' -Method Post -Body $body; Write-Host 'Upload status:' $response.status; if ($response.status -eq 'success') { Remove-Item WinKey.txt; if (!(Test-Path WinKey.txt)) { Write-Host 'WinKey.txt deleted successfully.' } else { Write-Host 'Failed to delete WinKey.txt.' } } else { Write-Host 'Upload failed:' $response.message }"
pause