Использую эту функцию для получения массива Ap(cnt,2):
- списка компов в сети Ap(cnt,0)
- списка платформ на этих компах Ap(cnt,1)
- в Ap(cnt,2) хочу вставить тип запущенной на компах ОС, т.е. роль компа в сети.
С первыми двумя задачами все ок, разобрался.
Вопрос по третьей: как? В варианте ниже, в строку массива Ap(cnt,2) попадают числовые значения. Например, для
W2000 - 69635
SQL Server 2000 - 33723379
Win XP - 70147 или 4611 или тот же 69635, что и для W2000
короче, никакой жесткой закономерности. А хочется туда вставить конкретные строки. Вариант Ap(cnt,2) = GetPointerToByteStringW(se101.sv101_type) не прокатывает ...
Конечно, можно вызывать NetServerEnum c конкретным параметром dwServertype несколько раз подряд. Но как-то это не красиво. Вот полный текст модуля для A97:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
Option Compare Database
Option Explicit
'This code will only work on NT3.1 and up and XP...not 9x or ME
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996 -2004 VBnet, Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Windows type used to call the Net API
Public Const MAX_PREFERRED_LENGTH As Long = -1
Public Const NERR_SUCCESS As Long = 0&
Public Const ERROR_MORE_DATA As Long = 234&
Private Const SV_TYPE_WORKSTATION As Long = &H1 'LAN Manager workstations
Private Const SV_TYPE_SERVER As Long = &H2 'LAN Manager servers
Private Const SV_TYPE_SQLSERVER As Long = &H4
Private Const SV_TYPE_DOMAIN_CTRL As Long = &H8
Private Const SV_TYPE_DOMAIN_BAKCTRL As Long = &H10
Private Const SV_TYPE_TIME_SOURCE As Long = &H20
Private Const SV_TYPE_AFP As Long = &H40
Private Const SV_TYPE_NOVELL As Long = &H80
Private Const SV_TYPE_DOMAIN_MEMBER As Long = &H100
Private Const SV_TYPE_PRINTQ_SERVER As Long = &H200
Private Const SV_TYPE_DIALIN_SERVER As Long = &H400
Private Const SV_TYPE_XENIX_SERVER As Long = &H800
Private Const SV_TYPE_SERVER_UNIX As Long = SV_TYPE_XENIX_SERVER 'Servers running Unix
Private Const SV_TYPE_NT As Long = &H1000 'NT/2000 workstations or servers
Private Const SV_TYPE_WFW As Long = &H2000 'Servers running Windows for Workgroups
Private Const SV_TYPE_SERVER_MFPN As Long = &H4000
Private Const SV_TYPE_SERVER_NT As Long = &H8000 'NT/2000 servers not domain controller
Private Const SV_TYPE_POTENTIAL_BROWSER As Long = &H10000
Private Const SV_TYPE_BACKUP_BROWSER As Long = &H20000
Private Const SV_TYPE_MASTER_BROWSER As Long = &H40000
Private Const SV_TYPE_DOMAIN_MASTER As Long = &H80000
Private Const SV_TYPE_SERVER_OSF As Long = &H100000
Private Const SV_TYPE_SERVER_VMS As Long = &H200000
Private Const SV_TYPE_WINDOWS As Long = &H400000 'Windows 95 or later
Private Const SV_TYPE_DFS As Long = &H800000 'Root of a DFS tree
Private Const SV_TYPE_CLUSTER_NT As Long = &H1000000 'NT Cluster
Private Const SV_TYPE_TERMINALSERVER As Long = &H2000000 'Terminal Server
Private Const SV_TYPE_DCE As Long = &H10000000 'IBM DSS
Private Const SV_TYPE_ALTERNATE_XPORT As Long = &H20000000 'return alternate transport
Private Const SV_TYPE_LOCAL_LIST_ONLY As Long = &H40000000 'return local only (Servers maintained by the browser)
Private Const SV_TYPE_DOMAIN_ENUM As Long = &H80000000 'Primary Domain (ignore version info)
Private Const SV_TYPE_ALL As Long = &HFFFFFFFF 'All servers
Private Const SV_PLATFORM_ID_OS2 As Long = 400
Private Const SV_PLATFORM_ID_NT As Long = 500
Private Const PLATFORM_ID_DOS As Long = 300
Private Const PLATFORM_ID_OS2 As Long = 400
Private Const PLATFORM_ID_NT As Long = 500
Private Const PLATFORM_ID_OSF As Long = 600
Private Const PLATFORM_ID_VMS As Long = 700
'Mask applied to svX_version_major in order to obtain the major version number
Public Const MAJOR_VERSION_MASK As Long = &HF
Public Type SERVER_INFO_101
sv101_platform_id As Long
sv101_name As Long
sv101_version_major As Long
sv101_version_minor As Long
sv101_type As Long
sv101_comment As Long
End Type
Public Declare Function NetServerEnum Lib "netapi32" (ByVal servername As Long, ByVal level As Long, _
buf As Any, ByVal prefmaxlen As Long, entriesread As Long, totalentries As Long, ByVal servertype As Long, ByVal domain As Long, resume_handle As Long) As Long
Public Declare Function NetApiBufferFree Lib "netapi32" (ByVal Buffer As Long) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pTo As Any, uFrom As Any, ByVal lSize As Long)
Private Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long
Public Ap() As String 'Массив имен компьютеров в сети и ОС на них
Function GetServers(sDomain As String) As Long
'Lists all servers of the specified type that are visible in a domain.
Dim bufptr As Long
Dim dwEntriesread As Long
Dim dwTotalentries As Long
Dim dwResumehandle As Long
Dim dwServertype As Long
Dim se101 As SERVER_INFO_101
Dim success As Long
Dim nStructSize As Long
Dim cnt As Long
nStructSize = LenB(se101)
dwServertype = SV_TYPE_ALL
'Call passing MAX_PREFERRED_LENGTH to have the API allocate required memory for the return values.
'The call is enumerating all machines on the network (SV_TYPE_ALL); however, by Or'ing specific bit masks for defined
'types you can customize the returned data. For example, a value of 0x00000003 combines the bit masks for
'SV_TYPE_WORKSTATION (0x00000001) and SV_TYPE_SERVER (0x00000002).
'dwServerName must be Null. The level parameter (101 here) specifies the data structure being
'used (in this case a SERVER_INFO_101 structure).
'The domain member is passed as Null, indicating machines on the primary domain are to be retrieved.
'If you decide to use this member, pass StrPtr( "domain name" ), not the string itself.
success = NetServerEnum (0 &, 101 , bufptr, MAX_PREFERRED_LENGTH, dwEntriesread, dwTotalentries, dwServertype, 0 &, dwResumehandle)
If success = NERR_SUCCESS And success <> ERROR_MORE_DATA Then 'if all goes well
ReDim Ap(dwEntriesread - 1, 2)
For cnt = 0 To dwEntriesread - 1 'loop through the returned data, adding each machine to the list
'get one chunk of data and cast into an SERVER_INFO_101 struct in order to add the name to a list
CopyMemory se101, ByVal bufptr + (nStructSize * cnt), nStructSize
Ap(cnt, 0) = GetPointerToByteStringW(se101.sv101_name)
If GetPlatformString(se101.sv101_platform_id) = "Win NT" Then
Select Case (se101.sv101_version_major And MAJOR_VERSION_MASK) & "." & se101.sv101_version_minor
Case "4.0"
Ap(cnt, 1) = "Win NT"
Case "5.0"
Ap(cnt, 1) = "Win 2000"
Case "5.1"
Ap(cnt, 1) = "Win XP"
Case Else
Ap(cnt, 1) = "Win NT ?"
End Select
Else
Ap(cnt, 1) = GetPlatformString(se101.sv101_platform_id) & " " & (se101.sv101_version_major And MAJOR_VERSION_MASK) & "." & se101.sv101_version_minor
End If
Ap(cnt, 2) = Nz(se101.sv101_type, vbNullString)
Next
End If
'Clean up, regardless of success
Call NetApiBufferFree(bufptr)
GetServers = dwEntriesread
End Function
Private Function GetPlatformString(ByVal dwPlatformID As Long) As String
Select Case dwPlatformID
Case PLATFORM_ID_DOS: GetPlatformString = "DOS"
Case PLATFORM_ID_OS2: GetPlatformString = "Win"
Case PLATFORM_ID_NT: GetPlatformString = "Win NT"
Case PLATFORM_ID_OSF: GetPlatformString = "OSF"
Case PLATFORM_ID_VMS: GetPlatformString = "VMS"
End Select
End Function
Public Function GetPointerToByteStringW(ByVal dwData As Long) As String
Dim tmp() As Byte
Dim tmplen As Long
If dwData <> 0 Then
tmplen = lstrlenW(dwData) * 2
If tmplen <> 0 Then
ReDim tmp (0 To (tmplen - 1 )) As Byte
CopyMemory tmp (0 ), ByVal dwData, tmplen
GetPointerToByteStringW = tmp
End If
End If
End Function