-
Notifications
You must be signed in to change notification settings - Fork 1
/
ADD-WIN10-SCHEDULER-JOB.bat
168 lines (120 loc) · 3.93 KB
/
ADD-WIN10-SCHEDULER-JOB.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
@echo off
:: Copyright 2014-2023 GPLv3, Open Crypto Tracker by Mike Kilday: Mike@DragonFrugal.com
echo:
echo IF YOU ARE RUNNING THE 'DESKTOP EDITION', the setting 'desktop_cron_interval' in the POWER USER Admin Config section MUST BE SET TO ZERO, before this Windows Task Scheduler job will be allowed to takeover running background tasks instead.
echo:
pause
echo:
echo Enter the time interval in minutes to run this scheduled task
set /p cron_interval="(5, 10, 15, 20, or 30...leave blank / hit enter for default of 20): "
if "%cron_interval%"=="" (
set "cron_interval=20"
echo:
echo Using default time interval in minutes:
) else (
echo:
echo Using custom time interval in minutes:
)
echo %cron_interval%
echo:
if exist %~p0%..\php\php-win.exe (
set "php_cli_binary_default=%~p0%..\php\php-win.exe"
echo PHP CLI binary detected at:
echo %~p0%..\php\php-win.exe
echo:
) else if exist %~p0%php\php-win.exe (
set "php_cli_binary_default=%~p0%php\php-win.exe"
echo PHP CLI binary detected at:
echo %~p0%php\php-win.exe
echo:
) else if exist %~p0%..\bin\php\php-win.exe (
set "php_cli_binary_default=%~p0%..\bin\php\php-win.exe"
echo PHP CLI binary detected at:
echo %~p0%..\bin\php\php-win.exe
echo:
) else if exist %~p0%bin\php\php-win.exe (
set "php_cli_binary_default=%~p0%bin\php\php-win.exe"
echo PHP CLI binary detected at:
echo %~p0%bin\php\php-win.exe
echo:
) else (
set "php_cli_binary_default=C:\php\php-win.exe"
)
echo Enter the full path to the PHP CLI binary
set /p php_cli_binary="(leave blank / hit enter for default of %php_cli_binary_default%): "
if "%php_cli_binary%"=="" (
set "php_cli_binary=%php_cli_binary_default%"
echo:
echo Using default PHP CLI binary path:
) else (
echo:
echo Using custom PHP CLI binary path:
)
echo %php_cli_binary%
echo:
if exist %~p0%cron.php (
set "cron_php_default=%~p0%cron.php"
echo cron.php detected at:
echo %~p0%cron.php
echo:
) else if exist %~p0%INSTALL_CRYPTO_TRACKER_HERE\cron.php (
set "cron_php_default=%~p0%INSTALL_CRYPTO_TRACKER_HERE\cron.php"
echo cron.php detected at:
echo %~p0%INSTALL_CRYPTO_TRACKER_HERE\cron.php
echo:
) else if exist %~p0%www\cron.php (
set "cron_php_default=%~p0%www\cron.php"
echo cron.php detected at:
echo %~p0%www\cron.php
echo:
) else (
set "cron_php_default=C:\php\cron.php"
)
echo Enter the full path to cron.php
set /p cron_php="(leave blank / hit enter for default of %cron_php_default%): "
if "%cron_php%"=="" (
set "cron_php=%cron_php_default%"
echo:
echo Using default cron.php path:
) else (
echo:
echo Using custom cron.php path:
)
echo %cron_php%
echo:
:: Check the length of the action command (it cannot be longer than 261 characters)
call :strlen "%php_cli_binary% %cron_php%", len
echo Action command character length is: %len%
echo:
if %len% gtr 261 (
echo ACTION COMMAND IS LONGER THAN THE MAXIMUM 261 CHARACTERS ALLOWED ^(%len% characters^)^, TRY MOVING THE APP INSTALLATION TO A SHORTER FILE PATH
echo:
pause
exit
) else (
echo Action command is within the maximum 261 character limit ^(%len% characters^)^, proceeding...
echo:
)
echo Windows will now add this Task Scheduler entry. If you wish
echo to remove this entry in the future, open Task Scheduler and
echo choose 'CRYPTO_TRACKER_CRON', then click 'Delete' on the right.
echo:
pause
echo:
schtasks /Create /TN CRYPTO_TRACKER_CRON /TR "%php_cli_binary% %cron_php%" /SC MINUTE /MO %cron_interval%
echo:
echo UNLESS YOU SEE ANY ERRORS ABOVE, the task 'CRYPTO_TRACKER_CRON' has been created, with PHP CLI binary path set as '%php_cli_binary%', cron path set as '%cron_php%', and set to run every %cron_interval% minutes.
echo:
pause
:: strlen function START
:: https://stackoverflow.com/questions/41179376/getting-length-of-a-variable-in-batch
:strlen string len
SetLocal EnableDelayedExpansion
set "token=#%~1" & set "len=0"
for /L %%A in (12,-1,0) do (
set/A "len|=1<<%%A"
for %%B in (!len!) do if "!token:~%%B,1!"=="" set/A "len&=~1<<%%A"
)
EndLocal & set %~2=%len%
exit/B
:: strlen function END