import ctypes import os from win32com.client import Dispatch def regsvr(): dm_path = os.path.abspath(os.path.dirname(__file__)) + "/3.1233" try: dm_1 = Dispatch('dm.dmsoft') except Exception: os.system(r'regsvr32 /s %sdm.dll' % dm_path) dm_1 = Dispatch('dm.dmsoft') return dm_1 #免注册方式 def noregsvr(): dm_path = os.path.abspath(os.path.dirname(__file__)) + "/3.1233" dms = ctypes.windll.LoadLibrary(r'%sDmReg.dll' % dm_path) dms.SetDllPathW(r'%sdm.dll' % dm_path, 0) return Dispatch('dm.dmsoft') dm = noregsvr() #dm = regsvr() print(dm.ver())