Reputation: 139
I'm working on a code to search information. I use wmic for it.
But there is something wrong. I don't get the results for the computers in a txt file.
This is the code I created:
@echo off
title Check software
color 1f
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
set YYYY=%dt:~0,4%
set MM=%dt:~4,2%
set DD=%dt:~6,2%
set HH=%dt:~8,2%
set Min=%dt:~10,2%
set Sec=%dt:~12,2%
set timestamp=Datum-%YYYY%%MM%%DD%--Tijd-%HH%%Min%%Sec%
set txt=results--%timestamp%.txt
if exist "1e-client" (
echo Check: Map aanwezig
goto :checkfolder
) else (
echo Check: Map NIET aanwezig
echo Map 1e-client maken...
mkdir "1e-client"
goto :checkfolder
)
:checkfolder
FOR /F "tokens=*" %%I in (list.txt) do call :pinger %%I goto :eof
:eof
move %txt% 1e-client
exit
:pinger
ping -4 -n 1 -w 1000 %1
if not errorlevel 1 set pingstatus=Ja
if errorlevel 1 set pingstatus=Nee
echo Computer: %1 >> %txt%
Echo Online: %pingstatus% >> %txt%
wmic /node:%1 /output:c:\tmp.txt product get name,version |findstr /c:"1E NomadBranch" c:\tmp.txt > %txt%
ping 1.1.1.1 -n 1 -w 100 >nul
echo 1eClient Geinstalleerd: %client% >> %txt%
echo 1eClient versie; >> %txt%
type tmp.txt >> %txt%
Update. This is the list I that WMIC create. I need to find the "1E NomadBranch" and import that to the %txt% file.
Compatibility Pack for the 2007 Office system 12.0.6514.5001
Microsoft Office Visio Viewer 2007 12.0.4518.1014
Microsoft Software Update for Web Folders (English) 14 14.0.6029.1000
Microsoft Office OneNote MUI (English) 2010 14.0.6029.1000
Microsoft Office Standard 2010 14.0.6029.1000
Microsoft Office Shared Setup Metadata MUI (English) 2010 14.0.6029.1000
Microsoft Office Excel MUI (English) 2010 14.0.6029.1000
Microsoft Office PowerPoint MUI (English) 2010 14.0.6029.1000
Microsoft Office IME (Japanese) 2010 14.0.4763.1000
1E NomadBranch 5.0.100
Microsoft Office IME (Korean) 2010 14.0.4763.1000
Microsoft Office IME (Chinese (Traditional)) 2010 14.0.4763.1000
Microsoft Office IME (Chinese (Simplified)) 2010 14.0.4763.1000
Microsoft Office Publisher MUI (English) 2010 14.0.6029.1000
Microsoft Office Outlook MUI (English) 2010 14.0.6029.1000
Microsoft Office ProofMUI (English) 2010 14.0.4763.1000
Microsoft Office Word MUI (English) 2010 14.0.6029.1000
Microsoft Office Proofing Kit 2010 14.0.4763.1000
Microsoft Office Access Runtime 2010 14.0.4763.1000
Microsoft Office Access Runtime MUI (English) 2010 14.0.4763.1000
Microsoft Office Proofing (English) 2010 14.0.6029.1000
Microsoft Office Shared MUI (English) 2010 14.0.6029.1000
Microsoft Office Proof (Italian) 2010 14.0.4763.1000
Microsoft Office Proof (Catalan) 2010 14.0.4763.1013
Microsoft Office Proof (Dutch) 2010 14.0.4763.1000
Microsoft Office Proof (German) 2010 14.0.4763.1000
Microsoft Office Proof (English) 2010 14.0.6029.1000
Adobe Flash Player 10 ActiveX 10.1.85.3
Microsoft redistributable runtime DLLs VS2010 SP1 (x86) 10.0.40219.1
Microsoft Visual C++ 2005 ATL Update kb973923 - x86 8.0.50727.4053 8.0.50727.4053
Microsoft .NET Framework 3.0 Service Pack 2 3.2.30729
OFFICE 2010 STANDARD P1 14.01.00.00
Microsoft redistributable runtime DLLs VS2008 SP1(x86) 9.0
WINZIP US V14.05.00.00.00 14.05.00.00
Configuration Manager Client 5.00.7804.1000
Microsoft .NET Framework 3.5 SP1 3.5.30729
Microsoft .NET Framework 4 Client Profile 4.0.30319
Microsoft .NET Framework 4 Extended 4.0.30319
Upvotes: 0
Views: 297
Reputation: 41244
This line below has an error - did you correct it?
Instead of this
FOR /F "tokens=*" %%I in (list.txt) do call :pinger %%I goto :eof
use this (which assume no spaces etc in the terms)
FOR /F "tokens=*" %%I in (list.txt) do call :pinger %%I&goto :eof
This assumes you only want to process the first line of list.txt
Upvotes: 1
Reputation: 80113
I'd suggest you change
FOR /F "tokens=*" %%I in (list.txt) do call :pinger %%I goto :eof
:eof
move %txt% 1e-client
exit
to
FOR /F "tokens=*" %%I in (list.txt) do call :pinger %%I
move %txt% 1e-client
exit
because :eof
is a special label meaning 'end of file`. It should not be assigned in a batchfile.
Also - it appears to have no purpose where it is. If you had coded
FOR /F "tokens=*" %%I in (list.txt) do call :pinger %%I&goto :eof
then the batch should have terminated after processing the first line in list.txt
. As it stands, goto
should merely have become an unused second parameter to :pinger
and :eof
an unused third parameter.
Personally, I only ever use goto label
(no colon) except for goto :eof
(the special condition) to avoid this very problem.
I believe the actual cause of your problem is here:
Echo Online: %pingstatus% >> %txt%
wmic /node:%1 /output:c:\tmp.txt product get name,version |findstr /c:"1E NomadBranch" c:\tmp.txt > %txt%
ping 1.1.1.1 -n 1 -w 100 >nul
This will echo whatever to the txt
file, then run wmic and send its output to c:\temp.txt
(since you specify /output
) and send the screen output to findstr, which appears also to be reading c:\temp.txt
which is probably open at the time... and to cap it all off, you are then redirecting the findstr
output to a new txt
(since you are using the create new
redirector, >
, not the append
redirector, >>
.
I'd suggest
Echo Online: %pingstatus% >> %txt%
wmic /node:%1 /output:c:\tmp.txt product get name,version
findstr /c:"1E NomadBranch" c:\tmp.txt >> %txt%
ping 1.1.1.1 -n 1 -w 100 >nul
... but I'll admit having not tested that.
Upvotes: 1