Solved

search directory on remote pc and output if file is found

Posted on 2014-12-08
9
257 Views
Last Modified: 2014-12-08
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):
set ocxlist=\mscomctl.ocx
dir "\\%computer%\c$\windows\system32" | findstr "%ocxlist%">> %logfile%
echo. >> %logfile%

Open in new window


Please assist.  Thanks!
0
Comment
Question by:samiam41
  • 4
  • 4
9 Comments
 
LVL 24

Expert Comment

by:NVIT
ID: 40487560
what is your question?
0
 
LVL 83

Expert Comment

by:oBdA
ID: 40487566
So you know the folder already? Then it's basically just a matter of
if exist "\\%computer%\c$\windows\system32\mscomctl.ocx" (
	>>"%LogFile%" echo 'mscomctl.ocx' found on %Computer%
) else (
	>>"%LogFile%" echo 'mscomctl.ocx' not found on %Computer%
)

Open in new window

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_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%
      )
)
0
 
LVL 9

Author Comment

by:samiam41
ID: 40487578
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?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 83

Expert Comment

by:oBdA
ID: 40487583
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%
       )
 )

Open in new window

0
 
LVL 9

Author Comment

by:samiam41
ID: 40487595
Perfect oBdA.  Can that script be modified to do something similar to the reg query?  That portion of the script looks like this:

set dlllist=\comdlg32.ocx \mscomctl.ocx
reg query "\\%computer%\hklm\software\microsoft\windows\currentversion\shareddlls" | findstr "%dlllist%">> %logfile%

Open in new window


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
0
 
LVL 83

Expert Comment

by:oBdA
ID: 40487607
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.
0
 
LVL 9

Author Comment

by:samiam41
ID: 40487611
That's fine but I can't get the syntax to work.  This is what I'm using:

set ocxlist= \mscomctl.ocx
dir \\%computer%\c$\windows\system32 | findstr "%ocxlist%">> %logfile%

Open in new window


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.
0
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 40487623
Oh, sorry, that was the "pretty much" part: you need to remove the backslash at the beginning of the file names.
set ocxlist=mscomctl.ocx
dir \\%computer%\c$\windows\system32 | findstr "%ocxlist%">> %logfile%

Open in new window

0
 
LVL 9

Author Closing Comment

by:samiam41
ID: 40487635
Thanks oBdA!
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Undelete files from a formatted drive 28 72
batch file problem 5 45
Get SMB version on Windows 7 3 80
Command prompt output to variable? 9 44
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
A quick guide on how to use Group Policy to create a custom power plan and set it active on Windows 7.
This Micro Tutorial will teach you how to the overview of Microsoft Security Essentials. This is a free anti-virus software that guards your PC against viruses, spyware, worms, and other malicious software. This will be demonstrated using Windows…
This Micro Tutorial will teach you how to change your appearance and customize your Windows 7 interface to your unique preference. This will be demonstrated using Windows 7 operating system.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question