问题
We have several hundred clients with unique server names on their own local networks that hosts a specific folder called "Installs". Ultimately what I'm trying to put together is a batch that finds this folder with said name and use an MSI file in that folder to install on their machine. The server name could just be anything, the only thing I know for sure is that it will be sharing out that specific folder. I've tried many variations of net view, find, dir, wmic share.. no such luck, no abilities to search all available network resources. I was thinking I could do a net view > shared.txt and somehow use the names it has in there to search for "Installs" on these machines. I'm just at a loss though, it seems like I'd have to start parsing which is a bit above me. Would anyone have any idea how to do this?
Net view remarks...
Server Name Remark
-------------------------------------------------------------------------------
\\TDF-DESK2
\\FWM-LAPT
\\CAC-VCM
\\BNE-DESK
\\MAXBETA Win2008R2 Std - Beta Test Server
回答1:
This searches each share available to your machine and searches for the foldername
listed on line 2.
@echo off
set "folder=foldername"
for /f %%a in ('net view ^|find "\\"') do if not "%%a"=="\\%computername%" (
echo trying server "%%a"
pushd "%%a" && (
for /d /r %%b in (%folder%*) do if /i "%%~nxb"=="%folder%" echo server "%%a" folder "%%b"
popd
)
)
pause
Earlier answer below:
Test this on a LAN - change the foldername*
but leave the *
there.
It should just echo the path\folders
that match.
This uses a helper batch file called repl.bat
- download from: https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat
Place repl.bat
in the same folder as the batch file or in a folder that is on the path.
@echo off
net share |repl "^.*(.:\\.*)" "$1" a|repl " *$" ""|repl "\\ *.*" "\"|repl "^..\\windows.*" "" i >temp.tmp
for /f "delims=" %%a in (temp.tmp) do (
for /d /r "%%a" %%b in (foldername*) do echo "%%b"
)
del temp.tmp
pause
来源:https://stackoverflow.com/questions/21869536/how-can-i-create-a-batch-that-searches-all-unknown-shared-folders-on-the-local