| 1. |
Solve : Refining net view command in batch? |
|
Answer» I am trying to make a batch FILE that simply outputs the name of every computer on the network. The problem is that "net view" command decides that it needs formatting and labels. I just want the computer names. So I am making a batch to strip out all of the unnecessary labels and stuff. It works well, BUT it says 2==\\ is unexpected at this time when reading the last line. I FIGURE that this is because the last COUPLE of lines in the net view list file are blank, but I don't know how to tell it to skip blank lines. Could someone please help me make this run without errors. GOTO:EOF before the line containing :CheckIt AND Quote use quotes or brackets. Here is the finished batch file. It can scan computers using net view or with a list of computers stored in comps.lst. The default method is using comps.lst so if you try it you will need to make a comps.lst file. You will also probably have to change the location of the temp file because I have it set to "B:\comps.tmp" for my RAM drive. Comps.lst should look like this: Code: [Select]bla bla bla this is ignored \\server more comments \\seccondserver Here is the batch: Code: [Select]@echo off setLocal EnableDelayedExpansion set tmpfile=B:\comps.tmp call ::initnewline if "%1"=="-?" goto help if "%1"=="-a" ( echo Using autoscan mode. net view > %tmpfile% ) else ( echo Using comps.lst mode. copy /Y comps.lst %tmpfile% >nul ) echo Getting comp names. . . echo Type whatson -? for modes. echo Checking comps. Please wait. . .%NL% for /F %%i IN (%tmpfile%) do call ::CheckIt %%i echo %NL%Any key to exit. . . pause >nul goto:EOF :CheckIt set line=%1 set line=%line:~0,2% if not "%line%"=="\\" goto:EOF set line=%1 set line=%line:~2% ping -n 1 %line% >nul if errorlevel 1 ( echo %line% is off. ) else ( echo %line% is on. ) goto:EOF :initnewline REM extra empty lines required set NLM=^ set NL=^^^%NLM%%NLM%^%NLM%%NLM% goto:EOF :help echo Type whatson -a to automatically scan for comps. echo Type whatson -n or just whatson to use the list echo of computers in the comps.lst file. echo Any key to exit. . . pause >nul |
|