win-planner 1.0.0__tar.gz → 1.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {win_planner-1.0.0 → win_planner-1.0.2}/PKG-INFO +1 -1
- {win_planner-1.0.0 → win_planner-1.0.2}/setup.py +1 -1
- {win_planner-1.0.0 → win_planner-1.0.2}/win_planner/__init__.py +60 -17
- {win_planner-1.0.0 → win_planner-1.0.2}/win_planner.egg-info/PKG-INFO +1 -1
- {win_planner-1.0.0 → win_planner-1.0.2}/README.md +0 -0
- {win_planner-1.0.0 → win_planner-1.0.2}/pyproject.toml +0 -0
- {win_planner-1.0.0 → win_planner-1.0.2}/setup.cfg +0 -0
- {win_planner-1.0.0 → win_planner-1.0.2}/win_planner.egg-info/SOURCES.txt +0 -0
- {win_planner-1.0.0 → win_planner-1.0.2}/win_planner.egg-info/dependency_links.txt +0 -0
- {win_planner-1.0.0 → win_planner-1.0.2}/win_planner.egg-info/requires.txt +0 -0
- {win_planner-1.0.0 → win_planner-1.0.2}/win_planner.egg-info/top_level.txt +0 -0
|
@@ -6,7 +6,7 @@ with open("README.md", encoding="utf-8") as f:
|
|
|
6
6
|
|
|
7
7
|
setup(
|
|
8
8
|
name="win_planner",
|
|
9
|
-
version="1.0.
|
|
9
|
+
version="1.0.2",
|
|
10
10
|
description="Регистрация задач в Планировщике задач Windows с наивысшими доступными правами и кастомным именем",
|
|
11
11
|
long_description=long_description,
|
|
12
12
|
long_description_content_type="text/markdown",
|
|
@@ -4,17 +4,19 @@ win_planner — регистрация задач в Планировщике з
|
|
|
4
4
|
API:
|
|
5
5
|
task_create(name=..., run_filepath=..., highest_available=..., description=...)
|
|
6
6
|
task_update(name=..., run_filepath=..., highest_available=..., description=..., new_name=...)
|
|
7
|
+
add_self(name=..., highest_available=..., description=...)
|
|
7
8
|
|
|
8
9
|
Триггер фиксирован: запуск при входе пользователя в систему.
|
|
9
10
|
Для задач с highest_available=True сам скрипт должен работать от администратора.
|
|
10
11
|
"""
|
|
11
12
|
|
|
12
13
|
import os
|
|
14
|
+
import sys
|
|
13
15
|
import ctypes
|
|
14
16
|
from datetime import datetime
|
|
15
17
|
|
|
16
|
-
__version__ = "1.0.
|
|
17
|
-
__all__ = ["task_create", "task_update"]
|
|
18
|
+
__version__ = "1.0.2"
|
|
19
|
+
__all__ = ["task_create", "task_update", "add_self"]
|
|
18
20
|
|
|
19
21
|
try:
|
|
20
22
|
import pythoncom
|
|
@@ -47,22 +49,24 @@ def _service():
|
|
|
47
49
|
return svc
|
|
48
50
|
|
|
49
51
|
|
|
50
|
-
def _new_definition(svc,
|
|
51
|
-
|
|
52
|
+
def _new_definition(svc,
|
|
53
|
+
run_filepath: str,
|
|
54
|
+
highest_available: bool,
|
|
55
|
+
description: str,
|
|
56
|
+
arguments: str = ""):
|
|
57
|
+
"""Собирает определение задачи из атрибутов."""
|
|
52
58
|
td = svc.NewTask(0)
|
|
53
59
|
|
|
54
|
-
# Описание
|
|
55
60
|
td.RegistrationInfo.Description = description
|
|
56
61
|
try:
|
|
57
62
|
td.RegistrationInfo.Author = os.getlogin()
|
|
58
63
|
except OSError:
|
|
59
64
|
pass
|
|
60
65
|
|
|
61
|
-
# Права запуска: RunLevel 1 = HIGHEST
|
|
66
|
+
# Права запуска: RunLevel 1 = HIGHEST, 0 = LIMITED
|
|
62
67
|
td.Principal.LogonType = TASK_LOGON_INTERACTIVE_TOKEN
|
|
63
68
|
td.Principal.RunLevel = 1 if highest_available else 0
|
|
64
69
|
|
|
65
|
-
# Настройки
|
|
66
70
|
td.Settings.StartWhenAvailable = True
|
|
67
71
|
td.Settings.AllowStartIfOnBatteries = True
|
|
68
72
|
td.Settings.StopIfGoingOnBatteries = False
|
|
@@ -73,6 +77,7 @@ def _new_definition(svc, run_filepath: str, highest_available: bool, description
|
|
|
73
77
|
# Действие — запуск файла
|
|
74
78
|
action = td.Actions.Create(TASK_ACTION_EXEC)
|
|
75
79
|
action.Path = run_filepath
|
|
80
|
+
action.Arguments = arguments
|
|
76
81
|
|
|
77
82
|
return td
|
|
78
83
|
|
|
@@ -93,7 +98,6 @@ def task_create(name: str,
|
|
|
93
98
|
"""
|
|
94
99
|
Регистрирует задачу в Планировщике задач Windows.
|
|
95
100
|
|
|
96
|
-
Параметры:
|
|
97
101
|
name — кастомное имя задачи;
|
|
98
102
|
run_filepath — путь к exe/скрипту;
|
|
99
103
|
highest_available — запуск с наивысшими доступными правами;
|
|
@@ -123,13 +127,8 @@ def task_update(name: str,
|
|
|
123
127
|
"""
|
|
124
128
|
Изменяет атрибуты уже созданной задачи.
|
|
125
129
|
|
|
126
|
-
Передайте только то, что нужно поменять:
|
|
127
|
-
|
|
128
|
-
highest_available — новое значение прав запуска;
|
|
129
|
-
description — новое описание;
|
|
130
|
-
new_name — переименовать задачу.
|
|
131
|
-
|
|
132
|
-
Не переданные параметры остаются прежними.
|
|
130
|
+
Передайте только то, что нужно поменять: run_filepath, highest_available,
|
|
131
|
+
description или new_name (переименовать). Остальное останется прежним.
|
|
133
132
|
"""
|
|
134
133
|
svc = _service()
|
|
135
134
|
try:
|
|
@@ -139,11 +138,13 @@ def task_update(name: str,
|
|
|
139
138
|
raise LookupError(f"Задача '{name}' не найдена") from exc
|
|
140
139
|
|
|
141
140
|
if new_name:
|
|
142
|
-
|
|
141
|
+
if not new_name or not new_name.strip():
|
|
142
|
+
raise ValueError("new_name не может быть пустым")
|
|
143
|
+
if "\\" in new_name or "/" in new_name:
|
|
144
|
+
raise ValueError("new_name не должен содержать '\\' или '/'")
|
|
143
145
|
if run_filepath is not None and not os.path.isfile(run_filepath):
|
|
144
146
|
raise FileNotFoundError(f"Файл не найден: {run_filepath}")
|
|
145
147
|
|
|
146
|
-
# Меняем только переданные атрибуты
|
|
147
148
|
if description is not None:
|
|
148
149
|
td.RegistrationInfo.Description = description
|
|
149
150
|
if highest_available is not None:
|
|
@@ -165,3 +166,45 @@ def task_update(name: str,
|
|
|
165
166
|
"description": td.RegistrationInfo.Description,
|
|
166
167
|
"updated_at": datetime.now().isoformat(timespec="seconds"),
|
|
167
168
|
}
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def add_self(name: str,
|
|
172
|
+
highest_available: bool = True,
|
|
173
|
+
description: str = "") -> dict:
|
|
174
|
+
"""
|
|
175
|
+
Регистрирует текущий запущенный скрипт в Планировщике задач:
|
|
176
|
+
при каждом входе пользователя он будет запускаться автоматически.
|
|
177
|
+
|
|
178
|
+
name — имя задачи;
|
|
179
|
+
highest_available — запуск с наивысшими доступными правами;
|
|
180
|
+
description — описание задачи.
|
|
181
|
+
"""
|
|
182
|
+
script_path = os.path.abspath(sys.argv[0])
|
|
183
|
+
if not os.path.isfile(script_path):
|
|
184
|
+
raise FileNotFoundError(
|
|
185
|
+
f"Не удалось определить файл скрипта: {script_path}"
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
# .pyw запускаем без консоли, .py — обычным интерпретатором
|
|
189
|
+
python_exe = sys.executable
|
|
190
|
+
if script_path.lower().endswith(".pyw"):
|
|
191
|
+
python_exe = python_exe.replace("python.exe", "pythonw.exe")
|
|
192
|
+
|
|
193
|
+
_validate(name, python_exe)
|
|
194
|
+
|
|
195
|
+
svc = _service()
|
|
196
|
+
td = _new_definition(svc, python_exe, highest_available, description,
|
|
197
|
+
arguments=f'"{script_path}"')
|
|
198
|
+
|
|
199
|
+
svc.GetFolder("\\").RegisterTaskDefinition(
|
|
200
|
+
name, td, TASK_CREATE_OR_UPDATE, None, None, TASK_LOGON_INTERACTIVE_TOKEN
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
return {
|
|
204
|
+
"name": name,
|
|
205
|
+
"script": script_path,
|
|
206
|
+
"interpreter": python_exe,
|
|
207
|
+
"highest_available": highest_available,
|
|
208
|
+
"description": description,
|
|
209
|
+
"registered_at": datetime.now().isoformat(timespec="seconds"),
|
|
210
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|