samiam41
asked on
search directory on remote pc and output if file is found
Hey Experts. I am searching a directory on a remote pc for a file and output whether the file was found.
Here is what I am using (it's a bad mod from what an EE expert suggested for another project):
Please assist. Thanks!
Here is what I am using (it's a bad mod from what an EE expert suggested for another project):
set ocxlist=\mscomctl.ocx
dir "\\%computer%\c$\windows\system32" | findstr "%ocxlist%">> %logfile%
echo. >> %logfile%
Please assist. Thanks!
what is your question?
So you know the folder already? Then it's basically just a matter of
@echo off
setlocal
set OcxList=mscomctl.ocx
set Folder=C$\Windows\system32
set /p "Computer=Please enter computer name: "
if "%Computer%" EQU "" (
echo No computer name entered, ending.
exit /b
)
set logfile=\\__\public\FG_Dia gnostic\%c omputer%.l og
for %%a in (\%OcxList%) do (
if exist "\\%computer%\%Folder%\%%~ a" (
>>"%LogFile%" echo '%%~a' found on %Computer%
) else (
>>"%LogFile%" echo '%%~a' not found on %Computer%
)
)
if exist "\\%computer%\c$\windows\system32\mscomctl.ocx" (
>>"%LogFile%" echo 'mscomctl.ocx' found on %Computer%
) else (
>>"%LogFile%" echo 'mscomctl.ocx' not found on %Computer%
)
But since probably want this more flexible, here's a version that supports a space separated list of files:@echo off
setlocal
set OcxList=mscomctl.ocx
set Folder=C$\Windows\system32
set /p "Computer=Please enter computer name: "
if "%Computer%" EQU "" (
echo No computer name entered, ending.
exit /b
)
set logfile=\\__\public\FG_Dia
for %%a in (\%OcxList%) do (
if exist "\\%computer%\%Folder%\%%~
>>"%LogFile%" echo '%%~a' found on %Computer%
) else (
>>"%LogFile%" echo '%%~a' not found on %Computer%
)
)
ASKER
I am searching a directory on a remote pc for a file and output whether the file was found but it isn't working.
I need to check a dir on the remote pc for several files and list them if they are there.
How?
I need to check a dir on the remote pc for several files and list them if they are there.
How?
Are they all in the system32 folder, and do you need additional action if all files were found and/or if some were missing? And here's my script from above again, this time with the missing code tags:
@echo off
setlocal
set OcxList=mscomctl.ocx
set Folder=C$\Windows\system32
set /p "Computer=Please enter computer name: "
if "%Computer%" EQU "" (
echo No computer name entered, ending.
exit /b
)
set logfile=\\__\public\FG_Diagnostic\%computer%.log
for %%a in (\%OcxList%) do (
if exist "\\%computer%\%Folder%\%%~a" (
>>"%LogFile%" echo '%%~a' found on %Computer%
) else (
>>"%LogFile%" echo '%%~a' not found on %Computer%
)
)
ASKER
Perfect oBdA. Can that script be modified to do something similar to the reg query? That portion of the script looks like this:
Can the script check the c$\windows\system32 for the files listed in Ocxlist in a similar method rather than the do/else?
I just need the files to be listed in the log file. That's it.
Thanks oBdA
set dlllist=\comdlg32.ocx \mscomctl.ocx
reg query "\\%computer%\hklm\software\microsoft\windows\currentversion\shareddlls" | findstr "%dlllist%">> %logfile%
Can the script check the c$\windows\system32 for the files listed in Ocxlist in a similar method rather than the do/else?
I just need the files to be listed in the log file. That's it.
Thanks oBdA
It could be with pretty much the syntax you posted in your question, but that will only list the files that were found. Files not found will not be listed.
ASKER
That's fine but I can't get the syntax to work. This is what I'm using:
That doesn't return the file even though it is there. I see it in Windows Explorer so I should see it in the log file.
set ocxlist= \mscomctl.ocx
dir \\%computer%\c$\windows\system32 | findstr "%ocxlist%">> %logfile%
That doesn't return the file even though it is there. I see it in Windows Explorer so I should see it in the log file.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks oBdA!