From f2e315beac965aa7d11e24c46697133a74752405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=85=8E=E9=A5=BC=E6=9E=9C=E5=AD=90=E5=8D=B7=E9=B2=A8?= =?UTF-8?q?=E9=B1=BC=E8=BE=A3=E6=A4=92?= Date: Tue, 18 Mar 2025 00:36:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96cursor=5Fwin=5Fid=5Fmodifier.?= =?UTF-8?q?ps1=E8=84=9A=E6=9C=AC=EF=BC=8C=E5=A2=9E=E5=BC=BA=E6=B3=A8?= =?UTF-8?q?=E5=86=8C=E8=A1=A8=E6=93=8D=E4=BD=9C=E7=9A=84=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=92=8C=E7=94=A8=E6=88=B7=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=EF=BC=8C=E7=A1=AE=E4=BF=9D=E5=9C=A8=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=92=8C=E6=9B=B4=E6=96=B0MachineGuid=E6=97=B6?= =?UTF-8?q?=E6=8F=90=E4=BE=9B=E6=9B=B4=E6=B8=85=E6=99=B0=E7=9A=84=E5=8F=8D?= =?UTF-8?q?=E9=A6=88=E3=80=82=E5=90=8C=E6=97=B6=EF=BC=8C=E7=AE=80=E5=8C=96?= =?UTF-8?q?=E4=BA=86=E5=A4=87=E4=BB=BD=E6=96=87=E4=BB=B6=E7=9A=84=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BB=85=E5=9C=A8=E5=8E=9F?= =?UTF-8?q?=E5=A7=8B=E5=80=BC=E5=AD=98=E5=9C=A8=E6=97=B6=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E5=A4=87=E4=BB=BD=EF=BC=8C=E6=8F=90=E5=8D=87=E4=BA=86=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E7=9A=84=E7=A8=B3=E5=AE=9A=E6=80=A7=E5=92=8C=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BD=93=E9=AA=8C=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/run/cursor_win_id_modifier.ps1 | 92 ++++++++++---------------- 1 file changed, 35 insertions(+), 57 deletions(-) diff --git a/scripts/run/cursor_win_id_modifier.ps1 b/scripts/run/cursor_win_id_modifier.ps1 index 2d749d9..7e3fdc7 100644 --- a/scripts/run/cursor_win_id_modifier.ps1 +++ b/scripts/run/cursor_win_id_modifier.ps1 @@ -200,42 +200,51 @@ if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdenti function Update-MachineGuid { try { - # 先检查注册表路径是否存在 + # 检查注册表路径是否存在,不存在则创建 $registryPath = "HKLM:\SOFTWARE\Microsoft\Cryptography" if (-not (Test-Path $registryPath)) { - throw "注册表路径不存在: $registryPath" + Write-Host "$YELLOW[警告]$NC 注册表路径不存在: $registryPath,正在创建..." + New-Item -Path $registryPath -Force | Out-Null + Write-Host "$GREEN[信息]$NC 注册表路径创建成功" } - # 获取当前的 MachineGuid - $currentGuid = Get-ItemProperty -Path $registryPath -Name MachineGuid -ErrorAction Stop - if (-not $currentGuid) { - throw "无法获取当前的 MachineGuid" + # 获取当前的 MachineGuid,如果不存在则使用空字符串作为默认值 + $originalGuid = "" + try { + $currentGuid = Get-ItemProperty -Path $registryPath -Name MachineGuid -ErrorAction SilentlyContinue + if ($currentGuid) { + $originalGuid = $currentGuid.MachineGuid + Write-Host "$GREEN[信息]$NC 当前注册表值:" + Write-Host "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography" + Write-Host " MachineGuid REG_SZ $originalGuid" + } else { + Write-Host "$YELLOW[警告]$NC MachineGuid 值不存在,将创建新值" + } + } catch { + Write-Host "$YELLOW[警告]$NC 获取 MachineGuid 失败: $($_.Exception.Message)" } - $originalGuid = $currentGuid.MachineGuid - Write-Host "$GREEN[信息]$NC 当前注册表值:" - Write-Host "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography" - Write-Host " MachineGuid REG_SZ $originalGuid" - # 创建备份目录(如果不存在) if (-not (Test-Path $BACKUP_DIR)) { New-Item -ItemType Directory -Path $BACKUP_DIR -Force | Out-Null } - # 创建备份文件 - $backupFile = "$BACKUP_DIR\MachineGuid_$(Get-Date -Format 'yyyyMMdd_HHmmss').reg" - $backupResult = Start-Process "reg.exe" -ArgumentList "export", "`"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography`"", "`"$backupFile`"" -NoNewWindow -Wait -PassThru - - if ($backupResult.ExitCode -eq 0) { - Write-Host "$GREEN[信息]$NC 注册表项已备份到:$backupFile" - } else { - Write-Host "$YELLOW[警告]$NC 备份创建失败,继续执行..." + # 创建备份文件(仅当原始值存在时) + if ($originalGuid) { + $backupFile = "$BACKUP_DIR\MachineGuid_$(Get-Date -Format 'yyyyMMdd_HHmmss').reg" + $backupResult = Start-Process "reg.exe" -ArgumentList "export", "`"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography`"", "`"$backupFile`"" -NoNewWindow -Wait -PassThru + + if ($backupResult.ExitCode -eq 0) { + Write-Host "$GREEN[信息]$NC 注册表项已备份到:$backupFile" + } else { + Write-Host "$YELLOW[警告]$NC 备份创建失败,继续执行..." + } } # 生成新GUID $newGuid = [System.Guid]::NewGuid().ToString() - # 更新注册表 + # 更新或创建注册表值 Set-ItemProperty -Path $registryPath -Name MachineGuid -Value $newGuid -Force -ErrorAction Stop # 验证更新 @@ -252,8 +261,8 @@ function Update-MachineGuid { catch { Write-Host "$RED[错误]$NC 注册表操作失败:$($_.Exception.Message)" - # 尝试恢复备份 - if ($backupFile -and (Test-Path $backupFile)) { + # 尝试恢复备份(如果存在) + if (($backupFile -ne $null) -and (Test-Path $backupFile)) { Write-Host "$YELLOW[恢复]$NC 正在从备份恢复..." $restoreResult = Start-Process "reg.exe" -ArgumentList "import", "`"$backupFile`"" -NoNewWindow -Wait -PassThru @@ -529,42 +538,11 @@ function Write-ConfigFile { } } -function Compare-Version { - param ( - [string]$version1, - [string]$version2 - ) - - try { - $v1 = [version]($version1 -replace '[^\d\.].*$') - $v2 = [version]($version2 -replace '[^\d\.].*$') - return $v1.CompareTo($v2) - } - catch { - Write-Host "$RED[错误]$NC 版本比较失败: $_" - return 0 - } -} - -# 在主流程开始时添加版本检查 -Write-Host "$GREEN[信息]$NC 正在检查 Cursor 版本..." +# 获取并显示版本信息 $cursorVersion = Get-CursorVersion - +Write-Host "" if ($cursorVersion) { - $compareResult = Compare-Version $cursorVersion "0.45.0" - if ($compareResult -ge 0) { - Write-Host "$RED[错误]$NC 当前版本 ($cursorVersion) 暂不支持" - Write-Host "$YELLOW[建议]$NC 请使用 v0.45.x 及以下版本" - Write-Host "$YELLOW[建议]$NC 可以从以下地址下载支持的版本:" - Write-Host "Windows: https://download.todesktop.com/230313mzl4w4u92/Cursor%20Setup%200.44.11%20-%20Build%20250103fqxdt5u9z-x64.exe" - Write-Host "Mac ARM64: https://dl.todesktop.com/230313mzl4w4u92/versions/0.44.11/mac/zip/arm64" - Read-Host "按回车键退出" - exit 1 - } - else { - Write-Host "$GREEN[信息]$NC 当前版本 ($cursorVersion) 支持重置功能" - } -} -else { + Write-Host "$GREEN[信息]$NC 检测到 Cursor 版本: $cursorVersion,继续执行..." +} else { Write-Host "$YELLOW[警告]$NC 无法检测版本,将继续执行..." } \ No newline at end of file