本文目录导读:

Windows (PowerShell)
# 获取所有用户启动项
Get-CimInstance Win32_StartupCommand | Select-Object Name, Command, Location, User
# 或使用注册表方法
$startupPaths = @(
"HKLM:\Software\Microsoft\Windows\CurrentVersion\Run",
"HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce",
"HKCU:\Software\Microsoft\Windows\CurrentVersion\Run",
"HKCU:\Software\Microsoft\Windows\CurrentVersion\RunOnce"
)
foreach ($path in $startupPaths) {
if (Test-Path $path) {
Get-ItemProperty $path | Select-Object * -ExcludeProperty PS*
}
}
# 导出到文件
Get-CimInstance Win32_StartupCommand | Export-Csv -Path "startup_list.csv" -NoTypeInformation
Windows (CMD/Batch)
@echo off echo 系统启动项列表: echo ================ echo 当前用户启动项: reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" 2>nul echo. echo 所有用户启动项: reg query "HKLM\Software\Microsoft\Windows\CurrentVersion\Run" 2>nul echo. echo 启动文件夹: dir "%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup" /b 2>nul echo. echo 所有用户启动文件夹: dir "%ProgramData%\Microsoft\Windows\Start Menu\Programs\Startup" /b 2>nul pause
Linux (Bash)
#!/bin/bash
echo "系统启动项列表:"
echo "================"
# 检查 systemd 服务
echo "systemd 启用的服务:"
systemctl list-unit-files --type=service --state=enabled 2>/dev/null | head -30
# 检查 rc.local
if [ -f /etc/rc.local ]; then
echo -e "\n/etc/rc.local 内容:"
grep -v "^#" /etc/rc.local | grep -v "^$"
fi
# 检查 crontab
echo -e "\n系统 crontab:"
cat /etc/crontab 2>/dev/null | grep -v "^#" | grep -v "^$"
# 检查用户 crontab
echo -e "\n当前用户 crontab:"
crontab -l 2>/dev/null
# 检查自动启动脚本
echo -e "\n/etc/init.d 脚本:"
ls /etc/init.d/ 2>/dev/null
# 检查 ~/.bashrc 等
echo -e "\n用户 shell 启动脚本:"
grep -r "start\|run\|exec" ~/.bashrc ~/.profile ~/.bash_profile 2>/dev/null | head -20
macOS (Bash)
#!/bin/bash
echo "macOS 启动项列表:"
echo "=================="
# 用户启动项
echo "用户登录项:"
osascript -e 'tell application "System Events" to get the name of every login item'
# LaunchAgents (用户级别)
echo -e "\n用户 LaunchAgents:"
ls ~/Library/LaunchAgents/ 2>/dev/null
# LaunchDaemons (系统级别)
echo -e "\n系统 LaunchDaemons (概要):"
ls /Library/LaunchDaemons/ 2>/dev/null | head -10
# 系统 LaunchAgents
echo -e "\n系统 LaunchAgents (概要):"
ls /Library/LaunchAgents/ 2>/dev/null | head -10
# 检查 plist 文件内容
echo -e "\n用户启动项详细信息:"
for plist in ~/Library/LaunchAgents/*.plist; do
if [ -f "$plist" ]; then
echo "--- $(basename $plist) ---"
plutil -p "$plist" 2>/dev/null | grep "Program\|ProgramArguments" | head -3
fi
done
使用说明
- Windows PowerShell: 以管理员身份运行获取更全面的信息
- Linux: 需要适当权限访问系统目录
- macOS: 某些操作需要系统权限
这些脚本可以帮助你查看系统启动时自动运行的程序和服务。