Windowsのバージョンを取得する
以下のWindowsVersion関数を使うとWindowsのバージョンを「Windows XP」のような文字列で取得することができる。目下のところWindows3.1より前のバージョンと、Windows Vista以降のバージョンは正しく判別できない。
Private Declare Function GetVersionEx
Lib "kernel32" Alias
"GetVersionExA" (VersionInfo As
OSVERSIONINFO)
As Boolean Private Type OSVERSIONINFO dwOSVersionInfoSize As Long 'この構造体のサイズ dwMajorVersion As Long 'メジャーバージョン dwMinorVersion As Long 'マイナーバージョン dwBuildNumber As Long 'ビルド番号 dwPlatformId As Long '3.1系、95系、NT系の区別 szCSDVersion(127) As Byte 'ServicePack情報など(Unicode文字列の配列) End Type |
'■WindowsVersion '■機能:Windowsのバージョンを返す。 '■戻り値:Winodwsのバージョン名を表す文字列。例:"Window 98" Public Function WindowsVersion() As String
Dim VersionInfo
As OSVERSIONINFO
'●API関数の呼び出し
'●どのWindowsか判定 WindowsID = .dwPlatformId & Format(.dwMajorVersion, "00") & Format(.dwMinorVersion, "0000")
Select Case WindowsID End With End Function |
→Environment.OSVersionを使用します。簡単に判別するにはEnvironment.OSVersion.ToStringとします。