[Go]python using ctypes module call WINDOWSAPI get System version

Source: Internet
Author: User

#Coding:utf-8ImportWin32uiImportWin32guiImportWin32conImportWin32API#https://mail.python.org/pipermail/python-win32/2009-April/009078.html" "ico_x = Win32API. GetSystemMetrics (Win32con. Sm_cxicon) ico_y = Win32API. GetSystemMetrics (Win32con. Sm_cyicon) Large, small = Win32gui. Extracticonex ("F:\\nginx\\nginx-1.13.0\\nginx.exe", 0) Win32gui. DestroyIcon (large[0]) hdc = Win32ui. Createdcfromhandle (Win32gui. GetDC (0)) hbmp = Win32ui. CreateBitmap () hbmp. CreateCompatibleBitmap (hdc, ico_x, ico_x) HDC = hdc. CreateCompatibleDC () hdc. SelectObject (hbmp) hdc. DrawIcon ((0,0), small[0]) hbmp. Savebitmapfile (hdc, "Save.bmp") print (large) print (small)" ""judging the current system version by invoking the window API"#demonstrates calling Windows API functions through cTYPES.#The author already knows that PYTHON32 can achieve the same function#a semicolon at the end of a statement is purely personal.#only partial version judgment, more detailed version judging recommendation system OSVERSIONINFOEX structure Importctypes;classOSINFO (ctypes. Structure): _fields_= [        ("dwOSVersionInfoSize", Ctypes.c_long), ("dwMajorVersion", Ctypes.c_long), ("dwMinorVersion", Ctypes.c_long), ("dwBuildNumber", Ctypes.c_long), ("dwPlatformId", Ctypes.c_long), ("szCSDVersion", ctypes.c_char*128)    ]; defgetsystemversionstring (): Kernel32= Ctypes.windll.LoadLibrary ("Kernel32.dll"); OS=OSINFO (); Os.dwosversioninfosize=ctypes.sizeof (OS); ifKernel32. GetVersionExA (Ctypes.byref (OS)) = =0:return "Null Version"; ifOs.dwplatformid==1:#Windows 95/98/me        ifOs.dwmajorversion==4 andos.dwminorversion==0:verstr="Windows"; elifOs.dwmajorversion==4 andos.dwminorversion==10: Verstr="Windows 98"; elifOs.dwmajorversion==4 andOs.dwminorversion==90: Verstr="Windows Me"; Else: Verstr="Unknown version"; elifos.dwplatformid==2:#Windows Vista/server 2008/server 2003/xp/2000/nt        ifOs.dwmajorversion==4 andos.dwminorversion==0:verstr="Windows NT 4.0"; elifOs.dwmajorversion==5 andos.dwminorversion==0:verstr="Windows $"; elifOs.dwmajorversion==5 andOs.dwminorversion==1: Verstr="Windows XP"; elifOs.dwmajorversion==5 andos.dwminorversion==2: Verstr="Windows 2003"; elifOs.dwmajorversion==6 andos.dwminorversion==0:verstr="Windows Vista";#or        elifos.dwmajorversion>=0:verstr="Windows 7"; Else: Verstr="Unknown version"; Else:        return "Unknown Version"; returnverstr+"Build"+str (Os.dwbuildnumber) +" "+Str (CTYPES.STRING_AT (os.szcsdversion))if __name__=="__main__":    Print(Getsystemversionstring ())

https://www.oschina.net/code/snippet_157181_13215

[Go]python using ctypes module call WINDOWSAPI get System version

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.