启动项命令就是查看和调整开机自动加载项目的一组系统命令。你可以把它理解为开机时自动运行的程序、服务、计划任务和用户登录项。在 Windows 里,msconfig、schtasks、reg query 可以帮你看到这些项目;在 Linux 里,systemctl、crontab、systemd 服务文件和 rc 脚本是主要入口;在 macOS 里,launchctl 和 LaunchAgents、LaunchDaemons 目录负责查看与调整。掌握这些命令后,你可以在终端、命令提示符或 PowerShell 里用标准步骤核对启动项来源,并按系统类型选择合适的方法。
一、核心答案速览
| 系统 | 常见入口 | 常用命令 |
|---|---|---|
| Windows | 系统配置、注册表启动项、计划任务、启动文件夹 | `msconfig`、`schtasks /query`、`reg query`、`shell:startup` |
| Linux | systemd 服务、计划任务、init 脚本、rc.local | `systemctl list-unit-files`、`crontab -l`、`ls /etc/init.d` |
| macOS | launchd 配置、用户登录项 | `launchctl list`、`ls ~/Library/LaunchAgents` |
二、Windows 常用启动项命令
| 命令 | 用途 | 示例 |
|---|---|---|
| `msconfig` | 打开系统配置,查看服务与启动项目 | 按 `Win + R`,输入 `msconfig`,回车 |
| `schtasks /query` | 查看计划任务列表 | `schtasks /query /fo LIST /v` |
| `reg query` | 查看注册表中的开机启动项 | `reg query "HKCUSoftwareMicrosoftWindowsCurrentVersionRun"` |
| `shell:startup` | 打开当前用户启动文件夹 | 按 `Win + R`,输入 `shell:startup`,回车 |
| `shell:common startup` | 打开全部用户启动文件夹 | 按 `Win + R`,输入 `shell:common startup`,回车 |
Windows 查看步骤
- 1、按 `Win + R`,打开运行窗口。
- 2、输入 `msconfig`,回车。
- 3、在系统配置窗口中查看“服务”和“启动”区域。
- 4、需要查看注册表启动项时,打开命令提示符或 PowerShell,输入 `reg query "HKCUSoftwareMicrosoftWindowsCurrentVersionRun"`。
- 5、需要查看全部用户启动项时,输入 `reg query "HKLMSoftwareMicrosoftWindowsCurrentVersionRun"`。
- 6、需要查看快捷方式类启动项时,打开 `shell:startup` 或 `shell:common startup` 文件夹。
三、Linux 常用启动项命令
| 命令 | 用途 | 示例 |
|---|---|---|
| `systemctl list-unit-files --type=service` | 查看 systemd 服务的开机启动配置 | `systemctl list-unit-files --type=service` |
| `systemctl is-enabled` | 查看单个服务是否开机启动 | `systemctl is-enabled ssh` |
| `systemctl enable` | 设置服务开机启动 | `systemctl enable ssh` |
| `systemctl list-dependencies` | 查看默认启动目标依赖的项目 | `systemctl list-dependencies multi-user.target` |
| `ls /etc/systemd/system` | 查看本机自定义 systemd 服务文件 | `ls -l /etc/systemd/system` |
| `crontab -l` | 查看当前用户的定时任务 | `crontab -l` |
| `cat /etc/crontab` | 查看系统计划任务配置 | `cat /etc/crontab` |
| `ls /etc/init.d` | 查看传统 init 服务脚本 | `ls -l /etc/init.d` |
Linux 查看步骤
- 1、打开终端。
- 2、输入 `systemctl list-unit-files --type=service`,查看服务开机启动状态。
- 3、输入 `systemctl list-dependencies multi-user.target`,查看默认启动目标关联的项目。
- 4、输入 `crontab -l`,查看当前用户的计划任务。
- 5、查看 `/etc/systemd/system/`、`/lib/systemd/system/`、`/etc/init.d/` 中的服务文件和脚本。
- 6、需要新增服务开机启动时,输入 `systemctl enable 服务名`。
四、macOS 常用启动项命令
| 命令 | 用途 | 示例 |
|---|---|---|
| `launchctl list` | 查看当前 launchd 加载的项目 | `launchctl list` |
| `ls ~/Library/LaunchAgents` | 查看当前用户登录项配置 | `ls -l ~/Library/LaunchAgents` |
| `ls /Library/LaunchAgents` | 查看全部用户登录项配置 | `ls -l /Library/LaunchAgents` |
| `ls /Library/LaunchDaemons` | 查看系统后台服务配置 | `ls -l /Library/LaunchDaemons` |
| `osascript` | 通过脚本语言读取登录项名称 | `osascript -e tell application "System Events" to get the name of every login item ` |
macOS 查看步骤
- 1、打开终端。
- 2、输入 `launchctl list`,查看当前加载项目。
- 3、查看 `~/Library/LaunchAgents`、`/Library/LaunchAgents`、`/Library/LaunchDaemons` 中的配置文件。
- 4、需要查看用户登录项时,可在系统设置通用登录项中查看。
- 5、需要新增用户登录项时,可在 Finder 中选中应用,通过登录项设置添加。
五、通用操作路径
| 路径类型 | 适用系统 | 说明 |
|---|---|---|
| 启动文件夹 | Windows、macOS | 快捷方式或应用入口会随用户登录加载 |
| 注册表 Run 项 | Windows | 程序通过注册表写入开机启动配置 |
| 计划任务 | Windows、Linux、macOS | 程序按时间或事件触发运行 |
| systemd 服务 | Linux | 服务文件决定开机启动配置 |
| launchd 配置 | macOS | plist 文件决定用户登录项或系统后台项目 |
六、判断启动项类型
| 看到的内容 | 可能的启动项类型 |
|---|---|
| 项目出现在 `Startup` 文件夹 | Windows 快捷方式启动项 |
| 项目出现在注册表 `Run` 路径 | Windows 开机自启项 |
| 项目出现在 `schtasks /query` 结果 | Windows 计划任务 |
| 项目出现在 `systemctl list-unit-files` 结果 | Linux systemd 服务 |
| 项目出现在 `crontab -l` 结果 | Linux 计划任务 |
| 项目出现在 `launchctl list` 或 LaunchAgents 目录 | macOS launchd 项目 |
免责声明:本文仅用于学习交流,请结合实际系统版本和安全规范操作。


