Easy one, I need to know where to enter critera in this bat file

  • Thread starter Thread starter im1crazymf
  • Start date Start date
I

im1crazymf

I know I'm on the right track but I need to figure out how to set it
to delete any user profile older than 90days unless I specify a name
like smithj.

Just need to know where to enter criteria.
Thanks all!


Script below:


@echo off
setlocal
set keep=$$$$$$$$
if {%1}=={} goto syntax
set older=%1
if "%older%" EQU "0" goto OK
if "%older:~0,1%" LEQ "0" goto syntax
if "%older:~0,1%" GTR "9" goto syntax
:OK
if not {%2}=={} set keep=%2
set bypass=N
set pipkey=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion
\ProfileListregedit /a %TEMP%\profilelist.reg "HKEY_LOCAL_MACHINE
\Software\Microsoft\Windows NT\CurrentVersion\ProfileList"
set today=%date%
if "%today:~0,1%" GTR "9" set today=%date:~4%
set today=%today:/=%
set today=%today:~4,4%%today:~0,4%
set todayyy=%today:~0,4%
set todaymm=%today:~4,2%
set todaydd=%today:~6,2%
call jsidatem %todayyy% %todaymm% %todaydd% - %older%
for /f "Skip=5 Tokens=7 Delims=\]" %%a in ('type %TEMP%
\profilelist.reg') do set sid=%%a&call :getpip
endlocal
goto :EOF
:syntax
@echo Syntax: DelProfile NNdays [KeepUserName]
endlocal
goto :EOF
:IIIS
set bypass=N
If /i %1 EQU "%keep%" set bypass=Y&goto :EOF
set param=%1
set param=%param:"=%
If "%param:~0,5%" EQU "IUSR_" set bypass=Y&goto :EOF
If "%param:~0,5%" EQU "IWAM_" set bypass=Y&goto :EOF
goto :EOF
:getpip
for /f "Tokens=8 Delims=-" %%b in ('@echo %sid%') do set admin=%%b
if "%admin%"=="" goto :EOF
if "%admin%"=="500" goto :EOF
for /f "Skip=3 Tokens=2*" %%b in ('reg QUERY "%pipkey%%sid%" /v
ProfileImagePath') do call set pip=%%c
for /f "Tokens=2-5 Delims=\" %%b in ('@echo %pip%') do set usr1=%
%b&set usr2=%%c&set usr3=%%d&set usr4=%%e
if not "%usr4%"=="" call :IIIS "%usr4%"&if "%bypass%" EQU "Y"
goto :EOF
if not "%usr3%"=="" call :IIIS "%usr3%"&if "%bypass%" EQU "Y"
goto :EOF
if not "%usr2%"=="" call :IIIS "%usr2%"&if "%bypass%" EQU "Y"
goto :EOF
if not "%usr1%"=="" call :IIIS "%usr1%"&if "%bypass%" EQU "Y"
goto :EOF
for /f "Tokens=1,4" %%b in ('dir "%pip%\ntuser.dat" /4 /a /tW ^|
Findstr /I /L "NTUSER.DAT"') do set dstring=%%b
set dstring=%dstring:/=%
set dstring=%dstring:~4,4%%dstring:~0,4%
if "%dstring%" GTR "%AYMD%" goto :EOF
@echo Delete "%pip%"
reg DELETE "%pipkey%%sid%" /f
RD "%pip%" /s /q
 
You should clarify what you need help with. What exactly are your referring
to when you ask "Just need to know where to enter criteria"? What's working
(or not working) in the script that you assistance with?

Also, you may be better off posting in one of the scriting/batch file
groups.
I know I'm on the right track but I need to figure out how to set it
to delete any user profile older than 90days unless I specify a name
like smithj.

Just need to know where to enter criteria.
Thanks all!


Script below:


@echo off
setlocal
set keep=$$$$$$$$
if {%1}=={} goto syntax
set older=%1
if "%older%" EQU "0" goto OK
if "%older:~0,1%" LEQ "0" goto syntax
if "%older:~0,1%" GTR "9" goto syntax
if not {%2}=={} set keep=%2
set bypass=N
set pipkey=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion
\ProfileListregedit /a %TEMP%\profilelist.reg "HKEY_LOCAL_MACHINE
\Software\Microsoft\Windows NT\CurrentVersion\ProfileList"
set today=%date%
if "%today:~0,1%" GTR "9" set today=%date:~4%
set today=%today:/=%
set today=%today:~4,4%%today:~0,4%
set todayyy=%today:~0,4%
set todaymm=%today:~4,2%
set todaydd=%today:~6,2%
call jsidatem %todayyy% %todaymm% %todaydd% - %older%
for /f "Skip=5 Tokens=7 Delims=\]" %%a in ('type %TEMP%
\profilelist.reg') do set sid=%%a&call :getpip
endlocal
goto :EOF
@echo Syntax: DelProfile NNdays [KeepUserName]
endlocal
goto :EOF
set bypass=N
If /i %1 EQU "%keep%" set bypass=Y&goto :EOF
set param=%1
set param=%param:"=%
If "%param:~0,5%" EQU "IUSR_" set bypass=Y&goto :EOF
If "%param:~0,5%" EQU "IWAM_" set bypass=Y&goto :EOF
goto :EOF
for /f "Tokens=8 Delims=-" %%b in ('@echo %sid%') do set admin=%%b
if "%admin%"=="" goto :EOF
if "%admin%"=="500" goto :EOF
for /f "Skip=3 Tokens=2*" %%b in ('reg QUERY "%pipkey%%sid%" /v
ProfileImagePath') do call set pip=%%c
for /f "Tokens=2-5 Delims=\" %%b in ('@echo %pip%') do set usr1=%
%b&set usr2=%%c&set usr3=%%d&set usr4=%%e
if not "%usr4%"=="" call :IIIS "%usr4%"&if "%bypass%" EQU "Y"
goto :EOF
if not "%usr3%"=="" call :IIIS "%usr3%"&if "%bypass%" EQU "Y"
goto :EOF
if not "%usr2%"=="" call :IIIS "%usr2%"&if "%bypass%" EQU "Y"
goto :EOF
if not "%usr1%"=="" call :IIIS "%usr1%"&if "%bypass%" EQU "Y"
goto :EOF
for /f "Tokens=1,4" %%b in ('dir "%pip%\ntuser.dat" /4 /a /tW ^|
Findstr /I /L "NTUSER.DAT"') do set dstring=%%b
set dstring=%dstring:/=%
set dstring=%dstring:~4,4%%dstring:~0,4%
if "%dstring%" GTR "%AYMD%" goto :EOF
@echo Delete "%pip%"
reg DELETE "%pipkey%%sid%" /f
RD "%pip%" /s /q
 
You should clarify what you need help with. What exactly are your referring
to when you ask "Just need to know where to enter criteria"? What's working
(or not working) in the script that you assistance with?

Also, you may be better off posting in one of the scriting/batch file
groups.


I know I'm on the right track but I need to figure out how to set it
to delete any user profile older than 90days unless I specify a name
like smithj.
Just need to know where to enter criteria.
Thanks all!
Script below:
@echo off
setlocal
set keep=$$$$$$$$
if {%1}=={} goto syntax
set older=%1
if "%older%" EQU "0" goto OK
if "%older:~0,1%" LEQ "0" goto syntax
if "%older:~0,1%" GTR "9" goto syntax
if not {%2}=={} set keep=%2
set bypass=N
set pipkey=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion
\ProfileListregedit /a %TEMP%\profilelist.reg "HKEY_LOCAL_MACHINE
\Software\Microsoft\Windows NT\CurrentVersion\ProfileList"
set today=%date%
if "%today:~0,1%" GTR "9" set today=%date:~4%
set today=%today:/=%
set today=%today:~4,4%%today:~0,4%
set todayyy=%today:~0,4%
set todaymm=%today:~4,2%
set todaydd=%today:~6,2%
call jsidatem %todayyy% %todaymm% %todaydd% - %older%
for /f "Skip=5 Tokens=7 Delims=\]" %%a in ('type %TEMP%
\profilelist.reg') do set sid=%%a&call :getpip
endlocal
goto :EOF
@echo Syntax: DelProfile NNdays [KeepUserName]
endlocal
goto :EOF
set bypass=N
If /i %1 EQU "%keep%" set bypass=Y&goto :EOF
set param=%1
set param=%param:"=%
If "%param:~0,5%" EQU "IUSR_" set bypass=Y&goto :EOF
If "%param:~0,5%" EQU "IWAM_" set bypass=Y&goto :EOF
goto :EOF
for /f "Tokens=8 Delims=-" %%b in ('@echo %sid%') do set admin=%%b
if "%admin%"=="" goto :EOF
if "%admin%"=="500" goto :EOF
for /f "Skip=3 Tokens=2*" %%b in ('reg QUERY "%pipkey%%sid%" /v
ProfileImagePath') do call set pip=%%c
for /f "Tokens=2-5 Delims=\" %%b in ('@echo %pip%') do set usr1=%
%b&set usr2=%%c&set usr3=%%d&set usr4=%%e
if not "%usr4%"=="" call :IIIS "%usr4%"&if "%bypass%" EQU "Y"
goto :EOF
if not "%usr3%"=="" call :IIIS "%usr3%"&if "%bypass%" EQU "Y"
goto :EOF
if not "%usr2%"=="" call :IIIS "%usr2%"&if "%bypass%" EQU "Y"
goto :EOF
if not "%usr1%"=="" call :IIIS "%usr1%"&if "%bypass%" EQU "Y"
goto :EOF
for /f "Tokens=1,4" %%b in ('dir "%pip%\ntuser.dat" /4 /a /tW ^|
Findstr /I /L "NTUSER.DAT"') do set dstring=%%b
set dstring=%dstring:/=%
set dstring=%dstring:~4,4%%dstring:~0,4%
if "%dstring%" GTR "%AYMD%" goto :EOF
@echo Delete "%pip%"
reg DELETE "%pipkey%%sid%" /f
RD "%pip%" /s /q- Hide quoted text -

- Show quoted text -

I'm not sure where to put in the 90days or the user name to keep also
I'm wondering if there is a way to output a log file showing whether
it was successful or not.
 
I know I'm on the right track but I need to figure out how to set it
to delete any user profile older than 90days unless I specify a name
like smithj.
Just need to know where to enter criteria.
Thanks all!
Script below:
@echo off
setlocal
set keep=$$$$$$$$
if {%1}=={} goto syntax
set older=%1
if "%older%" EQU "0" goto OK
if "%older:~0,1%" LEQ "0" goto syntax
if "%older:~0,1%" GTR "9" goto syntax
OK
if not {%2}=={} set keep=%2
set bypass=N
set pipkey=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion
\ProfileListregedit /a %TEMP%\profilelist.reg "HKEY_LOCAL_MACHINE
\Software\Microsoft\Windows NT\CurrentVersion\ProfileList"
set today=%date%
if "%today:~0,1%" GTR "9" set today=%date:~4%
set today=%today:/=%
set today=%today:~4,4%%today:~0,4%
set todayyy=%today:~0,4%
set todaymm=%today:~4,2%
set todaydd=%today:~6,2%
call jsidatem %todayyy% %todaymm% %todaydd% - %older%
for /f "Skip=5 Tokens=7 Delims=\]" %%a in ('type %TEMP%
\profilelist.reg') do set sid=%%a&call :getpip
endlocal
goto :EOF
syntax
@echo Syntax: DelProfile NNdays [KeepUserName]
endlocal
goto :EOF
IIIS
set bypass=N
If /i %1 EQU "%keep%" set bypass=Y&goto :EOF
set param=%1
set param=%param:"=%
If "%param:~0,5%" EQU "IUSR_" set bypass=Y&goto :EOF
If "%param:~0,5%" EQU "IWAM_" set bypass=Y&goto :EOF
goto :EOF
getpip
for /f "Tokens=8 Delims=-" %%b in ('@echo %sid%') do set admin=%%b
if "%admin%"=="" goto :EOF
if "%admin%"=="500" goto :EOF
for /f "Skip=3 Tokens=2*" %%b in ('reg QUERY "%pipkey%%sid%" /v
ProfileImagePath') do call set pip=%%c
for /f "Tokens=2-5 Delims=\" %%b in ('@echo %pip%') do set usr1=%
%b&set usr2=%%c&set usr3=%%d&set usr4=%%e
if not "%usr4%"=="" call :IIIS "%usr4%"&if "%bypass%" EQU "Y"
goto :EOF
if not "%usr3%"=="" call :IIIS "%usr3%"&if "%bypass%" EQU "Y"
goto :EOF
if not "%usr2%"=="" call :IIIS "%usr2%"&if "%bypass%" EQU "Y"
goto :EOF
if not "%usr1%"=="" call :IIIS "%usr1%"&if "%bypass%" EQU "Y"
goto :EOF
for /f "Tokens=1,4" %%b in ('dir "%pip%\ntuser.dat" /4 /a /tW ^|
Findstr /I /L "NTUSER.DAT"') do set dstring=%%b
set dstring=%dstring:/=%
set dstring=%dstring:~4,4%%dstring:~0,4%
if "%dstring%" GTR "%AYMD%" goto :EOF
@echo Delete "%pip%"
reg DELETE "%pipkey%%sid%" /f
RD "%pip%" /s /q- Hide quoted text -

- Show quoted text -

You should clarify what you need help with. What exactly are your
referring to when you ask "Just need to know where to enter
criteria"? What's working (or not working) in the script that you
assistance with?

Also, you may be better off posting in one of the scriting/batch file
groups.
I'm not sure where to put in the 90days or the user name to keep also

I would assume you'd put them in as command line arguments. I am not a
scripting guru so I really can't follow your script, but I would assume
since this is your script then you would know where you need to enter your
values. You'd probably be better served posting your question in one of the
scripting groups.
I'm wondering if there is a way to output a log file showing whether
it was successful or not.

You can redirect output with the greater-than (>) sign. eg:
dir >output.txt
This will write the directory contents of your current directory to a file
called output.txt.
As well you can use ">>" to append data to a file.
 
Back
Top