Domain users have a predefined set of desktop icons that are copied to their profile on logon using a logon script. As an example let's say the icons are currently copied from %logonserver%\icons
All users should therefore only have the icons contained in "%logonserver%\icons" on their desktop.
For every cached profile on the system the script scans "%userprofile%\Desktop" against "%logonserver%\icons" to check for any unexpected icons/content.
This script is working fine and finds all files that users have saved to their desktops but it is unable to find folders or files in folders.
If there is a folder on the users desktop that contains files e.g %userprofile%\Desktop\Images. The folder and files within are not detected.
How do I make it also scan subfolders?
Once I have this functioning I am going to extend the script to copy the unexpected fiels to a datatrans folder on the server but need to get this phase working correctly first.
Here's the script so far:
Code: Select all
REM change core variable to the location of a copy of all expected desktop icons/files
@echo off
if exist results.txt del results.txt
setlocal enableDelayedExpansion
::*****************************************************************************************
set core=\\servername\icons
::******************************************************************************************
echo James@Drift
echo.
echo This script searches all local user desktop folders for unexpected content
echo This script is currently scanning the local desktop folder against...
echo %core% (If this location is incorrect you will be prompted to change it)
timeout 5
if exist %core% goto start
if not exist %core% goto setcore
:setcore
cls
echo.
echo Invalid location detected, please enter correct location.
echo.
echo Core location is the location of a folder that contains all standard desktop icons which can be compared against local profiles.
echo i.e \\servername\icons
echo.
SET /P core=Enter Core location here =
echo you have entered %core%
pause
:start
if not exist %core% goto setcore
setlocal enableDelayedExpansion
set core=%logonserver%\icons
echo Here's what was found:>>RESULTS.TXT
echo. >>RESULTS.TXT
for /f "delims=*" %%N in ('dir C:\users\ /b') do (
set /A count=0
set sn=%%N
set custom=C:\users\!sn!\Desktop
set folderCt=0
for /f "eol=: delims=" %%G in ('dir /B %core%') do (
set /a folderCt+=1
set "folder!folderCt!=%%G"
)
set folderCt=0
for /f "eol=: delims=" %%G in ('dir /B !custom!') do (
set /a folderCt+=1
set "folder!folderCt!=%%G"
)
for %%b in ("!custom!\*.*") do (
if exist "%core%\%%~nxb" title scanning !sn!
if not exist "%core%\%%~nxb" echo. & echo !sn! - Unexpected File Detected>>RESULTS.TXT & echo "%%b">>RESULTS.TXT
)
echo.
)
cls
pause
title Scan Complete
echo All local users scanned, see results.txt for a list of unexpected content.
REM start "" "viewresults.vbs"
REM I normaly use the above line but viewing in notepad will do for now!
start "" "results.txt"
SET /P ANSWER=Do you wish to delete the results txt file on exit (Y/N)?
echo You chose: %ANSWER%
if /i {%ANSWER%}=={y} (goto :yes)
if /i {%ANSWER%}=={yes} (goto :yes)
goto :no
:yes
del results.txt
exit /b 0
:no
exit /b 1