Python可以使用winreg模块来修改Windows注册表信息。以下是一个示例代码,可以将当前用户的桌面路径修改为指定路径:
import winreg # 打开注册表 key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', 0, winreg.KEY_WRITE) # 修改桌面路径 new_path = r'C:\Users\username\NewDesktop' winreg.SetValueEx(key, 'Desktop', 0, winreg.REG_SZ, new_path) # 关闭注册表 winreg.CloseKey(key) print('桌面路径已修改为:', new_path)
在该示例中,我们使用winreg模块打开了HKEY_CURRENT_USER下的Shell Folders键,并将其打开方式设置为可写入。然后,我们使用SetValueEx函数将Desktop值的数据修改为指定路径。最后,我们关闭了注册表并打印了修改后的桌面路径。文章源自爱尚资源教程网-https://www.23jcw.net/6399.html 文章源自爱尚资源教程网-https://www.23jcw.net/6399.html
相关文章
版权声明:文章图片资源来源于网络,如有侵权,请留言删除!!!