# 检查管理员权限 $isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) if (-not $isAdmin) { Write-Host "`n[错误] 请以管理员身份运行此脚本" -ForegroundColor Red Write-Host "请使用 'Start-Process pwsh -Verb RunAs' 启动管理员PowerShell" -ForegroundColor Yellow Pause exit } Write-Host "`n=== Cursor更新禁用工具 ===" -ForegroundColor Cyan # 定义路径 $updaterPath = Join-Path $env:LOCALAPPDATA "cursor-updater" $cursorPath = Join-Path $env:LOCALAPPDATA "Programs\cursor" $packageJsonPath = Join-Path $cursorPath "resources\app\package.json" Write-Host "`n正在检查路径..." -ForegroundColor Gray Write-Host "updater路径: $updaterPath" -ForegroundColor Gray try { # 1. 删除现有的updater文件/目录 if (Test-Path $updaterPath) { Write-Host "`n发现现有updater文件/目录,正在删除..." -ForegroundColor Yellow Remove-Item -Path $updaterPath -Force -Recurse -ErrorAction Stop Write-Host "成功删除现有文件/目录" -ForegroundColor Green } # 2. 创建空文件 Write-Host "`n正在创建updater文件..." -ForegroundColor Yellow New-Item -Path $updaterPath -ItemType File -Force -ErrorAction Stop | Out-Null Write-Host "成功创建updater文件" -ForegroundColor Green # 3. 设置文件权限 Write-Host "`n正在设置文件权限..." -ForegroundColor Yellow # 获取当前用户 $currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name # 创建新的ACL $acl = New-Object System.Security.AccessControl.FileSecurity $acl.SetAccessRuleProtection($true, $false) # 禁用继承 # 添加只读权限规则 $readRule = New-Object System.Security.AccessControl.FileSystemAccessRule( $currentUser, [System.Security.AccessControl.FileSystemRights]::Read, [System.Security.AccessControl.AccessControlType]::Allow ) $acl.AddAccessRule($readRule) # 应用ACL Set-Acl -Path $updaterPath -AclObject $acl -ErrorAction Stop # 设置只读属性 Set-ItemProperty -Path $updaterPath -Name IsReadOnly -Value $true -ErrorAction Stop Write-Host "成功设置文件权限" -ForegroundColor Green # 4. 修改package.json if (Test-Path $packageJsonPath) { Write-Host "`n正在修改package.json..." -ForegroundColor Yellow $json = Get-Content $packageJsonPath -Raw | ConvertFrom-Json $json.updateUrl = "" $json.disableUpdate = $true $json | ConvertTo-Json -Depth 10 | Set-Content $packageJsonPath -Encoding UTF8 Write-Host "成功修改package.json" -ForegroundColor Green } # 5. 验证权限 Write-Host "`n正在验证文件权限..." -ForegroundColor Yellow $item = Get-Item $updaterPath if (-not $item.IsReadOnly) { throw "文件权限验证失败:文件不是只读" } Write-Host "文件权限验证通过" -ForegroundColor Green Write-Host "`n[成功] Cursor更新已禁用!" -ForegroundColor Green } catch { Write-Host "`n[错误] 操作失败: $($_.Exception.Message)" -ForegroundColor Red } Write-Host "`n按任意键退出..." -ForegroundColor Gray $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")