-
Notifications
You must be signed in to change notification settings - Fork 0
/
W7CleanProfiles.bat
133 lines (113 loc) · 3.72 KB
/
W7CleanProfiles.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
@ECHO OFF
ECHO.
ECHO. ***********************************************
ECHO. Profile Clean Utility for Medill School
ECHO. Written by Brett Keller
ECHO. Based on original work by Mike Stone from
ECHO. http://mstoneblog.wordpress.com/2010/12/08/
ECHO. ***********************************************
ECHO.
VER | FIND "6.1.760" > NUL
IF NOT %ERRORLEVEL% == 0 GOTO :WRONGOS
ECHO %USERNAME% | FIND "hansel" > NUL
IF %ERRORLEVEL% == 0 GOTO :HANSEL
MKDIR %SYSTEMROOT%\SYSTEM32\xyzzyTEMP > NUL
IF NOT %ERRORLEVEL% == 0 GOTO :NOTADMIN
RMDIR /S /Q %SYSTEMROOT%\SYSTEM32\xyzzyTEMP > NUL
FOR /f "tokens=*" %%a IN ('dir c:\USERS /b /ad') DO CALL :PATHCHECK "%%a"
GOTO REGISTRY
:PATHCHECK
IF /i [%1]==["%USERNAME%"] GOTO :PATHSKIPCURRENT
IF /i [%1]==["Administrator"] GOTO :PATHSKIP
IF /i [%1]==["hansel"] GOTO :PATHSKIP
IF /i [%1]==["Default"] GOTO :PATHSKIP
IF /i [%1]==["Default user"] GOTO :PATHSKIP
IF /i [%1]==["public"] GOTO :PATHSKIP
IF /i [%1]==["All Users"] GOTO :PATHSKIP
:: Enter any other profiles here by copying and pasting any of the above and changing the name.
GOTO PATHCLEAN
:PATHSKIP
ECHO. Skipping path clean for user %1
GOTO :EOF
:PATHSKIPCURRENT
ECHO. Skipping path clean for CURRENT USER %1
GOTO :EOF
:PATHCLEAN
ECHO. Cleaning profile for: %1
rmdir C:\USERS\%1 /s /q > NUL
IF EXIST "C:\USERS\%1" GOTO RETRYPATHFIRST
IF NOT EXIST "C:\USERS\%1" GOTO :EOF
:RETRYPATHFIRST
ECHO. Error cleaning profile for: %1 - Trying again.
rmdir C:\USERS\%1 /s /q > NUL
IF EXIST "C:\USERS\%1" GOTO RETRYPATHSECOND
IF NOT EXIST "C:\USERS\%1" GOTO :EOF
:RETRYPATHSECOND
ECHO. Error cleaning profile for: %1 - Trying again.
rmdir C:\USERS\%1 /s /q > NUL
IF EXIST "C:\USERS\%1" ECHO. ** Unable to clean profile for: %1 - PLEASE MANUALLY REMOVE DIRECTORY!
GOTO :EOF
:REGISTRY
ECHO.------------
FOR /f "tokens=*" %%a IN ('reg query "hklm\software\microsoft\windows nt\currentversion\profilelist"^|find /i "s-1-5-21"') DO CALL :REGCHECK "%%a"
GOTO EXIT
:REGCHECK
FOR /f "tokens=3" %%b in ('reg query %1 /v ProfileImagePath') DO SET USERREG=%%b
IF /i [%USERREG%]==[c:\Users\%USERNAME%] GOTO :REGSKIPCURRENT
IF /i [%USERREG%]==[c:\Users\Administrator] GOTO :REGSKIP
IF /i [%USERREG%]==[c:\Users\hansel] GOTO :REGSKIP
:: Enter any other profiles here by copying and pasting any of the above and changing the name.
GOTO REGCLEAN
:REGSKIP
ECHO. Skipping registry clean for %USERREG%
GOTO :EOF
:REGSKIPCURRENT
ECHO. Skipping registry clean for CURRENT USER %USERREG%
GOTO :EOF
:REGCLEAN
ECHO. Cleaning registry for: %USERREG%
reg delete %1 /f > NUL
GOTO :EOF
:EXIT
REM CLS
ECHO.
ECHO. ***********************************************
ECHO. Profile Clean Utility for Medill School
ECHO. Written by Brett Keller
ECHO. Based on original work by Mike Stone from
ECHO. http://mstoneblog.wordpress.com/2010/12/08/
ECHO. ***********************************************
ECHO.
ECHO. Profile cleaning is complete.
ECHO.
PAUSE
EXIT
:WRONGOS
ECHO. The script has detected that you are NOT running Windows 7!
ECHO. Please execute the appropriate script for the OS you are running.
ECHO.
ECHO. TERMINATING SCRIPT
ECHO.
PAUSE
EXIT
:HANSEL
ECHO. It appears that you are logged in to the "hansel" account.
ECHO. This script will not run properly when executed as this user.
ECHO. Please run it under a domain administrator's user account.
ECHO.
ECHO. TERMINATING SCRIPT
ECHO.
PAUSE
EXIT
:NOTADMIN
ECHO.
ECHO. The script is unable to establish elevated privileges.
ECHO. Please check and make sure that you are logged into an
ECHO. administrator's account and that User Account Control
ECHO. is either turned off or prompts have been approved.
ECHO.
ECHO. TERMINATING SCRIPT
ECHO.
PAUSE
EXIT
:EOF