Og for andre vindows versjoner kan du bruke dette utklippet (fra vbcode
magician)
This tip will show you how to identify the type of OS
(Windows95/98/ME/NT/2000) and any installed service pack information.
If also shows how to retrieve the version info string (Major, Minor and
Build info).
To try this sample start a new project and add a module to the project
(Module1). To the form (Form1) add to labels (named Label1 and Label2)
plus a Button (Button1). Then add this code.
Add this code to a Module:
Option Explicit
Public Declare Function GetVersionEx Lib "kernel32" Alias _
"GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
Public Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128 ' Maintenance string for PSS usage
End Type
' dwPlatforID Constants
Public Const VER_PLATFORM_WIN32s = 0
Public Const VER_PLATFORM_WIN32_WINDOWS = 1
Public Const VER_PLATFORM_WIN32_NT = 2
'-- End --'
Add this code to a form:
Private Sub Form_Load()
Dim tOSVer As OSVERSIONINFO
' First set length of OSVERSIONINFO
' structure size
tOSVer.dwOSVersionInfoSize = Len(tOSVer)
' Get version information
GetVersionEx tOSVer
' Determine OS type
With tOSVer
Select Case .dwPlatformId
Case VER_PLATFORM_WIN32_NT
' This is an NT version (NT/2000)
' If dwMajorVersion >= 5 then
' the OS is Win2000
If .dwMajorVersion >= 5 Then
Label1.Caption = "Windows 2000"
Else
Label1.Caption = "Windows NT"
End If
Case Else
' This is Windows 95/98/ME
If .dwMajorVersion >= 5 Then
Label1.Caption = "Windows ME"
ElseIf .dwMajorVersion = 4 And .dwMinorVersion > 0 Then
Label1.Caption = "Windows 98"
Else
Label1.Caption = "Windows 95"
End If
End Select
' Check for service pack
Label1.Caption = Label1.Caption & " " & Left(.szCSDVersion, _
InStr(1, .szCSDVersion, Chr$(0)))
' Get OS version
Label2.Caption = "Version: " & .dwMajorVersion & "." & _
.dwMinorVersion & "." & .dwBuildNumber
End With
End Sub
Private Sub Command1_Click()
Unload Me
End Sub
'-- End --'
Run the application by pressing F5. Label1 will hold OS type and
service pack info. Label2 will hold the version string.
In article <Pc0c6.1080$jQ1.16802@news1.oke.nextra.no>,
"Helge Bjørkhaug" <snutten@techie.online.no> wrote:
> "Casper Clausen" <casperc@get2net.dk> wrote in message
> news:DiWb6.181$_N1.9204@news.get2net.dk...
> > En API version den kune jeg da også godt tænke mig at se
> >
> [snip]
>
> Putt dette i en Module og sett "Startup Object" til "Sub Main"
i "Project Properties";
> Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA"
(lpVersionInformation As
> OSVERSIONINFO) As Long
> Type OSVERSIONINFO
> dwOSVersionInfoSize As Long
> dwMajorVersion As Long
> dwMinorVersion As Long
> dwBuildNumber As Long
> dwPlatformId As Long
> szCSDVersion As String * 128
> End Type
> Sub Main()
> Dim OSInfo As OSVERSIONINFO, PId As String, Ret as Long
> OSInfo.dwOSVersionInfoSize = Len(OSInfo)
> Ret = GetVersionEx(OSInfo)
> If Ret = 0 Then MsgBox "Error Getting Version Information": Exit
Sub
> If OSInfo.dwPlatformId = 2 And OSInfo.dwMajorVersion = 5 Then
> MsgBox "Programmet er ikke testet ut under WIN2000!!!"
> End
> Else
> MsgBox "Start Default Form her, f.eks Form1.Show"
> End If
> End Sub
>
> Mvh,
>
> Snutten
>
>
Sent via Deja.com
http://www.deja.com/