-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReset.bat
280 lines (206 loc) · 6.82 KB
/
Reset.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
:init
@echo off
color 4f
cls
cd /d %~dp0
net session >nul 2>&1
if %errorLevel% == 0 (
goto vars
) else (
goto runasadmin
)
rem Starts the program with initial settings and checks if the program is being run as admin
:vars
cls
echo Getting system information...
if %PROCESSOR_ARCHITECTURE% == AMD64 (
set archtype=64 Bit
goto confirm)
if %PROCESSOR_ARCHITECTURE% == x86 (
set archtype=32 Bit
goto confirm) else (goto unsupported)
rem Checks the processor's archetecture and sets a varible based upon what is found. If there is an unkown arthecture then it goes to the unsupported section.
:confirm
cls
echo Are you sure that you want to reset Syncthing?
echo This will cause a disruprion on *this* computer's syncing!
echo ONLY do this if you are having trouble with Syncthing!!!
echo.
choice /c RC /m "Press \"R\" to Reset or press \"C\" to Cancel... "
if %errorlevel%==1 (
goto doubbleconfirm
) else (goto exit)
rem Checks if the user wants to reset syncthing
:doubbleconfirm
cls
echo Are you absolutely sure that you want to reset syncthing?
echo This is your last chance to back out!
echo.
choice /c EC /m "Press \"E\" to Exit or press \"C\" to Confirm... "
if %errorlevel%==2 (goto check
) else (goto exit)
rem Doubble checks if the user wants to reset syncthing
:check
cls
if not exist C:\syncthingtemp\ mkdir C:\syncthingtemp\
if exist C:\syncthingtemp\syncthing-windows*.zip goto stop
echo Please download and place the %archtype% Windows version ZIP file
echo of Syncthing in this folder.
pause
cls
echo Place the %archtype% zip file in the file browser that was opened
echo then press any key to continue.
echo.
start https://syncthing.net/
start C:\syncthingtemp\
pause
if not exist C:\syncthingtemp\extracted\ mkdir C:\syncthingtemp\extracted\
goto check
rem Checks if the zip file of syncthing is available for usage.
rem If the zip file is not found then it prompts the user download it and place it in a specific folder.
rem The folder is autocreated if it does not exist.
:stop
cls
echo Stoping running instances of Syncthing...
taskkill /IM syncthing.*
goto clear
rem Closes all instances of Syncthing so that files can be edited.
:clear
cls
echo Cleaning out Syncthing directory for new files...
rmdir /S /Q C:\syncthing
mkdir C:\Syncthing
goto preunpack
rem Removes the syncthing folder so that the new syncthing files can be installed
:preunpack
cls
echo Unpacking and moving files into position...
setlocal
for %%a in ("C:\syncthingtemp\*.zip") do call:UnpackMove "%%a"
endlocal
goto icon
rem Sends the commands to unpack the users zip file.
:UnpackMove
powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem';[IO.Compression.ZipFile]::ExtractToDirectory('C:\syncthingtemp\%~nx1', 'C:\syncthingtemp\extracted\'); }"
xcopy /E "C:\syncthingtemp\extracted\%~n1" C:\Syncthing\
exit /b
rem Unzips the specified zip file into a specific folder.
rem Moves the files into position.
:icon
cls
echo Creating settings icon...
if exist "Syncthing Settings.url" del "%cd%\Syncthing Settings.url"
if exist "Syncthing Settings.lnk" del "%cd%\Syncthing Settings.lnk"
(
echo([InternetShortcut]
echo(URL=http://127.0.0.1:8384/
echo(IDList=
echo(IconFile="%systemroot%\system32\shell32.dll"
echo(IconIndex=238
)>"Syncthing Settings.url"
goto schvars
rem Deletes existing icon if present in current directory and creates a new settings icon.
:schvars
cls
echo Creating/resetting scheduled task...
schtasks /Delete /TN Syncthing /F
set year=%date:~10,4%
set month=%date:~4,2%
set day=%date:~7,2%
set scripttime=%time:~0,8%
for /f "delims= " %%a in ('"wmic useraccount where name='%username%' get sid"') do (
if not "%%a"=="SID" (set usersid=%%a
goto :createxml))
rem Gets varables for XML files and deletes existing scheduled task.
:createxml
(
echo(^<?xml version^="1.0" encoding^="UTF-16"?^>
echo(^<Task version^="1.2" xmlns^="http://schemas.microsoft.com/windows/2004/02/mit/task"^>
echo( ^<RegistrationInfo^>
echo( ^<Date^>%year%-%month%-%day%T%scripttime%.1008091^</Date^>
echo( ^<Author^>%computername%\%username%^</Author^>
echo( ^<Description^>Syncthing autostart task^</Description^>
echo( ^<URI^>\Syncthing^</URI^>
echo( ^</RegistrationInfo^>
echo( ^<Triggers^>
echo( ^<LogonTrigger^>
echo( ^<Enabled^>true^</Enabled^>
echo( ^</LogonTrigger^>
echo( ^</Triggers^>
echo( ^<Principals^>
echo( ^<Principal id^="Author"^>
echo( ^<UserId^>%usersid%^</UserId^>
echo( ^<LogonType^>InteractiveToken^</LogonType^>
echo( ^<RunLevel^>LeastPrivilege^</RunLevel^>
echo( ^</Principal^>
echo( ^</Principals^>
echo( ^<Settings^>
echo( ^<MultipleInstancesPolicy^>IgnoreNew^</MultipleInstancesPolicy^>
echo( ^<DisallowStartIfOnBatteries^>false^</DisallowStartIfOnBatteries^>
echo( ^<StopIfGoingOnBatteries^>true^</StopIfGoingOnBatteries^>
echo( ^<AllowHardTerminate^>false^</AllowHardTerminate^>
echo( ^<StartWhenAvailable^>false^</StartWhenAvailable^>
echo( ^<RunOnlyIfNetworkAvailable^>false^</RunOnlyIfNetworkAvailable^>
echo( ^<IdleSettings^>
echo( ^<StopOnIdleEnd^>true^</StopOnIdleEnd^>
echo( ^<RestartOnIdle^>false^</RestartOnIdle^>
echo( ^</IdleSettings^>
echo( ^<AllowStartOnDemand^>true^</AllowStartOnDemand^>
echo( ^<Enabled^>true^</Enabled^>
echo( ^<Hidden^>false^</Hidden^>
echo( ^<RunOnlyIfIdle^>false^</RunOnlyIfIdle^>
echo( ^<WakeToRun^>false^</WakeToRun^>
echo( ^<ExecutionTimeLimit^>PT0S^</ExecutionTimeLimit^>
echo( ^<Priority^>7^</Priority^>
echo( ^</Settings^>
echo( ^<Actions Context^="Author"^>
echo( ^<Exec^>
echo( ^<Command^>C:\Syncthing\Syncthing.exe^</Command^>
echo( ^<Arguments^>-no-console -no-browser^</Arguments^>
echo( ^</Exec^>
echo( ^</Actions^>
echo(^</Task^>
)>"C:\syncthingtemp\schtsk.xml"
goto createschtsk
rem creates xml file with customized settings for current user
:createschtsk
schtasks /create /TN Syncthing /xml "C:\syncthingtemp\schtsk.xml"
goto startprocess
rem Creates a new scheduled task for Syncthing auto start
:startprocess
cls
echo Starting Syncthing...
schtasks /run /tn Syncthing
goto cleanup
rem Starts the syncthing program in the background.
:cleanup
cls
echo Cleaning up...
rmdir /S /Q C:\syncthingtemp\
goto message
rem Sleans up after the extraction and file manipulation.
:message
cls
echo The utility has completed, your sync services
echo should be restored.
pause
goto exit
rem Tells the user that the program has completed.
:unsupported
cls
echo Unfortuneately only Windows 32bit and 64bit x86 compatible versions are
echo supported.
pause
goto exit
rem Tells teh user that Syncthing is unsupported on their platform.
:runasadmin
cls
echo This script needs to be run as admin.
echo.
echo To do this, right click on this script and select run as administrator.
pause
goto exit
rem Displays information to user on how to run this script as admin.
:exit
exit /B
rem Exits this script cleanly.