2

I currently have a batch file I use to delete 2 folders off of my profile on my domain, it is as follows.

IF EXIST "C:\Documents and Settings\%Username%\Application Data\Mozilla" (
    rmdir "C:\Documents and Settings\%Username%\Application Data\Mozilla" /s /q
)
IF EXIST "C:\Documents and Settings\%Username%\Application Data\Microsoft\CryptnetUrlCache" (
    rmdir "C:\Documents and Settings\%Username%\Application Data\Microsoft\CryptnetUrlCache" /s /q
)

But since finding the success of this batch file, we decided we would like to implement it on all users files on our server. The \%Username%\ portion will only delete the user logged in currently correct? I would like it to delete it from every profile.

E:\Profiles\ is where we store all of our users profiles.

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
  • [Google](http://www.google.com/search?q=batch+file+iterate+through+directories) is a great first step. There are a number of relevant Stack Overflow questions listed. [This answer](http://stackoverflow.com/a/16462274/119527) in particular. – Jonathon Reinhart Nov 20 '13 at 23:52
  • I wouldn't have asked if I hadn't googled it already. I have been working at this for quite some time with very limited success across the entire Profiles folder. – user3015370 Nov 20 '13 at 23:54
  • I'm active duty navy assigned to a ship, so I'm sure you can see why I need to reach out for help. – user3015370 Nov 20 '13 at 23:56
  • Coukd you elaborate on what you have tried so far and what didn't work? So far, you have only described what you want, but you haven't asked an actual question. – Mark Nov 21 '13 at 00:06
  • We tried looking around on google to see if there was some sort of modifier that you can replace \%Username%\ with to go through all subfolders of the E:\Profiles\ path but so far we haven't been able to find anything. This issue with the folders getting to big in size is exceeding profile storage limits thus not allowing them to log off. – user3015370 Nov 21 '13 at 00:41

2 Answers2

0

You can make a little "Gambiarra" (Gambiarra is a kind of repair, here in Brazil we call by Gambiarra or just Gambis)

@echo off
pushd %userprofile%
cd..
dir /b > "%~dp0\users.txt"
popd
For /F "delims=*" %%a in (users.txt) do (
set invalid=0
CALL:PROCESS "%%a")
del users.txt
echo/Finish with error level %error%
pause>nul
:PROCESS
For %%b in (Public UpdatusUser) do (CALL:EXCUSR "%%b" "%~1")
if %invalid% EQU 1 (exit/b)
if /i "%~1" == "All Users" (exit/b)
if "%~x1" NEQ "" (exit/b)
set "user=%~1"
IF EXIST "C:\Documents and Settings\%User%\Application Data\Mozilla" (
    rmdir "C:\Documents and Settings\%User%\Application Data\Mozilla" /s /q
)
IF EXIST "C:\Documents and Settings\%User%\Application Data\Microsoft\CryptnetUrlCache" (
    rmdir "C:\Documents and Settings\%User%\Application Data\Microsoft\CryptnetUrlCache" /s /q
)
echo/User %user% complete
set error=%errorlevel%
exit/b
:EXCUSR
if "%~1" == "%~2" set invalid=1&exit/b
net user %~2 1>nul 2>nul || set invalid=1&exit/b
exit/b

I hope this code help you

Rafael
  • 3,042
  • 3
  • 20
  • 36
0

you can use Active Setup. Just add to Active Setup execution of your bat-file (using properly enviroment variables to get access to userprofile):)Good Luck)

Ksenia
  • 1