如何更改设备的设备码

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
import os
import json
import uuid
from datetime import datetime
import shutil
 
"""
    请以管理员身份运行 PowerShell,并执行以下命令:
    python change_machine_id.py
"""
 
# 配置文件路径,适配 Windows 的路径格式
# storage_file = os.path.expanduser(r"~\AppData\Local\Cursor\User\globalStorage\storage.json")
# win11 专用
storage_file = os.path.expanduser(r"C:\Users\Administrator\AppData\Roaming\Cursor\User\globalStorage\storage.json")
 
# 生成随机 ID
def generate_random_id():
    return uuid.uuid4().hex
 
# 获取新的 ID(从命令行参数或自动生成)
def get_new_id():
    import sys
    return sys.argv[1] if len(sys.argv) > 1 else generate_random_id()
 
# 创建备份
def backup_file(file_path):
    if os.path.exists(file_path):
        backup_path = f"{file_path}.backup_{datetime.now().strftime('%Y%m%d_%H%M%S')}"
        shutil.copy(file_path, backup_path)
        print(f"已创建备份文件: {backup_path}")
    else:
        print("未找到需要备份的文件,跳过备份步骤。")
 
# 更新或创建 JSON 文件
def update_machine_id(file_path, new_id):
    # 确保目录存在
    os.makedirs(os.path.dirname(file_path), exist_ok=True)
 
    # 如果文件不存在,创建一个空的 JSON 文件
    if not os.path.exists(file_path):
        with open(file_path, "w", encoding="utf-8") as f:
            json.dump({}, f)
 
    # 读取 JSON 数据
    with open(file_path, "r", encoding="utf-8") as f:
        try:
            data = json.load(f)
        except json.JSONDecodeError:
            data = {}
 
    # 更新或添加 machineId
    data["telemetry.machineId"] = new_id
 
    # 写回更新后的 JSON 文件
    with open(file_path, "w", encoding="utf-8") as f:
        json.dump(data, f, indent=4, ensure_ascii=False)
 
    print(f"已成功修改 machineId 为: {new_id}")
 
# 主函数
if __name__ == "__main__":
    new_id = get_new_id()
 
    # 创建备份
    backup_file(storage_file)
 
    # 更新 JSON 文件
    update_machine_id(storage_file, new_id)

python 版本 3.8以上 

管理员身份打开pycharm 然后运行代码 就可以了

Geek Uninstaller - 最好的免费卸载程序

需要使用这个工具 将Cursor彻底删除,再次重新下载,就可以实现使用Cursor了

 

posted @   财神给你送元宝  阅读(51)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示