قطعه کدی که خود من درگذشته توی یکی از برنامه هام برای بررسی نسخه ویندوز به منظور برقراری ارتباط شبکه بکار بردم(ویژوال بیسیک):
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "INF"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type
Dim Buffer As String
Function AccountName()
Buffer = String(255, 0)
GetUserName Buffer, 255
Buffer = Left$(Buffer, InStr(Buffer, Chr$(0)) - 1)
AccountName = Buffer
End Function
Function PcName()
Buffer = String(255, 0)
GetComputerName Buffer, 255
PcName = Left$(Buffer, InStr(1, Buffer, Chr$(0)) - 1)
End Function
Function VersionWindows()
Dim Info As OSVERSIONINFO, strOs As String
Dim Retval As Long, Result As String
Info.dwOSVersionInfoSize = Len(Info)
Retval = GetVersionEx(Info)
Select Case Info.dwPlatformId
Case 0
strOs = "Windows 3.x"
Case 1
If (Info.dwMinorVersion = 0) Then
strOs = "Windows 95"
End If
If (Info.dwMinorVersion = 10) Then
strOs = "Windows 98"
End If
If (Info.dwMinorVersion = 90) Then
strOs = "Windows ME"
End If
Case 2
If (Info.dwMajorVersion < 5) Then
strOs = "Windows NT"
End If
If (Info.dwMajorVersion = 5 And Info.dwMinorVersion = 0) Then
strOs = "Windows 2K"
End If
If (Info.dwMajorVersion = 5 And Info.dwMinorVersion = 1) Then
strOs = "Windows XP"
End If
If (Info.dwMajorVersion = 6) Then
strOs = "Windows 7"
End If
End Select
VersionWindows = strOs
End Function