Veya bu kodu dene.
@echo off
setlocal
:: Office kurulum yollarını tanımla
set "Office64Path=C:\Program Files\Microsoft Office\Office16"
set "Office32Path=C:\Program Files (x86)\Microsoft Office\Office16"
:: 64-bit Office kurulu mu kontrol et
if exist "%Office64Path%" (
call :LicenseCheck "%Office64Path%"
goto :EOF
)
:: 32-bit Office kurulu mu kontrol et
if exist "%Office32Path%" (
call :LicenseCheck "%Office32Path%"
goto :EOF
)
:: Hiçbir Office kurulumu bulunamazsa hata mesajı göster
echo 32-bit veya 64-bit Office kurulumu bulunamadı.
exit /b
:LicenseCheck
set "OfficePath=%~1"
cd /d "%OfficePath%"
:: Lisans durumunu al ve ürün anahtarının son 5 karakterini bul
for /f "tokens=5" %%A in ('cscript ospp.vbs /dstatus ^| findstr /i "Last 5 characters"') do set "productKey=%%A"
:: Ürün anahtarı bulunamazsa hata mesajı göster
if "%productKey%"=="" (
echo Ürün anahtarı bulunamadı.
exit /b
)
:: Bulunan ürün anahtarını göster
echo Ürün anahtarı bulundu: %productKey%
:: Ürün anahtarını kaldır
cscript ospp.vbs /unpkey:%productKey%
:: Ürün anahtarının başarıyla kaldırıldığını bildir
echo Ürün anahtarı %productKey% başarıyla kaldırıldı.
exit /b