-
Notifications
You must be signed in to change notification settings - Fork 66
/
win_change_id.bat
71 lines (57 loc) · 2.7 KB
/
win_change_id.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
@echo off
setlocal EnableDelayedExpansion
:: Set configuration file path
set "STORAGE_FILE=%APPDATA%\Cursor\User\globalStorage\storage.json"
echo Starting script...
echo Target file path: %STORAGE_FILE%
:: Generate random IDs in correct format
:: Generate machineId (40-character hex)
powershell -Command "$bytes = New-Object Byte[] 32; (New-Object Security.Cryptography.RNGCryptoServiceProvider).GetBytes($bytes); -join ($bytes | ForEach-Object { $_.ToString('x2') })" > "%TEMP%\guid1.txt"
if errorlevel 1 goto :error
set /p NEW_MACHINE_ID=<"%TEMP%\guid1.txt"
:: Generate macMachineId (40-character hex)
powershell -Command "$bytes = New-Object Byte[] 32; (New-Object Security.Cryptography.RNGCryptoServiceProvider).GetBytes($bytes); -join ($bytes | ForEach-Object { $_.ToString('x2') })" > "%TEMP%\guid2.txt"
if errorlevel 1 goto :error
set /p NEW_MAC_MACHINE_ID=<"%TEMP%\guid2.txt"
:: Generate sqmId (UUID with braces)
powershell -Command "$guid = [guid]::NewGuid(); '{' + $guid.ToString().ToUpper() + '}'" > "%TEMP%\guid3.txt"
if errorlevel 1 goto :error
set /p NEW_SQM_ID=<"%TEMP%\guid3.txt"
:: Generate devDeviceId (standard UUID)
powershell -Command "[guid]::NewGuid().ToString()" > "%TEMP%\guid4.txt"
if errorlevel 1 goto :error
set /p NEW_DEV_DEVICE_ID=<"%TEMP%\guid4.txt"
:: Clean up temporary files
del "%TEMP%\guid1.txt" "%TEMP%\guid2.txt" "%TEMP%\guid3.txt" "%TEMP%\guid4.txt"
:: Create backup
if exist "%STORAGE_FILE%" (
copy "%STORAGE_FILE%" "%STORAGE_FILE%.backup_%date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%%time:~6,2%" >nul
)
:: Create and execute update script
(
echo $ErrorActionPreference = 'Stop'
echo try {
echo $json = Get-Content '%STORAGE_FILE%' -Raw
echo $json = $json -replace '"telemetry\.machineId"\s*:\s*"[^"]*"', '"telemetry.machineId": "%NEW_MACHINE_ID%"'
echo $json = $json -replace '"telemetry\.macMachineId"\s*:\s*"[^"]*"', '"telemetry.macMachineId": "%NEW_MAC_MACHINE_ID%"'
echo $json = $json -replace '"telemetry\.sqmId"\s*:\s*"[^"]*"', '"telemetry.sqmId": "%NEW_SQM_ID%"'
echo $json = $json -replace '"telemetry\.devDeviceId"\s*:\s*"[^"]*"', '"telemetry.devDeviceId": "%NEW_DEV_DEVICE_ID%"'
echo $json ^| Set-Content '%STORAGE_FILE%' -NoNewline
echo } catch {
echo Write-Host "Error: $($_.Exception.Message)"
echo exit 1
echo }
) > "%TEMP%\update_json.ps1"
powershell -ExecutionPolicy Bypass -File "%TEMP%\update_json.ps1"
if errorlevel 1 (
del "%TEMP%\update_json.ps1"
goto :error
)
del "%TEMP%\update_json.ps1"
echo Operation completed successfully!
goto :end
:error
echo Script execution error!
echo Please make sure Cursor editor is closed and you have sufficient file access permissions.
:end
pause