networkingavailability

Checking network availability of PC and of specific file via CMD


I have list with some PC hostnames and I would like to simple check if PCs are online in local network and check if the specific file is in that PC. I made some "program" via CMD. But it's lazy and it takes too long to check few PCs on network.

Example of command for first PC(workstation):

::this first command will check if PC is online and it will save workstation's hostname to result.txt file for next used command.
wmic /FAILFAST:ON /user: "admin" /password:"123456" /node:"Workstation1.subdomain.domain" computersystem get "Name" | more >>result.txt

    ::this second command will check if specific file (for example: AcroRd32.exe) not exist and it will save result to result.txt if it is not exist. Problem is that the this part is executing too long if PC is offline.
if not exist "\\Workstation1.subdomain.domain\c$\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" echo File NOT EXIST! | more >>result.txt

Output from result.txt should looks like this:

Worskation1.subdomain.domain
File NOT EXIST!

or

Worskation1.subdomain.domain
(empty line) 

1. is it possible to make second command more faster?

or

  1. is it possible to solve this through another way in CMD?
  2. is CMD suitable for this job?
  3. another solution?

Solution

  • There is a simple way.

    The first command wmic /FAILFAST:ON /user: "admin" /password:"123456" /node:"Workstation1.subdomain.domain" computersystem get "Name" will exit with status code 0 if the network is up and the workstation is up (and your credentials are corrects), anything else if there is a problem.

    So you just have to check the exit code :

    ::this first command will check if PC is online and it will save workstation's hostname to result.txt file for next used command.
    set LOCALV_WORKSTATIONUP=0
    ( wmic /FAILFAST:ON /user: "admin" /password:"123456" /node:"Workstation1.subdomain.domain" computersystem get "Name"  | more >>result.txt ) && set LOCALV_WORKSTATIONUP=1
    
    IF "%LOCALV_WORKSTATIONUP%" == "1" (
        ::this second command will check if specific file (for example: AcroRd32.exe) not exist and it will save result to result.txt if it is not exist. Problem is that the this part is executing too long if PC is offline.
    if not exist "\\Workstation1.subdomain.domain\c$\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" echo File NOT EXIST! | more >>result.txt
    )
    

    If you are using delayed expansion, take care to check for !LOCALV_WORKSTATIONUP! instead of %LOCALV_WORKSTATIONUP% :

    ::this first command will check if PC is online and it will save workstation's hostname to result.txt file for next used command.
    set LOCALV_WORKSTATIONUP=0
    ( wmic /FAILFAST:ON /user: "admin" /password:"123456" /node:"Workstation1.subdomain.domain" computersystem get "Name"  | more >>result.txt ) && set LOCALV_WORKSTATIONUP=1
    
    IF "!LOCALV_WORKSTATIONUP!" == "1" (
        ::this second command will check if specific file (for example: AcroRd32.exe) not exist and it will save result to result.txt if it is not exist. Problem is that the this part is executing too long if PC is offline.
    if not exist "\\Workstation1.subdomain.domain\c$\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" echo File NOT EXIST! | more >>result.txt
    )