Wins

发布于 更新于

AI总结: 本文介绍了如何使用Autoruns软件和注册表来管理Windows系统的自启动项,包括通过注册表路径添加自启动脚本和在启动文件夹中添加快捷方式。此外,提供了一个PowerShell脚本示例,用于每天自动执行文件同步操作。该脚本定义了文件到目录的映射,确保目标目录存在,并在延迟3分钟后执行文件复制操作,同时处理可能出现的错误。改进建议包括提供更详细的操作步骤和解释,以帮助初学者更好地理解每个步骤的目的和功能。

注册表

可以使用Autoruns软件 可以方便的跳转注册表

regedit 打开注册表, 定位以下路径
HKCU\Software\Microsoft\Windows\CurrentVersion\Run

添加字符串值, 填名称和对应脚本路径

启动文件夹

按 Win + R 输入 shell:startup 回车

C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup  

添加需要自启动的快捷方式

同步配置

添加到注册表 每天自动执行

# 执行: powershell D:\\sync.ps1  
# 定义文件到目录的映射  
$mappings = @{  
    # Git配置  
    "C:\Users\Administrator\.gitconfig" = "D:\Config\Git\_gitconfig"  
}  

# 延迟3分钟执行  
Start-Sleep -Seconds 180  

foreach ($src in $mappings.Keys) {  
    $dst = $mappings[$src]  

    if (Test-Path $src -PathType Leaf) {  
        # 确保目标目录存在  
        if (-not (Test-Path $dst)) {  
            New-Item -ItemType Directory -Path $dst -Force | Out-Null  
        }  

        try {  
            Copy-Item -Path $src -Destination $dst -Force -ErrorAction Stop  
            Write-Host "Copied: $src -> $dst" -ForegroundColor Green  
        } catch {  
            Write-Host "Copy Fail: $src - $_" -ForegroundColor Red  
        }  
    } else {  
        Write-Host "Skip(Not Exist): $src" -ForegroundColor Yellow  
    }  
}