I think the main answer you're looking for is that success and failure of a command can be tracked by the automatic variable %ERRORLEVEL% and choices can be made in the script with "IF ERRORLEVEL":
::::::
net use \\10.40.12.1\ipc$ >NUL 2>NUL
IF ERRORLEVEL 2 GOTO :NEXT
echo \\10.40.12.1 has IPC$ >> c:\temp\ipc.txt
:NEXT
::::::
Note that error level 2 or any error higher would match the IF and bypass. No error (Success=0) or error level 1 (share is there but we cannot connect) would fails the above IF, and causes the reported line.
If you want to expand that to a "walk" you can drop it into a FOR loop:
::::::
FOR /L %%K IN (1,1,254) DO (
net use \\10.40.12.%%K\ipc$ >NUL 2>NUL
IF NOT ERRORLEVEL 2 echo \\10.40.12.1 has IPC$ >> c:\temp\ipc.txt
IF NOT ERRORLEVEL 1 net use \\10.40.12.%%K\ipc$ /delete >NUL 2>NUL
)
::::::
Notice, if it's there we report it even if a level one error prevented using it. We only need to release the resource to clean up our act if it actually did connect.
Goud Luck,
Main Topics
Browse All Topics





by: SteveGTRPosted on 2005-12-20 at 13:03:43ID: 15521792
You could try this:
@echo off
set reportFile=Output.txt
if "%~1"=="REFRESH" if exist "%reportFile%" del "%reportFile%"
set firstTime=Y
for /f "tokens=1,2" %%a in ('net use 2^>NUL' ^| findstr /l /i IPC$') do if not "%%b"=="" call :PROCESS "%%b"
goto :EOF
:PROCESS
if "%firstTime%"=="Y" (
>>%reportFile% echo [%date% %time%] %computername% has IPC$ mapped
set firstTime=
)
>>%reportFile% echo %~1
You'd want to change reportFile to a network share that accessable to all computers. A problem with this might be file contention. In that case you could modify the processing to output to a file that uses the individual's machine name and place the output in some directory on a network share.
This processing allows you to clear the content of the report file by passing REFRESH as a command line parameter.
Good Luck,
Steve