devxlogo

Determining the OS using API

Determining the OS using API

Question:
Is it possible to use API to determine the OS of a system without resorting to SysInfo control?

Answer:
Sure. Just call the GetVersionEx API. Add the following to your Declarations section:

Private Declare Function GetVersionEx Lib "kernel32" _   Alias "GetVersionExA" (lpVersionInformation _   As OSVERSIONINFO) As LongPrivate Type OSVERSIONINFO   dwOSVersionInfoSize As Long   dwMajorVersion As Long   dwMinorVersion As Long   dwBuildNumber As Long   dwPlatformId As Long   szCSDVersion As String * 128End TypePrivate Const VER_PLATFORM_WIN32s = 0Private Const VER_PLATFORM_WIN32_WINDOWS = 1Private Const VER_PLATFORM_WIN32_NT = 2

Then, to make the call, declare an instance of the OSVERSIONINFO type, fill out its length member, and pass it to GetWindowEx:

   Dim os As OSVERSIONINFO   os.dwOSVersionInfoSize = Len(os)   Call GetVersionEx(os)
See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist