|
|
50鱼币
本帖最后由 戴宇轩 于 2015-6-28 18:05 编辑
注册表写入 winreg.HKEY_CLASSES_ROOT 会报错
写入winreg.HKEY_CURRENT_USER就可以。
- #coding = utf-8
- '''
- Created on 2015年5月24日
- author: likui
- '''
- import os
- import winreg
- HKCU = winreg.HKEY_CURRENT_USER
- def modify():
-
- try:
- kdspath = input('请输入kds的目录:')
- #----以下为制版软件注册表修复-----
- knit_cad = os.path.join(kdspath,'运行库\制版模块')
- knit_cad_shell ='"'+os.path.join(knit_cad,'KDS-Pattern.exe')+'" "%1" %*'
-
- # 。kni 注册表项
- dot_kni = winreg.OpenKey(HKCU, '', 0, winreg.KEY_ALL_ACCESS)
- winreg.SetValue(dot_kni, '.kni', winreg.REG_SZ, 'kni document')
-
- # kni document 注册表项
- kni_key=winreg.CreateKey(dot_kni, 'kni document')
- winreg.SetValue(kni_key, 'DefaultIcon', winreg.REG_SZ,os.path.join(knit_cad,'KnitCAD.ICO') )
- kni_shell=winreg.CreateKey(kni_key, 'shell')
- kni_shell_open=winreg.CreateKey(kni_shell,'open')
- winreg.SetValue(kni_shell_open, 'command', winreg.REG_SZ,knit_cad_shell)
-
- #----以下是工艺软件的注册表修复------
- knit_proc = os.path.join(kdspath,'运行库\工艺模块')
- knit_proc_shell ='"'+os.path.join(knit_proc,'KDS-Process.exe')+'" "%1" %*'
-
- # .kds 注册表项
- dot_kds =winreg.OpenKey(HKCU, '', 0, winreg.KEY_ALL_ACCESS)
- winreg.SetValue(dot_kni, '.kds', winreg.REG_SZ, 'kds document')
-
- # kds document 注册表项
- kds_key=winreg.CreateKey(dot_kds, 'kds document')
- winreg.SetValue(kds_key, 'DefaultIcon', winreg.REG_SZ,os.path.join(knit_cad,'Process.ICO') )
- kds_shell=winreg.CreateKey(kds_key, 'shell')
- kds_shell_open=winreg.CreateKey(kds_shell,'open')
- winreg.SetValue(kds_shell_open, 'command', winreg.REG_SZ,knit_proc_shell)
-
- except WindowsError:
- print('error')
-
-
- if __name__ =='__main__':
- modify()
复制代码
|
|