@echo Off
set port=1688
for /f "tokens=2,*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" /v "KeyManagementServicePort" 2^>NUL ^| findstr KeyManagementServicePort') do set port=%%b

net start sppsvc
"%systemdrive%\kmshost\kms client.exe" %port% x.x.x.x Windows
"%systemdrive%\kmshost\kms client.exe" %port% x.x.x.x Office2010
"%systemdrive%\kmshost\kms client.exe" %port% x.x.x.x Office2013