现在工作电脑是Ubuntu14.04的,平常使用的数据库客户端工具是navicat(不喜欢mysql workbench),但navicat是一款商业软件,premium版在安装14天后就无法使用了,将个人目录下的.navicat目录删掉才行(网上也有人说将.navicat目录下的system.reg删掉即可,我试过不行),但一些配置信息也会一同删掉,得重新配置,不胜其烦,决定试试看能不能修改navicat的过期时间。
进入.navicat目录,逐步查看,编辑和删除system.reg, user.reg, userdef.reg,最终将目标锁定在user.reg文件,下面一段代码记录了时间信息。
[Software\\Classes\\CLSID\\{34333022-E79C-57CB-721A-AC00E0CF8464}\\Info] 1437704549 "3433"="CE" [Software\\Classes\\CLSID\\{4B436C50-3D26-316A-ADF7-0D0ABE54702D}\\Info] 1437704549 "4B43"="88" [Software\\Classes\\CLSID\\{6F154612-5C6D-8BA8-3B84-6C8A1AB59144}\\Info] 1437704549 "6F15"="D3" [Software\\Classes\\CLSID\\{746E91AB-0CD9-7ACD-EA69-DB12798BFDA2}\\Info] 1437704549 "746E"="" [Software\\Classes\\CLSID\\{7EDC6314-1F7D-6E46-04EE-4733B89DE9FB}\\Info] 1437704549 "7EDC"="EB" [Software\\Classes\\CLSID\\{987C4F4A-4DE6-82AE-1735-6A414C7DDE35}\\Info] 1437704549 "987C"="" [Software\\Classes\\CLSID\\{D84DDFBD-0FCF-9793-B20E-59220F8DBCC7}\\Info] 1437704549 "D84D"="FF" [Software\\Classes\\CLSID\\{DCB766E2-1DD6-B071-F5F1-DAD7DEB25281}\\Info] 1437704549 "DCB7"="FF" [Software\\Classes\\CLSID\\{F39D6149-C8C8-9DA7-6C2B-764E443E0BF4}\\Info] 1437704549 "F39D"="D1" [Software\\Classes\\CLSID\\{FD9023CC-F5C6-DDD1-8986-C51B9A3B3957}\\Info] 1437704549 "FD90"="3D"
提取了两个例子,如下:
"3433"="8F" "4B43"="C8" "6F15"="41" "746E"="" "7EDC"="BF" "987C"="" "D84D"="38" "DCB7"="80" "F39D"="BF" "FD90"="4D" 安装时间:2015-07-24(1437667200,十六进制:0X55B10F80) 过期时间:2015-08-07(1438876800,十六进制:0X55C38480) "3433"="CE" "4B43"="88" "6F15"="D3" "746E"="" "7EDC"="EB" "987C"="" "D84D"="5B" "DCB7"="FF" "F39D"="D1" "FD90"="3D" 安装时间:2015-07-20(1437321600,十六进制:0X55ABC980) 过期时间:2015-08-03(1438531200,十六进制:0X55BE3E80)
貌似需要花点时间从上面的例子中找出过期日期的逻辑,先记录下来等以后再处理。
临时的做法:写了个python脚本,先重命名原本的user.reg,启动navicat再关闭,将新生成的user.reg中关于日期的代码复制出来替换到旧文件,旧文件再覆盖新文件即可。重新启动navicat,可以发现过期时间会是当前的14天后。代码如下:
#!/usr/bin/env python # encoding: utf-8 import subprocess, time, re, os def main(): new_file = "/path/to/.navicat/user.reg" bak_file = "/path/to/.navicat/user.reg.bak" if os.path.isfile(new_file): os.rename(new_file, bak_file) #os.remove(new_filed) pid = get_navicat_pid() if pid > 0 and kill_navicat(pid): time.sleep(3) if os.path.isfile(new_file) and os.path.isfile(bak_file): new = open(new_file, "r") old = open(bak_file, "r") new_data = new.read() old_data = old.read() new.close() old.close() p_list = ['"3433"=".*"', '"4B43"=".*"', '"6F15"=".*"', '"7EDC"=".*"', '"D84D"=".*"', '"DCB7"=".*"', '"F39D"=".*"', '"FD90"=".*"'] for p in p_list: res = re.findall(p, new_data) if len(res) > 0: old_data = re.sub(p, res[0], old_data) new = open(new_file, "w") new.write(old_data) new.close() # 获取navicat进程pid def get_navicat_pid(flag=False): start_cmd = "/path/to/navicat" command = "ps -ef|grep -v grep|grep /path/to/navicat111_premium_cs/Navicat/Navicat.exe|awk '{print $2}'" sub = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) out, err = sub.communicate() pid = 0 if err is None and len(out)>0: pattern = re.compile(r"\s*") out_list = pattern.split(out.strip()) if 1 == len(out_list) and out_list[0].isdigit(): pid = int(out_list[0]) elif flag is False: sub = subprocess.Popen(start_cmd, shell=True, stdout=open("/dev/null", "w"), stderr=subprocess.STDOUT) out, err = sub.communicate() time.sleep(5) return get_navicat_pid(flag=True) return pid # 结束navicat进程 def kill_navicat(pid): cmd = "kill "+str(pid) sub = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) out, err = sub.communicate() return True if err is None else False if __name__ == "__main__": main()