Skip to content

Commit 1373067

Browse files
Create run.ps1
1 parent 32eb829 commit 1373067

File tree

1 file changed

+169
-0
lines changed

1 file changed

+169
-0
lines changed

run.ps1

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
# Set output encoding to UTF-8
2+
$OutputEncoding = [System.Text.Encoding]::UTF8
3+
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
4+
5+
# Color definitions
6+
$RED = "`e[31m"
7+
$GREEN = "`e[32m"
8+
$YELLOW = "`e[33m"
9+
$BLUE = "`e[34m"
10+
$NC = "`e[0m"
11+
12+
# Configuration file paths
13+
$STORAGE_FILE = "$env:APPDATA\Cursor\User\globalStorage\storage.json"
14+
$BACKUP_DIR = "$env:APPDATA\Cursor\User\globalStorage\backups"
15+
16+
# Check for administrator privileges
17+
function Test-Administrator {
18+
$user = [Security.Principal.WindowsIdentity]::GetCurrent()
19+
$principal = New-Object Security.Principal.WindowsPrincipal($user)
20+
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
21+
}
22+
23+
if (-not (Test-Administrator)) {
24+
Write-Host "$RED[Error]$NC Please run this script as an administrator."
25+
Write-Host "Right-click the script and select 'Run as Administrator'."
26+
Read-Host "Press Enter to exit"
27+
exit 1
28+
}
29+
30+
# Display Logo
31+
Clear-Host
32+
Write-Host "@"
33+
Write-Host "
34+
██████╗██╗ ██╗██████╗ ███████╗ ██████╗ ██████╗
35+
██╔════╝██║ ██║██╔══██╗██╔════╝██╔═══██╗██╔══██╗
36+
██║ ██║ ██║██████╔╝███████╗██║ ██║██████╔╝
37+
██║ ██║ ██║██╔══██╗╚════██║██║ ██║██╔══██╗
38+
╚██████╗╚██████╔╝██║ ██║███████║╚██████╔╝██║ ██║
39+
╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═╝ ╚═╝
40+
"
41+
Write-Host "$BLUE================================$NC"
42+
Write-Host "$GREEN Cursor ID Modification Tool $NC"
43+
Write-Host "$BLUE================================$NC"
44+
Write-Host ""
45+
46+
# Check and close Cursor processes
47+
Write-Host "$GREEN[Info]$NC Checking for Cursor processes..."
48+
49+
function Get-ProcessDetails {
50+
param($processName)
51+
Write-Host "$BLUE[Debug]$NC Retrieving details for $processName:"
52+
Get-WmiObject Win32_Process -Filter "name='$processName'" |
53+
Select-Object ProcessId, ExecutablePath, CommandLine |
54+
Format-List
55+
}
56+
57+
# Define retry settings
58+
$MAX_RETRIES = 5
59+
$WAIT_TIME = 1
60+
61+
# Handle process closure
62+
function Close-CursorProcess {
63+
param($processName)
64+
65+
$process = Get-Process -Name $processName -ErrorAction SilentlyContinue
66+
if ($process) {
67+
Write-Host "$YELLOW[Warning]$NC Found $processName running."
68+
Get-ProcessDetails $processName
69+
70+
Write-Host "$YELLOW[Warning]$NC Attempting to close $processName..."
71+
Stop-Process -Name $processName -Force
72+
73+
$retryCount = 0
74+
while ($retryCount -lt $MAX_RETRIES) {
75+
$process = Get-Process -Name $processName -ErrorAction SilentlyContinue
76+
if (-not $process) { break }
77+
78+
$retryCount++
79+
if ($retryCount -ge $MAX_RETRIES) {
80+
Write-Host "$RED[Error]$NC Unable to close $processName after $MAX_RETRIES attempts."
81+
Get-ProcessDetails $processName
82+
Write-Host "$RED[Error]$NC Please manually close the process and try again."
83+
Read-Host "Press Enter to exit"
84+
exit 1
85+
}
86+
Write-Host "$YELLOW[Warning]$NC Waiting for process closure, attempt $retryCount/$MAX_RETRIES..."
87+
Start-Sleep -Seconds $WAIT_TIME
88+
}
89+
Write-Host "$GREEN[Info]$NC Successfully closed $processName."
90+
}
91+
}
92+
93+
# Close all Cursor processes
94+
Close-CursorProcess "Cursor"
95+
Close-CursorProcess "cursor"
96+
97+
# Create backup directory
98+
if (-not (Test-Path $BACKUP_DIR)) {
99+
New-Item -ItemType Directory -Path $BACKUP_DIR | Out-Null
100+
}
101+
102+
# Backup existing configuration
103+
if (Test-Path $STORAGE_FILE) {
104+
Write-Host "$GREEN[Info]$NC Backing up configuration file..."
105+
$backupName = "storage.json.backup_$(Get-Date -Format 'yyyyMMdd_HHmmss')"
106+
Copy-Item $STORAGE_FILE "$BACKUP_DIR\$backupName"
107+
}
108+
109+
# Generate new ID
110+
Write-Host "$GREEN[Info]$NC Generating new ID..."
111+
112+
function Get-RandomHex {
113+
param (
114+
[int]$length
115+
)
116+
$bytes = New-Object byte[] $length
117+
$rng = [System.Security.Cryptography.RNGCryptoServiceProvider]::new()
118+
$rng.GetBytes($bytes)
119+
$rng.Dispose()
120+
return -join ($bytes | ForEach-Object { '{0:x2}' -f $_ })
121+
}
122+
123+
$UUID = [System.Guid]::NewGuid().ToString()
124+
$prefixBytes = [System.Text.Encoding]::UTF8.GetBytes("auth0|user_")
125+
$prefixHex = -join ($prefixBytes | ForEach-Object { '{0:x2}' -f $_ })
126+
$randomPart = Get-RandomHex -length 32
127+
$MACHINE_ID = "$prefixHex$randomPart"
128+
$MAC_MACHINE_ID = Get-RandomHex -length 32
129+
$SQM_ID = "{$([System.Guid]::NewGuid().ToString().ToUpper())}"
130+
131+
# Update configuration file
132+
Write-Host "$GREEN[Info]$NC Updating configuration..."
133+
134+
try {
135+
$storageDir = Split-Path $STORAGE_FILE -Parent
136+
if (-not (Test-Path $storageDir)) {
137+
New-Item -ItemType Directory -Path $storageDir -Force | Out-Null
138+
}
139+
140+
$config = @{
141+
'telemetry.machineId' = $MACHINE_ID
142+
'telemetry.macMachineId' = $MAC_MACHINE_ID
143+
'telemetry.devDeviceId' = $UUID
144+
'telemetry.sqmId' = $SQM_ID
145+
}
146+
147+
$jsonContent = $config | ConvertTo-Json
148+
[System.IO.File]::WriteAllText(
149+
[System.IO.Path]::GetFullPath($STORAGE_FILE),
150+
$jsonContent,
151+
[System.Text.Encoding]::UTF8
152+
)
153+
Write-Host "$GREEN[Info]$NC Configuration file updated successfully."
154+
} catch {
155+
Write-Host "$RED[Error]$NC Failed to update configuration: $_"
156+
Read-Host "Press Enter to exit"
157+
exit 1
158+
}
159+
160+
Write-Host ""
161+
Write-Host "$GREEN[Info]$NC Configuration updated:"
162+
Write-Host "$BLUE[Debug]$NC machineId: $MACHINE_ID"
163+
Write-Host "$BLUE[Debug]$NC macMachineId: $MAC_MACHINE_ID"
164+
Write-Host "$BLUE[Debug]$NC devDeviceId: $UUID"
165+
Write-Host "$BLUE[Debug]$NC sqmId: $SQM_ID"
166+
167+
Write-Host "$GREEN[Info]$NC Please restart Cursor to apply the new configuration."
168+
Read-Host "Press Enter to exit"
169+
exit 0

0 commit comments

Comments
 (0)