2

I tried following code:

if exist "\\%1\c$\users\Public\" (
set sysos=Windows 7
) else (
set sysos=Windows XP
)

But when they can't find \\computername\c$ it takes more than 20 seconds for a time out. How can I create a shorter timeout in the code?

Matthew Green
  • 10,161
  • 4
  • 36
  • 54
Tom
  • 119
  • 2
  • 2
  • 11
  • you want a time-out or you have unwanted timeout? – npocmaka Feb 11 '14 at 13:50
  • I tried clarifying the question based on what I think you were trying to ask. If I guessed incorrectly then please edit the question to better highlight what you are wanting accomplished. – Matthew Green Feb 11 '14 at 17:22

2 Answers2

3

See if this solves your issue:

set "sysos="
ping -n 1 %1 >nul && if exist "\\%1\c$\users\Public\" (
      set sysos=Windows 7
   ) else (
      set sysos=Windows XP
   )
if not defined sysos echo %1 server is offline
foxidrive
  • 40,353
  • 10
  • 53
  • 68
  • Thank you for the answer. I will try it. It safes a lot of time. – Tom Feb 12 '14 at 05:40
  • Very useful! Explanation for `&&`: https://stackoverflow.com/questions/28889954/what-does-in-this-batch-file – Andre Feb 14 '19 at 14:44
2

May be with WMIC commands it will work faster ?

@echo off
setlocal

for /f  delims^= %%a in ('wmic /node:%~1 os get version /format:Wmiclivalueformat') do (
    for /f %%O in ("%%~a") do set "%%O"

)
set /a version=%version:.=%

if %version% LSS 620000 if %version% GEQ 610000(
    set "sysos=Windows 7"
)

if %version% LEQ 520000 if %version% GEQ 510000(
    set "sysos=Windows XP"
)

echo %sysos%
endlocal

Does not check if the remote machine exists...

npocmaka
  • 55,367
  • 18
  • 148
  • 187