🐍 Python 3.10+
Backup Startup Programs to JSON (Python)
Snapshots Startup Programs (Win32_StartupCommand) to a timestamped JSON file for later comparison or auditing.
backup_startup_command_to_json.py
#!/usr/bin/env python3
"""
backup_startup_command_to_json.py
Snapshots Startup Programs (Win32_StartupCommand) to a timestamped JSON file, useful for
comparing point-in-time state later. Stdlib only.
Usage:
python backup_startup_command_to_json.py [output_folder]
"""
import csv
import io
import json
import subprocess
import sys
from datetime import datetime
from pathlib import Path
def main() -> None:
out_folder = Path(sys.argv[1]) if len(sys.argv) > 1 else Path(".")
out_folder.mkdir(parents=True, exist_ok=True)
result = subprocess.run(
["wmic", "path", "Win32_StartupCommand", "get", "Name,Command,Location,User", "/format:csv"],
capture_output=True, text=True, check=False,
)
if result.returncode != 0:
sys.exit(f"wmic failed: {result.stderr.strip()}")
lines = [line for line in result.stdout.splitlines() if line.strip()]
rows = list(csv.DictReader(io.StringIO("\n".join(lines)))) if len(lines) >= 2 else []
timestamp = datetime.now().strftime("%Y%m%d-%H%M%S")
out_path = out_folder / f"startup_command-snapshot_{timestamp}.json"
out_path.write_text(json.dumps(rows, indent=2), encoding="utf-8")
print(f"Snapshot of Startup Programs ({len(rows)} items) saved to {out_path}")
if __name__ == "__main__":
main()