Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- rem -- check if a given host is lcalhost
- rem -- by Vasil "npocmaka" Arnaudov
- setlocal
- set /A errorlevel=0
- if "%1" EQU "" (
- echo %~n0 hostname
- echo set errorlevel to 1 if the host is localhost and 2 if host is not found
- )
- if "%1" EQU "/?" (
- echo %~n0 hostname
- echo set errorlevel to 1 if the host is localhost and 2 if host is not found
- )
- set ping_result=
- for /f %%P in ('call ping -n 1 %1 ^| find "could not find host"') do (
- set ping_result=%%P
- ) > nul
- if "%ping_result%" NEQ "" (
- echo host not found
- endlocal & exit /b 2
- goto :eof
- )
- setlocal ENABLEDELAYEDEXPANSION
- for /f "tokens=1,2,* delims= " %%W in ('wmic /node:%1 /user:? /password:? process get 2^>^&1 ^| findstr "Description" ') do (
- rem the commented echo produces a strange result
- rem echo --%%Y--
- call set resp=%%Y
- if [!resp!] EQU [User credentials cannot be used for local connections] (
- endlocal
- endlocal & exit /b 1
- )
- )
- endlocal
- endlocal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement