from ctypes import * ''' C原型 typedef struct _OSVERSIONINFO { DWORD dwOSVersionInfoSize; DWORD dwMajorVersion; DWORD dwMinorVersion; DWORD dwBuildNumber; DWORD dwPlatformId; TCHAR szCSDVersion[128]; } OSVERSIONINFO; ''' # 转到Python class OSINFO(Structure): _fields_ = [ ("dwOSVersionInfoSize", c_long), ("dwMajorVersion", c_long), ("dwMinorVersion", c_long), ("dwBuildNumber", c_long), ("dwPlatformId", c_long), ("szCSDVersion", c_char*128) # 注意数组处理 ] def GetSystemVersion(): kernel32 = windll.kernel32 #windll.LoadLibrary("kernel32.dll") os = OSINFO() os.dwOSVersionInfoSize = sizeof(os) # 下面就按照C++一样的流程调用即可 if kernel32.GetVersionExA(byref(os)) == 0: return "Null Version" if os.dwPlatformId == 1: # windows 95/98/me if os.dwMajorVersion == 4 and os.dwMinorVersion == 0: verStr = "windows 95" elif os.dwMajorVersion == 4 and os.dwMinorVersion == 10: verStr = "windows 98" elif os.dwMajorVersion == 4 and os.dwMinorVersion == 90: verStr = "windows me" else: verStr = "unknown version" # windows vista/server 2008/server 2003/xp/2000/nt elif os.dwPlatformId == 2: if os.dwMajorVersion == 4 and os.dwMinorVersion == 0: verStr = "windows nt 4.0" elif os.dwMajorVersion == 5 and os.dwMinorVersion == 0: verStr = "windows 2000" elif os.dwMajorVersion == 5 and os.dwMinorVersion == 1: verStr = "windows xp" elif os.dwMajorVersion == 5 and os.dwMinorVersion == 2: verStr = "windows 2003" elif os.dwMajorVersion == 6 and os.dwMinorVersion == 0: verStr = "windows vista" # or 2008 elif os.dwMajorVersion >= 0: verStr = "windows 7" else: verStr = "unknown version" else: return "unknown Version" return verStr + " build" + str(os.dwBuildNumber) + " " + string_at(os.szCSDVersion) def MessageBox_Test(): MessageBox = windll.user32.MessageBoxW MessageBox(None, u'http://www.dllhook.com!', u'优雅人生', 0) if __name__ == '__main__': print(GetSystemVersion())
发表评论