Windows 定时任务 设置某bat文件在开机 MySQL启动后启动

To ensure that a Windows scheduled task starts after a specific Windows service, you can follow these steps:

  1. Open the Task Scheduler by searching for it in the Start menu or pressing Win + R and typing "taskschd.msc".

  2. In the Task Scheduler, click on "Create Basic Task" or "Create Task" in the right-hand panel to create a new task or edit an existing task.

  3. In the General tab, give the task a name and an optional description.

  4. In the Triggers tab, click on "New" to create a new trigger for the task.

  5. Choose the appropriate trigger type (e.g., At startup, On a schedule, etc.) and configure the trigger settings as needed.

  6. In the Actions tab, click on "New" to create a new action for the task.

  7. Select "Start a program" as the action type, and specify the program or script to be executed as part of the task.

  8. In the Conditions tab, check the box for "Start the task only if the computer is idle for" or "Start the task only if the following network connection is available" and configure the necessary conditions.

  9. In the Settings tab, enable the option "Run task as soon as possible after a scheduled start is missed."

  10. Now, to make the task start after a specific Windows service, you need to create a custom event trigger for the task. Follow these steps:

a. In the Triggers tab, click on "New" to create a new trigger for the task.

b. Choose the trigger type "On an Event" and click "Custom" at the bottom of the dialog box.

c. Click "New Event Filter" to open the XML Filter Editor.

d. In the XML Filter Editor, go to the tab "XML" and select "Edit query manually".

e. Type or copy the following XML query into the editor, replacing the SERVICE_NAME with the name of the specific Windows service. For example, to wait for the "Spooler" service, replace SERVICE_NAME with "Spooler":

自定义查询条件

XML 复制代码
<QueryList>     
<Query Id="0" Path="System">
         
<Select Path="System"> 
*[System[Provider[@Name='Service Control Manager'] and (EventID=7036)]] 
and            *[EventData[Data[@Name='param1'] and (Data='MySQL80')]]        
 </Select>
 </Query>
 </QueryList>

f. Click "OK" to save the XML query.

g. In the "Select Event" section, choose the Event ID "7036" (Service Control Manager event indicating a service has entered the running state).

h. Click "OK" and configure any additional settings for the trigger as needed.

  1. Finally, save the task and exit the Task Scheduler.

With these steps, the task will be triggered after the specified Windows service enters the running state.

how to ensure a windows scheduled task start after a specific windows service?

To ensure that a Windows scheduled task starts after a specific Windows service, you can use the task scheduler's "triggers" and "actions" to configure it correctly.

Here's a step-by-step guide on how to do it:

  1. Open the Task Scheduler by searching for it in the Start menu or using the `taskschd.msc` command in the Run dialog box (Win + R).

  2. In the Task Scheduler window, click on "Create Task" in the right sidebar.

  3. In the General tab, provide a name and description for the task.

  4. Go to the "Triggers" tab, click "New," and select the appropriate trigger for your task. This could be a specific time, logon, or an event.

  5. Set your desired trigger settings (e.g., daily at a specific time).

  6. Go to the "Actions" tab, click "New," and choose the executable or script that the task will run.

  7. In the "Add arguments" field, add any necessary command-line arguments for your script.

  8. In the "Start in (optional)" field, specify the directory where the script is located if needed.

  9. Now, switch to the "Conditions" tab. In the "Start the task only if the computer is idle for" section, make sure all boxes are unchecked.

  10. In the "Power" section, check the box next to "Start the task only if the computer is on AC power."

  11. In the "Settings" tab, select "Run task as soon as possible after a scheduled start is missed" if preferred.

  12. Next, switch to the "Actions" tab, click "New," and choose the executable or script that needs to be run before your scheduled task. Specify any necessary arguments and the appropriate "Start in (optional)" field if needed.

  13. Click on "OK" to save the settings.

By following these steps, your scheduled task will now start after the specified Windows service has begun.

相关推荐
love530love2 小时前
【笔记】AutoClaw NSIS 安装器卡死、进程杀不掉、目录删不了?我是这么解决的
人工智能·windows·笔记·agent
2401_841495645 小时前
【数据结构】B+树
数据结构·数据库·c++·b+树·概念·结构·操作原理
大模型码小白7 小时前
JAVA 集合框架进阶:List 与 Set 的深度解析与实战
java·开发语言·人工智能·windows·语言模型·list·ai编程
Hardworking6667 小时前
第7章 软硬件系统集成
数据库·软硬件系统集成
名字还没想好☜7 小时前
Go 的 time.Ticker 陷阱:定时任务里被忽略的内存泄漏与正确关闭
java·数据库·golang·go·定时器
关关长语8 小时前
Wsl解决MySQL容器跨域权限问题
mysql·docker·容器
熊猫钓鱼>_>8 小时前
Redis 突发缓存穿透:一次完整的定位复盘
数据库·人工智能·redis·缓存·ai·agent·智能
wenb1n8 小时前
MySQL诊断系列(3/6):索引分析——5个SQL揪出“僵尸索引”
数据库·人工智能·编程语言
这个DBA有点耶8 小时前
索引碎片与统计信息维护:执行计划突然变差的隐形杀手
mysql·程序员·架构
XUHUOJUN9 小时前
AKS 不是安装在 Windows Server 上,而是运行在 Windows Server 之上的 Azure 平台能力
windows·架构·k8s·azure local·azure stack