1
- # Set output encoding to UTF-8
1
+ # Set the output encoding to UTF-8
2
2
$OutputEncoding = [System.Text.Encoding ]::UTF8
3
3
[Console ]::OutputEncoding = [System.Text.Encoding ]::UTF8
4
4
5
- # Color definitions
5
+ # Color definition
6
6
$RED = " `e [31m"
7
7
$GREEN = " `e [32m"
8
8
$YELLOW = " `e [33m"
9
9
$BLUE = " `e [34m"
10
10
$NC = " `e [0m"
11
11
12
- # Configuration file paths
12
+ # Configuration file path
13
13
$STORAGE_FILE = " $env: APPDATA \Cursor\User\globalStorage\storage.json"
14
14
$BACKUP_DIR = " $env: APPDATA \Cursor\User\globalStorage\backups"
15
15
16
- # Check for administrator privileges
16
+ # Check administrator privileges
17
17
function Test-Administrator {
18
18
$user = [Security.Principal.WindowsIdentity ]::GetCurrent()
19
19
$principal = New-Object Security.Principal.WindowsPrincipal($user )
20
20
return $principal.IsInRole ([Security.Principal.WindowsBuiltInRole ]::Administrator)
21
21
}
22
22
23
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'. "
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
26
Read-Host " Press Enter to exit"
27
27
exit 1
28
28
}
29
29
30
30
# Display Logo
31
31
Clear-Host
32
- Write-Host " @"
33
- Write-Host "
34
- ██████╗██╗ ██╗██████╗ ███████╗ ██████╗ ██████╗
35
- ██╔════╝██║ ██║██╔══██╗██╔════╝██╔═══██╗██╔══██╗
36
- ██║ ██║ ██║██████╔╝███████╗██║ ██║██████╔╝
37
- ██║ ██║ ██║██╔══██╗╚════██║██║ ██║██╔══██╗
38
- ╚██████╗╚██████╔╝██║ ██║███████║╚██████╔╝██║ ██║
39
- ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═╝ ╚═╝
40
- "
32
+ Write-Host @"
33
+
34
+ ╗
35
+ ██╔════╝██║ ██║██╔══██╗██╔════╝██╔═══██╗██╔══██╗
36
+ ║
37
+ ██║ ██║ ██║██╔══██╗╚════██║██║ ██║██╔══██╗
38
+ *
39
+ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═╝ ╚═╝
40
+
41
+ "@
41
42
Write-Host " $BLUE ================================$NC "
42
- Write-Host " $GREEN Cursor ID Modification Tool $NC "
43
+ Write-Host " $GREEN Cursor ID Modification Tool $NC "
43
44
Write-Host " $BLUE ================================$NC "
44
45
Write-Host " "
45
46
46
- # Check and close Cursor processes
47
- Write-Host " $GREEN [Info ]$NC Checking for Cursor processes ..."
47
+ # Check and close the Cursor process
48
+ Write-Host " $GREEN [INFO ]$NC Check Cursor Process ..."
48
49
49
50
function Get-ProcessDetails {
50
51
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 |
52
+ Write-Host " $BLUE [debug ]$NC Getting $processName process details :"
53
+ Get-WmiObject Win32_Process - Filter " name='$processName '" |
54
+ Select-Object ProcessId, ExecutablePath, CommandLine |
54
55
Format-List
55
56
}
56
57
57
- # Define retry settings
58
+ # Define the maximum number of retries and waiting time
58
59
$MAX_RETRIES = 5
59
60
$WAIT_TIME = 1
60
61
61
- # Handle process closure
62
+ # Process shutdown
62
63
function Close-CursorProcess {
63
64
param ($processName )
64
-
65
+
65
66
$process = Get-Process - Name $processName - ErrorAction SilentlyContinue
66
67
if ($process ) {
67
- Write-Host " $YELLOW [Warning]$NC Found $processName running. "
68
+ Write-Host " $YELLOW [Warning]$NC found $processName running"
68
69
Get-ProcessDetails $processName
69
-
70
- Write-Host " $YELLOW [Warning ]$NC Attempting to close $processName ..."
70
+
71
+ Write-Host " $YELLOW [WARN ]$NC Trying to shut down $processName ..."
71
72
Stop-Process - Name $processName - Force
72
-
73
+
73
74
$retryCount = 0
74
75
while ($retryCount -lt $MAX_RETRIES ) {
75
76
$process = Get-Process - Name $processName - ErrorAction SilentlyContinue
76
77
if (-not $process ) { break }
77
-
78
+
78
79
$retryCount ++
79
80
if ($retryCount -ge $MAX_RETRIES ) {
80
- Write-Host " $RED [Error ]$NC Unable to close $processName after $MAX_RETRIES attempts. "
81
+ Write-Host " $RED [ERROR ]$NC Failed to close $processName after $MAX_RETRIES attempts"
81
82
Get-ProcessDetails $processName
82
- Write-Host " $RED [Error ]$NC Please manually close the process and try again. "
83
+ Write-Host " $RED [error ]$NC Please manually close the process and try again"
83
84
Read-Host " Press Enter to exit"
84
85
exit 1
85
86
}
86
- Write-Host " $YELLOW [Warning ]$NC Waiting for process closure, attempt $retryCount /$MAX_RETRIES ..."
87
+ Write-Host " $YELLOW [WARN ]$NC Waiting for process to close, trying $retryCount /$MAX_RETRIES ..."
87
88
Start-Sleep - Seconds $WAIT_TIME
88
89
}
89
- Write-Host " $GREEN [Info ]$NC Successfully closed $processName . "
90
+ Write-Host " $GREEN [info ]$NC $processName successfully closed "
90
91
}
91
92
}
92
93
93
94
# Close all Cursor processes
94
95
Close-CursorProcess " Cursor"
95
96
Close-CursorProcess " cursor"
96
97
97
- # Create backup directory
98
+ # Create a backup directory
98
99
if (-not (Test-Path $BACKUP_DIR )) {
99
100
New-Item - ItemType Directory - Path $BACKUP_DIR | Out-Null
100
101
}
101
102
102
- # Backup existing configuration
103
+ # Back up the existing configuration
103
104
if (Test-Path $STORAGE_FILE ) {
104
- Write-Host " $GREEN [Info ]$NC Backing up configuration file ..."
105
+ Write-Host " $GREEN [INFO ]$NC Backing up configuration files ..."
105
106
$backupName = " storage.json.backup_$ ( Get-Date - Format ' yyyyMMdd_HHmmss' ) "
106
107
Copy-Item $STORAGE_FILE " $BACKUP_DIR \$backupName "
107
108
}
108
109
109
- # Generate new ID
110
- Write-Host " $GREEN [Info ]$NC Generating new ID..."
110
+ # Generate a new ID
111
+ Write-Host " $GREEN [INFO ]$NC Generating new ID..."
111
112
113
+ # Function to generate random byte array and convert to hexadecimal string
112
114
function Get-RandomHex {
113
115
param (
114
116
[int ]$length
@@ -121,49 +123,189 @@ function Get-RandomHex {
121
123
}
122
124
123
125
$UUID = [System.Guid ]::NewGuid().ToString()
126
+ # Convert auth0|user_ to hexadecimal byte array
124
127
$prefixBytes = [System.Text.Encoding ]::UTF8.GetBytes(" auth0|user_" )
125
128
$prefixHex = -join ($prefixBytes | ForEach-Object { ' {0:x2}' -f $_ })
129
+ # Generate a 32-byte (64 hexadecimal characters) random number as the random part of machineId
126
130
$randomPart = Get-RandomHex - length 32
127
131
$MACHINE_ID = " $prefixHex$randomPart "
128
132
$MAC_MACHINE_ID = Get-RandomHex - length 32
129
133
$SQM_ID = " {$ ( [System.Guid ]::NewGuid().ToString().ToUpper()) }"
130
134
131
- # Update configuration file
132
- Write-Host " $GREEN [Info ]$NC Updating configuration..."
135
+ # Create or update configuration files
136
+ Write-Host " $GREEN [INFO ]$NC Updating configuration..."
133
137
134
138
try {
139
+ # Make sure the directory exists
135
140
$storageDir = Split-Path $STORAGE_FILE - Parent
136
141
if (-not (Test-Path $storageDir )) {
137
142
New-Item - ItemType Directory - Path $storageDir - Force | Out-Null
138
143
}
139
144
145
+ # Write configuration
140
146
$config = @ {
141
147
' telemetry.machineId' = $MACHINE_ID
142
148
' telemetry.macMachineId' = $MAC_MACHINE_ID
143
149
' telemetry.devDeviceId' = $UUID
144
150
' telemetry.sqmId' = $SQM_ID
145
151
}
146
152
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."
153
+ # Use System.IO.File methods to write to a file
154
+ try {
155
+ $jsonContent = $config | ConvertTo-Json
156
+ [System.IO.File ]::WriteAllText(
157
+ [System.IO.Path ]::GetFullPath($STORAGE_FILE ),
158
+ $jsonContent ,
159
+ [System.Text.Encoding ]::UTF8
160
+ )
161
+ Write-Host " $GREEN [INFO]$NC Successfully wrote configuration file"
162
+ } catch {
163
+ throw " Failed to write file: $_ "
164
+ }
165
+
166
+ # Try setting file permissions
167
+ try {
168
+ # Use the current username and domain name
169
+ $currentUser = [System.Security.Principal.WindowsIdentity ]::GetCurrent()
170
+ $userAccount = " $ ( $env: USERDOMAIN ) \$ ( $env: USERNAME ) "
171
+
172
+ # Create a new access control list
173
+ $acl = New-Object System.Security.AccessControl.FileSecurity
174
+
175
+ # Add full control permissions for the current user
176
+ $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule(
177
+ $userAccount , # Use domain name\user name format
178
+ [System.Security.AccessControl.FileSystemRights ]::FullControl,
179
+ [System.Security.AccessControl.InheritanceFlags ]::None,
180
+ [System.Security.AccessControl.PropagationFlags ]::None,
181
+ [System.Security.AccessControl.AccessControlType ]::Allow
182
+ )
183
+
184
+ try {
185
+ $acl.AddAccessRule ($accessRule )
186
+ Set-Acl - Path $STORAGE_FILE - AclObject $acl - ErrorAction Stop
187
+ Write-Host " $GREEN [INFO]$NC Successfully set file permissions"
188
+ } catch {
189
+ # If the first method fails, try icacls
190
+ Write-Host " $YELLOW [WARNING]$NC Using alternate method to set permissions..."
191
+ $result = Start-Process " icacls.exe" - ArgumentList " `" $STORAGE_FILE `" /grant `" $ ( $env: USERNAME ) :(F)`" " - Wait - NoNewWindow - PassThru
192
+ if ($result.ExitCode -eq 0 ) {
193
+ Write-Host " $GREEN [INFO]$NC Successfully used icacls to set file permissions"
194
+ } else {
195
+ Write-Host " $YELLOW [Warning]$NC Failed to set file permissions, but the file was written successfully"
196
+ }
197
+ }
198
+ } catch {
199
+ Write-Host " $YELLOW [WARNING]$NC Failed to set file permissions: $_ "
200
+ Write-Host " $YELLOW [WARNING]$NC Attempting to use the icacls command..."
201
+ try {
202
+ $result = Start-Process " icacls.exe" - ArgumentList " `" $STORAGE_FILE `" /grant `" $ ( $env: USERNAME ) :(F)`" " - Wait - NoNewWindow - PassThru
203
+ if ($result.ExitCode -eq 0 ) {
204
+ Write-Host " $GREEN [INFO]$NC Successfully used icacls to set file permissions"
205
+ } else {
206
+ Write-Host " $YELLOW [Warning]$NC All permission setting methods failed, but the file was written successfully"
207
+ }
208
+ } catch {
209
+ Write-Host " $YELLOW [WARNING]$NC icacls command failed: $_ "
210
+ }
211
+ }
212
+
154
213
} catch {
155
- Write-Host " $RED [Error]$NC Failed to update configuration: $_ "
156
- Read-Host " Press Enter to exit"
157
- exit 1
214
+ Write-Host " $RED [ERROR]$NC Primary operation failed: $_ "
215
+ Write-Host " $YELLOW [Try]$NC Use alternative method..."
216
+
217
+ try {
218
+ # Alternative method: Use Add-Content
219
+ $tempFile = [System.IO.Path ]::GetTempFileName()
220
+ $config | ConvertTo-Json | Set-Content - Path $tempFile - Encoding UTF8
221
+ Copy-Item - Path $tempFile - Destination $STORAGE_FILE - Force
222
+ Remove-Item - Path $tempFile
223
+ Write-Host " $GREEN [INFO]$NC Successfully wrote configuration using alternative method"
224
+ } catch {
225
+ Write-Host " $RED [ERROR]$NC All attempts failed"
226
+ Write-Host " Error Details: $_ "
227
+ Write-Host " Destination File: $STORAGE_FILE "
228
+ Write-Host " Please make sure you have sufficient permissions to access the file"
229
+ Read-Host " Press Enter to exit"
230
+ exit 1
231
+ }
232
+ }
233
+
234
+ # Display results
235
+ Write-Host " "
236
+ Write-Host " $GREEN [INFO]$NC Updated configuration:"
237
+ Write-Host " $BLUE [debug]$NC machineId:$MACHINE_ID "
238
+ Write-Host " $BLUE [debug]$NC macMachineId:$MAC_MACHINE_ID "
239
+ Write-Host " $BLUE [debug]$NC devDeviceId:$UUID "
240
+ Write-Host " $BLUE [DEBUG]$NC sqmId: $SQM_ID "
241
+
242
+ # Display the file tree structure
243
+ Write-Host " "
244
+ Write-Host " $GREEN [INFO]$NC File Structure:"
245
+ Write-Host " $BLUE$env: APPDATA \Cursor\User$NC "
246
+ Write-Host " ├── globalStorage"
247
+ Write-Host " │ ├── storage.json (modified)"
248
+ Write-Host " │ └── backups"
249
+
250
+ # List backup files
251
+ $backupFiles = Get-ChildItem " $BACKUP_DIR \*" - ErrorAction SilentlyContinue
252
+ if ($backupFiles ) {
253
+ foreach ($file in $backupFiles ) {
254
+ Write-Host " │ └── $ ( $file.Name ) "
255
+ }
256
+ } else {
257
+ Write-Host " │ └── (empty)"
158
258
}
159
259
260
+ # Display public account information
160
261
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 "
262
+ Write-Host " $GREEN ================================$NC "
263
+ Write-Host " $YELLOW Follow the public account [Jianbing Guozijuan AI] to exchange more Cursor skills and AI knowledge $NC "
264
+ Write-Host " $GREEN ================================$NC "
265
+ Write-Host " "
266
+ Write-Host " $GREEN [info]$NC Please restart Cursor to apply the new configuration"
267
+ Write-Host " "
268
+
269
+ # Ask if you want to disable automatic updates
270
+ Write-Host " "
271
+ Write-Host " $YELLOW [Ask]$NC Do you want to disable the automatic update feature of the Cursor?"
272
+ Write-Host " 0) No - Keep default settings (Press Enter)"
273
+ Write-Host " 1) Yes - Disable automatic updates"
274
+ $choice = Read-Host " Please enter an option (1 or press Enter)"
275
+
276
+ if ($choice -eq " 1" ) {
277
+ Write-Host " "
278
+ Write-Host " $GREEN [INFO]$NC Processing automatic updates..."
279
+ $updaterPath = " $env: LOCALAPPDATA \cursor-updater"
280
+
281
+ if (Test-Path $updaterPath ) {
282
+ try {
283
+ # Force delete directory
284
+ Remove-Item - Path $updaterPath - Force - Recurse - ErrorAction Stop
285
+ Write-Host " $GREEN [INFO]$NC Successfully deleted cursor-updater directory"
286
+
287
+ # Create a file with the same name
288
+ New-Item - Path $updaterPath - ItemType File - Force | Out-Null
289
+ Write-Host " $GREEN [INFO]$NC Successfully created block file"
290
+ }
291
+ catch {
292
+ Write-Host " $RED [ERROR]$NC Error processing cursor-updater: $_ "
293
+ }
294
+ }
295
+ else {
296
+ # Create a blocking file directly
297
+ New-Item - Path $updaterPath - ItemType File - Force | Out-Null
298
+ Write-Host " $GREEN [INFO]$NC Successfully created block file"
299
+ }
300
+ }
301
+ elseif ($choice -ne " " ) {
302
+ Write-Host " $YELLOW [info]$NC Keep the default settings and do not change"
303
+ }
304
+ else {
305
+ Write-Host " $YELLOW [info]$NC Keep the default settings and do not change"
306
+ }
307
+
308
+
166
309
167
- Write-Host " $GREEN [Info]$NC Please restart Cursor to apply the new configuration."
168
310
Read-Host " Press Enter to exit"
169
311
exit 0
0 commit comments