1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- @echo off
- echo Configuring hosts file
- net session >nul 2>&1
- if %errorLevel% neq 0 (
- echo Please run this script as an administrator
- exit /b
- )
- set "hostsFile=C:\Windows\System32\drivers\etc\hosts"
- set "newEntry=192.168.8.235 exam.habook.local"
- if not exist "%hostsFile%" (
- echo hosts file does not exist:%hostsFile%
- exit /b
- )
- findstr /v /i /c:"exam.habook.local" "%hostsFile%" > "%hostsFile%.tmp"
- if %errorLevel% equ 0 (
- move /y "%hostsFile%.tmp" "%hostsFile%" >nul 2>&1
- echo Removed all entries containing exam.habook.local
- ) else (
- echo Failed to remove entries containing exam.habook.local
- exit /b
- )
- echo %newEntry% >> "%hostsFile%"
- if %errorLevel% equ 0 (
- echo Hosts file configured successfully
- ) else (
- echo Hosts file configuration failed
- exit /b
- )
- :ImportCert
- echo Importing certificate
- if not exist "%~dp0certificate.cer" (
- echo Certificate file does not exist:%~dp0certificate.cer
- exit /b
- )
- set "certSubject="
- for /f "tokens=*" %%i in ('certutil -dump "%~dp0certificate.cer" ^| findstr /i "CN="') do (
- set "certSubject=%%i"
- )
- if defined certSubject (
- echo Deleting existing certificate with the same name
- certutil -delstore "Root" "%certSubject%"
- if %errorLevel% equ 0 (
- echo Existing certificate deleted successfully
- ) else (
- echo Failed to delete existing certificate (may not exist)
- )
- )
- echo Importing new certificate
- certutil -addstore -f "Root" "%~dp0certificate.cer"
- if %errorLevel% equ 0 (
- echo Certificate imported successfully
- ) else (
- echo Certificate import failed
- )
- echo All operations completed
|