-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdles.bat
344 lines (262 loc) · 16.4 KB
/
dles.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
@ECHO OFF
@title DLES
:: dles.bat
:: Michael McMahon
:: github.com/BlueHillBGCB/BAT/dles.bat
:: To run this script, right click on the file and choose "Run as administrator" to start. You should read all bat files before giving them admin rights.
:: Based off of OSACS by agent-squirrel
:: https://www.reddit.com/r/commandline/comments/2sm2lc/osacs_officeworks_setup_and_cleaning_system/
REM ######################################################
REM #The Digital Learning Environment Setup (DLES) script
REM #creates useful scheduled tasks and helps automate
REM #Windows systems in educational environments.
REM ######################################################
:: TODO
:: The system is circumvented from Friday history in cache by doing a special maneuver in the browser.
:: Rename history with hostname and today's date.
:: Copy history to a remote machine.
:: Clear browsing history.
:: This also solves the problem of not logging out of accounts.
CLS
mode con: cols=92 lines=20
:: First lets check what mode we are running in.
:: Failure to check what mode we are in will result in the admin check failing
:: in safe mode.
if /i "%SAFEBOOT_OPTION%"=="MINIMAL" goto progstart
if /i "%SAFEBOOT_OPTION%"=="NETWORK" goto progstart
:MENU
CLS
goto check_Permissions
:: Attempts to run the 'net session' command and if it fails, assumes we are not
:: running with elevated permissions.
:check_Permissions
net session >nul 2>&1
if %errorLevel% == 0 (
GOTO progstart
) else (
echo.
echo.
echo.
echo Current permissions inadequate.
echo Please re-run as admin by right clicking the program and choosing
echo 'Run as Administrator'
echo Press Enter to quit.
)
pause>nul
EXIT
:progstart
mode con: cols=74 lines=20
:: Spawn the batch file used to generate the ASCII art at the top of the menu.
:: The ASCII script is pretty hefty and as a wonderful side effect, it tends to
:: load in line by line on slower machines.
:: ECHO out the menu then pause.
ECHO.
ECHO.
ECHO ================= Digital Learning Environment Setup (DLES) =============
ECHO ======================= What would you like to do? ======================
ECHO -------------------------------------------------------------------------
ECHO 1. Setup automatic school year shutdown (Sep-Jun)
ECHO 2. Setup automatic summer shutdown (Jul-Aug)
ECHO 3. Setup automatic summer shutdown TC (Jul-Aug)
ECHO 4. Setup HOSTS file rotation (games only on Fridays)
ECHO 5. Setup updating HOSTS file (most games any day)
ECHO 6. Setup school year HOSTS file rotation (local web Server redirect)
ECHO C. Reverse changes to scheduled tasks.
ECHO ============================PRESS 'Q' TO QUIT============================
ECHO.
SET INPUT=
SET /P INPUT=Please select a number:
IF /I '%INPUT%'=='1' GOTO Selection1
IF /I '%INPUT%'=='2' GOTO Selection2
IF /I '%INPUT%'=='3' GOTO Selection3
IF /I '%INPUT%'=='4' GOTO Selection4
IF /I '%INPUT%'=='5' GOTO Selection5
IF /I '%INPUT%'=='6' GOTO Selection6
IF /I '%INPUT%'=='C' GOTO Selection9
IF /I '%INPUT%'=='Q' GOTO EXITMSG
CLS
ECHO.
ECHO.
ECHO.
ECHO Whatever you just pressed probably wasn't between 1 and 5.
ECHO -------------------------------------
ECHO Please select a number from the Main Menu
ECHO [1-4] or select 'Q' to quit.
ECHO -------------------------------------
ECHO.
ECHO Press enter to have another go.
PAUSE > NUL
GOTO MENU
:Selection1
CLS
ECHO 1. Setup automatic school year shutdown (Sep-Jun)
ECHO =============================Installing...===============================
schtasks /delete /tn "DailySchoolShutdown" /f 1>NUL
schtasks /delete /tn "DailySummerShutdown" /f 1>NUL
schtasks /delete /tn "DailySummerShutdown2" /f 1>NUL
schtasks /delete /tn "DailySummerShutdown3" /f 1>NUL
SCHTASKS /Create /RU "SYSTEM" /TN "DailySchoolShutdown" /xml %~dp0\dlesXML\DailySchoolShutdown.xml /f 1>NUL
GOTO progstart
:Selection2
CLS
ECHO 2. Setup automatic summer shutdown (Jul-Aug)
ECHO =============================Installing...===============================
schtasks /delete /tn "DailySchoolShutdown" /f 1>NUL
schtasks /delete /tn "DailySummerShutdown" /f 1>NUL
schtasks /delete /tn "DailySummerShutdown2" /f 1>NUL
schtasks /delete /tn "DailySummerShutdown3" /f 1>NUL
SCHTASKS /Create /RU "SYSTEM" /TN "DailySummerShutdown" /xml %~dp0\dlesXML\DailySchoolShutdown.xml /f 1>NUL
SCHTASKS /Create /RU "SYSTEM" /TN "DailySummerShutdown2" /xml %~dp0\dlesXML\DailySchoolShutdown2.xml /f 1>NUL
GOTO progstart
:Selection3
CLS
ECHO 3. Setup automatic summer shutdown TC (Jul-Aug)
ECHO =============================Installing...===============================
schtasks /delete /tn "DailySchoolShutdown" /f 1>NUL
schtasks /delete /tn "DailySummerShutdown" /f 1>NUL
schtasks /delete /tn "DailySummerShutdown2" /f 1>NUL
schtasks /delete /tn "DailySummerShutdown3" /f 1>NUL
SCHTASKS /Create /RU "SYSTEM" /TN "DailySummerShutdown3" /xml %~dp0\dlesXML\DailySchoolShutdown3.xml /f 1>NUL
GOTO progstart
:Selection4
mode con: cols=80 lines=25
CLS
ECHO 4. Setup HOSTS file rotation (games only on Fridays)
ECHO =============================Installing...===============================
:: Create a directory on disk.
if not exist C:\hosts mkdir C:\hosts
:: MUST BE RUN WITH ADMIN CMD
powershell "$url = 'https://raw.githubusercontent.com/BlueHillBGCB/HOSTS/master/HOSTSFwin.txt'; $path = 'c:\hosts\HOSTSFwin.txt'; [Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; $webClient = new-object System.Net.WebClient; $webClient.DownloadFile( $url, $path )" 1>NUL
powershell "$url = 'https://raw.githubusercontent.com/BlueHillBGCB/HOSTS/master/HOSTSMTWRwin.txt'; $path = 'c:\hosts\HOSTSMTWRwin.txt'; [Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; $webClient = new-object System.Net.WebClient; $webClient.DownloadFile( $url, $path )" 1>NUL
powershell "$url = 'https://raw.githubusercontent.com/BlueHillBGCB/BAT/master/updatehosts.bat'; $path = 'c:\hosts\updatehosts.bat'; [Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; $webClient = new-object System.Net.WebClient; $webClient.DownloadFile( $url, $path )" 1>NUL
:: Formatting from ::http://blog.gpunktschmitz.com/504-powershell-download-file-from-server-via-https-which-has-a-self-signed-certificate
:: Create bat files
:: Build updatehosts.bat
:: http://stackoverflow.com/questions/11364147/setting-a-windows-batch-file-variable-to-the-day-of-the-week
@echo :: undatehosts.bat> c:\hosts\updatehosts.bat
@echo :: Michael McMahon>> c:\hosts\updatehosts.bat
@echo :: This script downloads HOSTS files from github.com/BlueHillBGCB/HOSTS on Windows systems.>> c:\hosts\updatehosts.bat
@echo. >> c:\hosts\updatehosts.bat
@echo :: MUST BE RUN WITH ADMIN CMD>> c:\hosts\updatehosts.bat
@echo. >> c:\hosts\updatehosts.bat
@echo @ECHO OFF>> c:\hosts\updatehosts.bat
@echo :: Create a directory on disk.>> c:\hosts\updatehosts.bat
@echo if not exist C:\hosts mkdir C:\hosts>> c:\hosts\updatehosts.bat
@echo powershell "$url = 'https://raw.githubusercontent.com/BlueHillBGCB/HOSTS/master/HOSTSFwin.txt'; $path = 'c:\hosts\HOSTSFwin.txt'; [Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; $webClient = new-object System.Net.WebClient; $webClient.DownloadFile( $url, $path )" 1>NUL>> c:\hosts\updatehosts.bat
@echo powershell "$url = 'https://raw.githubusercontent.com/BlueHillBGCB/HOSTS/master/HOSTSMTWRwin.txt'; $path = 'c:\hosts\HOSTSMTWRwin.txt'; [Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; $webClient = new-object System.Net.WebClient; $webClient.DownloadFile( $url, $path )" 1>NUL>> c:\hosts\updatehosts.bat
@echo :: Formatting from http://blog.gpunktschmitz.com/504-powershell-download-file-from-server-via-https-which-has-a-self-signed-certificate>> c:\hosts\updatehosts.bat
@echo. >> c:\hosts\updatehosts.bat
@echo :: This copies the hosts file depending on the day>> c:\hosts\updatehosts.bat
@echo setlocal 1>NUL>> c:\hosts\updatehosts.bat
@echo for /f "delims=" %%%%a in ('wmic path win32_localtime get dayofweek /format:list ') do for /f "delims=" %%%%d in ("%%%%a") do set %%%%d 1>NUL>> c:\hosts\updatehosts.bat
@echo IF %%dayofweek%%==5 (copy /Y C:\hosts\HOSTSFwin.txt C:\windows\system32\drivers\etc\hosts) ELSE (copy /Y C:\hosts\HOSTSMTWRwin.txt C:\windows\system32\drivers\etc\hosts) 1>NUL>> c:\hosts\updatehosts.bat
@echo endlocal 1>NUL>> c:\hosts\updatehosts.bat
@echo :: Formatting from http://stackoverflow.com/questions/11364147/setting-a-windows-batch-file-variable-to-the-day-of-the-week 1>NUL>> c:\hosts\updatehosts.bat
:: Create a task that runs every time the computer starts
schtasks /delete /tn "UpdateHosts" /f 1>NUL
SCHTASKS /Create /RU "SYSTEM" /TN "UpdateHosts" /xml %~dp0\dlesXML\UpdateHosts.xml /f 1>NUL
GOTO progstart
:Selection5
mode con: cols=80 lines=25
CLS
ECHO 5. Setup updating HOSTS file (most games any day)
ECHO =============================Installing...===============================
:: Create some directories on disk.
if not exist C:\hosts mkdir C:\hosts
:: MUST BE RUN WITH ADMIN CMD
powershell "$url = 'https://raw.githubusercontent.com/BlueHillBGCB/HOSTS/master/HOSTSFwin.txt'; $path = 'c:\hosts\HOSTSFwin.txt'; [Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; $webClient = new-object System.Net.WebClient; $webClient.DownloadFile( $url, $path )" 1>NUL
powershell "$url = 'https://raw.githubusercontent.com/BlueHillBGCB/HOSTS/master/HOSTSMTWRwin.txt'; $path = 'c:\hosts\HOSTSMTWRwin.txt'; [Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; $webClient = new-object System.Net.WebClient; $webClient.DownloadFile( $url, $path )" 1>NUL
:: Formatting from ::http://blog.gpunktschmitz.com/504-powershell-download-file-from-server-via-https-which-has-a-self-signed-certificate
:: Create bat files
:: Build updatehosts.bat
@echo :: undatehosts.bat> c:\hosts\updatehosts.bat
@echo :: Michael McMahon>> c:\hosts\updatehosts.bat
@echo :: This script downloads HOSTS files from github.com/BlueHillBGCB/HOSTS on Windows systems.>> c:\hosts\updatehosts.bat
@echo. >> c:\hosts\updatehosts.bat
@echo :: MUST BE RUN WITH ADMIN CMD>> c:\hosts\updatehosts.bat
@echo. >> c:\hosts\updatehosts.bat
@echo @ECHO OFF>> c:\hosts\updatehosts.bat
@echo :: Create a directory on disk.>> c:\hosts\updatehosts.bat
@echo if not exist C:\hosts mkdir C:\hosts>> c:\hosts\updatehosts.bat
@echo powershell "$url = 'https://raw.githubusercontent.com/BlueHillBGCB/HOSTS/master/HOSTSFwin.txt'; $path = 'c:\hosts\HOSTSFwin.txt'; [Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; $webClient = new-object System.Net.WebClient; $webClient.DownloadFile( $url, $path )" 1>NUL>> c:\hosts\updatehosts.bat
@echo :: Formatting from ::http://blog.gpunktschmitz.com/504-powershell-download-file-from-server-via-https-which-has-a-self-signed-certificate>> c:\hosts\updatehosts.bat
@echo. >> c:\hosts\updatehosts.bat
@echo :: This copies the hosts file>> c:\hosts\updatehosts.bat
@echo copy /Y C:\hosts\HOSTSFwin.txt C:\windows\system32\drivers\etc\hosts 1>NUL>> c:\hosts\updatehosts.bat
:: Create a task that runs every time the computer starts
schtasks /delete /tn "UpdateHosts" /f 1>NUL
SCHTASKS /Create /RU "SYSTEM" /TN "UpdateHosts" /xml %~dp0\dlesXML\UpdateHosts.xml /f 1>NUL
GOTO progstart
:Selection6
mode con: cols=80 lines=25
CLS
ECHO 6. Setup HOSTS file rotation (local web Server redirect)
ECHO =============================Installing...===============================
:: Create a directory on disk.
if not exist C:\hosts mkdir C:\hosts
:: MUST BE RUN WITH ADMIN CMD
powershell "$url = 'https://raw.githubusercontent.com/BlueHillBGCB/HOSTS/master/HOSTSFwinLS.txt'; $path = 'c:\hosts\HOSTSFwinLS.txt'; [Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; $webClient = new-object System.Net.WebClient; $webClient.DownloadFile( $url, $path )" 1>NUL
powershell "$url = 'https://raw.githubusercontent.com/BlueHillBGCB/HOSTS/master/HOSTSMTWRwinLS.txt'; $path = 'c:\hosts\HOSTSMTWRwinLS.txt'; [Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; $webClient = new-object System.Net.WebClient; $webClient.DownloadFile( $url, $path )" 1>NUL
:: Formatting from ::http://blog.gpunktschmitz.com/504-powershell-download-file-from-server-via-https-which-has-a-self-signed-certificate
:: Create bat files
:: Build updatehosts.bat
@echo :: undatehosts.bat> c:\hosts\updatehosts.bat
@echo :: Michael McMahon>> c:\hosts\updatehosts.bat
@echo :: This script downloads HOSTS files from github.com/BlueHillBGCB/HOSTS on Windows systems.>> c:\hosts\updatehosts.bat
@echo. >> c:\hosts\updatehosts.bat
@echo :: MUST BE RUN WITH ADMIN CMD>> c:\hosts\updatehosts.bat
@echo. >> c:\hosts\updatehosts.bat
@echo @ECHO OFF>> c:\hosts\updatehosts.bat
@echo :: Create a directory on disk.>> c:\hosts\updatehosts.bat
@echo if not exist C:\hosts mkdir C:\hosts>> c:\hosts\updatehosts.bat
@echo powershell "$url = 'https://raw.githubusercontent.com/BlueHillBGCB/HOSTS/master/HOSTSFwinLS.txt'; $path = 'c:\hosts\HOSTSFwinLS.txt'; [Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; $webClient = new-object System.Net.WebClient; $webClient.DownloadFile( $url, $path )" 1>NUL>> c:\hosts\updatehosts.bat
@echo powershell "$url = 'https://raw.githubusercontent.com/BlueHillBGCB/HOSTS/master/HOSTSMTWRwinLS.txt'; $path = 'c:\hosts\HOSTSMTWRwinLS.txt'; [Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; $webClient = new-object System.Net.WebClient; $webClient.DownloadFile( $url, $path )" 1>NUL>> c:\hosts\updatehosts.bat
@echo :: Formatting from http://blog.gpunktschmitz.com/504-powershell-download-file-from-server-via-https-which-has-a-self-signed-certificate>> c:\hosts\updatehosts.bat
@echo. >> c:\hosts\updatehosts.bat
@echo :: This copies the hosts file depending on the day>> c:\hosts\updatehosts.bat
@echo setlocal 1>NUL>> c:\hosts\updatehosts.bat
@echo for /f "delims=" %%%%a in ('wmic path win32_localtime get dayofweek /format:list ') do for /f "delims=" %%%%d in ("%%%%a") do set %%%%d 1>NUL>> c:\hosts\updatehosts.bat
@echo IF %%dayofweek%%==5 (copy /Y C:\hosts\HOSTSFwinLS.txt C:\windows\system32\drivers\etc\hosts) ELSE (copy /Y C:\hosts\HOSTSMTWRwinLS.txt C:\windows\system32\drivers\etc\hosts) 1>NUL>> c:\hosts\updatehosts.bat
@echo endlocal 1>NUL>> c:\hosts\updatehosts.bat
@echo :: Formatting from http://stackoverflow.com/questions/11364147/setting-a-windows-batch-file-variable-to-the-day-of-the-week 1>NUL>> c:\hosts\updatehosts.bat
:: Create a task that runs every time the computer starts
SCHTASKS /delete /tn "UpdateHosts" /f 1>NUL
SCHTASKS /Create /RU "SYSTEM" /TN "UpdateHosts" /xml %~dp0\dlesXML\UpdateHosts.xml /f 1>NUL
GOTO progstart
:Selection9
mode con: cols=80 lines=25
CLS
ECHO C. Reverse changes to scheduled tasks.
ECHO =============================Installing...===============================
schtasks /delete /tn "Summer Computer Shutdown" /f 1>NUL
schtasks /delete /tn "Yearly Computer Shutdown" /f 1>NUL
schtasks /delete /tn "HostRotateYearFriMorn" /f 1>NUL
schtasks /delete /tn "HostRotateSumFriMorn" /f 1>NUL
schtasks /delete /tn "HostRotateYearFriEven" /f 1>NUL
schtasks /delete /tn "HostRotateSumFriEven" /f 1>NUL
schtasks /delete /tn "HostRotateonlogon" /f 1>NUL
schtasks /delete /tn "HostRotateonstart" /f 1>NUL
schtasks /delete /tn "UpdateHosts" /f 1>NUL
schtasks /delete /tn "DailySchoolShutdown" /f 1>NUL
schtasks /delete /tn "DailySummerShutdown" /f 1>NUL
schtasks /delete /tn "DailySummerShutdown2" /f 1>NUL
schtasks /delete /tn "DailySummerShutdown3" /f 1>NUL
schtasks /delete /tn "HostRotateSchoolFriMorn" /f 1>NUL
schtasks /delete /tn "HostRotateSummerFriMorn" /f 1>NUL
schtasks /delete /tn "HostRotateSchoolFriEven" /f 1>NUL
schtasks /delete /tn "HostRotateSummerFriEven" /f 1>NUL
schtasks /delete /tn "HostRotateSchoolFriMornLS" /f 1>NUL
schtasks /delete /tn "HostRotateSummerFriMornLS" /f 1>NUL
schtasks /delete /tn "HostRotateSchoolFriEvenLS" /f 1>NUL
schtasks /delete /tn "HostRotateSummerFriEvenLS" /f 1>NUL
schtasks /delete /tn "HostRotateonlogonLS" /f 1>NUL
schtasks /delete /tn "HostRotateonstartLS" /f 1>NUL
GOTO progstart
:Quit
EXIT
:EXITMSG
ECHO ================================Goodbye==================================
ECHO -------------------------------------------------------------------------
ECHO =========================PRESS ANY KEY TO QUIT===========================
PAUSE>NUL
EXIT