install_certificate.bat 945 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. @echo off
  2. echo Importing certificate
  3. net session >nul 2>&1
  4. if %errorLevel% neq 0 (
  5. echo Please run this script as an administrator
  6. exit /b
  7. )
  8. if not exist "%~dp0certificate.cer" (
  9. echo Certificate file does not exist:%~dp0certificate.cer
  10. exit /b
  11. )
  12. set "certSubject="
  13. for /f "tokens=*" %%i in ('certutil -dump "%~dp0certificate.cer" ^| findstr /i "CN="') do (
  14. set "certSubject=%%i"
  15. )
  16. if defined certSubject (
  17. echo Deleting existing certificate with the same name
  18. certutil -delstore "Root" "%certSubject%"
  19. if %errorLevel% equ 0 (
  20. echo Existing certificate deleted successfully
  21. ) else (
  22. echo Failed to delete existing certificate (may not exist)
  23. )
  24. )
  25. echo Importing new certificate
  26. certutil -addstore -f "Root" "%~dp0certificate.cer"
  27. if %errorLevel% equ 0 (
  28. echo Certificate imported successfully
  29. ) else (
  30. echo Certificate import failed
  31. )
  32. echo Certificate installation completed