Leon_ писал(а):Нашел -- так поделись, мне тоже интересно![]()
Или убери топик -- зачем форум засорять пустыми темами?
Option Explicit
Private Type WKSTA_INFO_102
wki100_platform_id As Long
pwki100_computername As Long
pwki100_langroup As Long
wki100_ver_major As Long
wki100_ver_minor As Long
pwki102_lanroot As Long
wki102_logged_on_users As Long
End Type
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function NetWkstaGetInfo Lib "netapi32" (ByVal Servername As String, ByVal Level As Long, lpBuf As Any) As Long
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function GetHostByName Lib "wsock32.dll" Alias "gethostbyname" (ByVal HostName As String) As Long
Private Function Pointer2StringW(ByVal Address As Long) As String
Dim Buffer() As Byte, Count As Long
Count = lstrlenW(Address) * 2
If Count Then
ReDim Buffer(0 To (Count - 1)) As Byte
CopyMemory Buffer(0), ByVal Address, Count
Pointer2StringW = Buffer
End If
End Function
Private Function Get_Name() As String
Dim dwLen As Long, strString As String
dwLen = 32
strString = String(dwLen, "X")
GetComputerName strString, dwLen
strString = Left(strString, dwLen)
Get_Name = strString
End Function
Private Function Get_Domain() As String
Dim pWrkInfo As Long, WrkInfo(0) As WKSTA_INFO_102, lResult As Long
Dim strComputername As String
strComputername = Get_Name
lResult = NetWkstaGetInfo(StrConv("\\" & strComputername, 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
Get_Domain = StripTerminator(StrConv(cname, vbFromUnicode))
End If
End Function
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 Function
Private Sub Form_Load()
MsgBox Get_Domain
End Sub
Declare Function NetWkstaGetInfo Lib "NetAPI.DLL" _
(ByVal lServer As Long, ByVal sLevel As Integer, _
ByVal pbBuffer As Long, ByVal cbBuffer As Integer, _
pcbTotalAvail As Integer) As Integer
API-Guide писал(а):NetWkstaGetInfo
Requires Windows NT 3.1 or later; Win9x/ME: Not supported
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 1