Private Const PLATFORM_ID_DOS = 300
Private Const PLATFORM_ID_OS2 = 400
Private Const PLATFORM_ID_NT = 500
Private Const PLATFORM_ID_OSF = 600
Private Const PLATFORM_ID_VMS = 700
Private Type WKSTA_INFO_102
wki100_platform_id As Long
pwki100_computername As Long
pwki100_langroup As Long
wki100_ver_major As Long
End Type
Private Declare Function NetWkstaGetInfo Lib "netapi32" (ByVal servername As String, ByVal level As Long, lpBuf As Any) As Long
Private Declare Function GetEnvironmentVariable Lib "kernel32" Alias "GetEnvironmentVariableA" (ByVal lpName As String, ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)
Private Function StripTerminator(sInput As String) As String
Dim ZeroPos As Integer
ZeroPos = InStr(1, sInput, vbNullChar)
If ZeroPos > 0 Then
StripTerminator = Left$(sInput, ZeroPos - 1)
Else
StripTerminator = sInput
End If
End Function
Function GetEnvironmentVar(sName As String) As String
GetEnvironmentVar = String(255, 0)
GetEnvironmentVariable sName, GetEnvironmentVar, Len(GetEnvironmentVar)
If InStr(1, GetEnvironmentVar, Chr$(0)) > 0 Then GetEnvironmentVar = Left$(GetEnvironmentVar, InStr(1, GetEnvironmentVar, Chr$(0)) - 1)
GetEnvironmentVar = GetEnvironmentVar
End Function
Private Sub Form_Load()
Dim pWrkInfo As Long, WrkInfo(0) As WKSTA_INFO_102, lResult As Long
MsgBox "Usuario de Dominio: " & GetEnvironmentVar("UserDomain")
lResult = NetWkstaGetInfo(StrConv("\\" & GetEnvironmentVar("UserDomain"), vbUnicode), 102, pWrkInfo)
If lResult = 0 Then
Dim cname As String
cname = String$(255, 0)
CopyMemory WrkInfo(0), ByVal pWrkInfo, ByVal Len(WrkInfo(0))
CopyMemory ByVal cname, ByVal WrkInfo(0).pwki100_langroup, ByVal 255
MsgBox "Dominio: " & StripTerminator(StrConv(cname, vbFromUnicode))
Select Case WrkInfo(0).wki100_platform_id
Case PLATFORM_ID_DOS: MsgBox "Sistema Operativo: " & "DOS"
Case PLATFORM_ID_OS2:
If WrkInfo(0).wki100_ver_major = "4" Then
MsgBox "Sistema Operativo: " & "Win9x"
Else
MsgBox "Sistema Operativo: " & "OS2"
End If
Case PLATFORM_ID_NT:
If WrkInfo(0).wki100_ver_major = "5" Then
MsgBox "Sistema Operativo: " & "Win 2000"
Else
MsgBox "Sistema Operativo: " & "Win NT"
End If
Case PLATFORM_ID_OSF: MsgBox "Sistema Operativo: " & "OSF"
Case PLATFORM_ID_VMS: MsgBox "Sistema Operativo: " & "VMS"
End Select
End If
End Sub