powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Microsoft Access [игнор отключен] [закрыт для гостей] / Вопрос к спецам по API. Функция NetServerEnum ...
6 сообщений из 6, страница 1 из 1
Вопрос к спецам по API. Функция NetServerEnum ...
    #32488245
Alex112
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Использую эту функцию для получения массива 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:

Код: plaintext
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

...
Рейтинг: 0 / 0
Вопрос к спецам по API. Функция NetServerEnum ...
    #32488315
Фотография Лох Позорный
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Если спецы по API не объявятся - унесу это в VB. Или в программирование?
...
Рейтинг: 0 / 0
Вопрос к спецам по API. Функция NetServerEnum ...
    #32488320
Alex112
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Мне что-то подсказывает, что здесь должны быть спецы ...
...
Рейтинг: 0 / 0
Вопрос к спецам по API. Функция NetServerEnum ...
    #32488360
Фотография Лох Позорный
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Те, кто при работе в аксесе стали спецами в API - найдут тебя и в VB :)
...
Рейтинг: 0 / 0
Вопрос к спецам по API. Функция NetServerEnum ...
    #32488363
Хвост
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Код: plaintext
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.
sv101_type 
Specifies the type of software the computer is running. This member can be one of 
the following values. Value Meaning 

SV_TYPE_WORKSTATION A LAN Manager workstation 
SV_TYPE_SERVER A LAN Manager server 
SV_TYPE_SQLSERVER Any server running with Microsoft SQL Server 
SV_TYPE_DOMAIN_CTRL Primary domain controller 
SV_TYPE_DOMAIN_BAKCTRL Backup domain controller 
SV_TYPE_TIME_SOURCE Server running the Timesource service 
SV_TYPE_AFP Apple File Protocol server 
SV_TYPE_NOVELL Novell server 
SV_TYPE_DOMAIN_MEMBER LAN Manager  2 .x domain member 
SV_TYPE_LOCAL_LIST_ONLY Servers maintained by the browser 
SV_TYPE_PRINTQ_SERVER Server sharing print queue 
SV_TYPE_DIALIN_SERVER Server running dial-in service 
SV_TYPE_XENIX_SERVER Xenix server 
SV_TYPE_SERVER_MFPN Microsoft File and Print for NetWare 
SV_TYPE_NT Windows Server  2003 , Windows XP, Windows  2000 , or Windows NT 
SV_TYPE_WFW Server running Windows for Workgroups 
SV_TYPE_SERVER_NT Windows Server  2003 , Windows  2000  server, or Windows NT server that is not a domain controller 
SV_TYPE_POTENTIAL_BROWSER Server that can run the browser service 
SV_TYPE_BACKUP_BROWSER Server running a browser service as backup 
SV_TYPE_MASTER_BROWSER Server running the master browser service 
SV_TYPE_DOMAIN_MASTER Server running the domain master browser 
SV_TYPE_DOMAIN_ENUM Primary domain 
SV_TYPE_WINDOWS Windows Me, Windows  98 , or Windows  95  
SV_TYPE_ALL All servers 
SV_TYPE_TERMINALSERVER Terminal Server 
SV_TYPE_CLUSTER_NT Server clusters available in the domain 
SV_TYPE_CLUSTER_VS_NT Cluster virtual servers available in the domain 


Код: plaintext
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.
#define SV_TYPE_WORKSTATION         0x00000001
#define SV_TYPE_SERVER              0x00000002
#define SV_TYPE_SQLSERVER           0x00000004
#define SV_TYPE_DOMAIN_CTRL         0x00000008
#define SV_TYPE_DOMAIN_BAKCTRL      0x00000010
#define SV_TYPE_TIME_SOURCE         0x00000020
#define SV_TYPE_AFP                 0x00000040
#define SV_TYPE_NOVELL              0x00000080
#define SV_TYPE_DOMAIN_MEMBER       0x00000100
#define SV_TYPE_PRINTQ_SERVER       0x00000200
#define SV_TYPE_DIALIN_SERVER       0x00000400
#define SV_TYPE_XENIX_SERVER        0x00000800
#define SV_TYPE_SERVER_UNIX         SV_TYPE_XENIX_SERVER
#define SV_TYPE_NT                  0x00001000
#define SV_TYPE_WFW                 0x00002000
#define SV_TYPE_SERVER_MFPN         0x00004000
#define SV_TYPE_SERVER_NT           0x00008000
#define SV_TYPE_POTENTIAL_BROWSER   0x00010000
#define SV_TYPE_BACKUP_BROWSER      0x00020000
#define SV_TYPE_MASTER_BROWSER      0x00040000
#define SV_TYPE_DOMAIN_MASTER       0x00080000
#define SV_TYPE_SERVER_OSF          0x00100000
#define SV_TYPE_SERVER_VMS          0x00200000
#define SV_TYPE_WINDOWS             0x00400000   /* Windows95 and above */ 
#define SV_TYPE_DFS                 0x00800000   /* Root of a DFS tree */ 
#define SV_TYPE_CLUSTER_NT          0x01000000   /* NT Cluster */ 
#define SV_TYPE_TERMINALSERVER      0x02000000   /* Terminal Server(Hydra) */ 
#define SV_TYPE_CLUSTER_VS_NT       0x04000000   /* NT Cluster Virtual Server Name */ 
#define SV_TYPE_DCE                 0x10000000   /* IBM DSS (Directory and Security Services) or equivalent */ 
#define SV_TYPE_ALTERNATE_XPORT     0x20000000   /* return list for alternate transport */ 
#define SV_TYPE_LOCAL_LIST_ONLY     0x40000000   /* Return local list only */ 
#define SV_TYPE_DOMAIN_ENUM         0x80000000
#define SV_TYPE_ALL                 0xFFFFFFFF   /* handy for NetServerEnum2 */ 


То что значения разные - так это AND вышеперечисленных констант

З.Ы.
я не спец, и вообще я про это только что узнал ... из МСДН
...
Рейтинг: 0 / 0
Вопрос к спецам по API. Функция NetServerEnum ...
    #32488391
Alex112
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
2 хвост

Спасибо, дошло, как только по русски сказали. В MSDN сам сижу :) сейчас.
...
Рейтинг: 0 / 0
6 сообщений из 6, страница 1 из 1
Форумы / Microsoft Access [игнор отключен] [закрыт для гостей] / Вопрос к спецам по API. Функция NetServerEnum ...
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]