Справочник функций

Ваш аккаунт

Войти через: 
Забыли пароль?
Регистрация
Информацию о новых материалах можно получать и без регистрации:

Почтовая рассылка

Подписчиков: -1
Последний выпуск: 19.06.2015

Перечисление общих ресурсов

8.3K
29 августа 2006 года
IT-Shark
33 / / 25.05.2006
Уважаемые коллеги!
Я программирую на VB 6 и меня интересует следующий вопрос:

Как перечислить общие папки на заданном компьютере.

Спасибо!
282
29 августа 2006 года
Bard
481 / / 26.02.2006
Кидаеш на форму List1, Command1, Label1, Label2 и етот

Код:
Option Explicit

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2006 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
Private Const MAX_PREFERRED_LENGTH As Long = -1
Private Const NERR_SUCCESS As Long = 0&
Private Const ERROR_MORE_DATA As Long = 234&
Private Const LB_SETTABSTOPS As Long = &H192

'See NetServerEnum demo for complete
'list of server types supported
Private Const SV_TYPE_ALL As Long = &HFFFFFFFF
Private Const SV_TYPE_WORKSTATION As Long = &H1
Private Const SV_TYPE_SERVER As Long = &H2

Private Const STYPE_ALL As Long = -1  'note: my const
Private Const STYPE_DISKTREE As Long = 0
Private Const STYPE_PRINTQ As Long = 1
Private Const STYPE_DEVICE As Long = 2
Private Const STYPE_IPC As Long = 3
Private Const STYPE_SPECIAL As Long = &H80000000
Private Const ACCESS_READ  As Long = &H1
Private Const ACCESS_WRITE As Long = &H2
Private Const ACCESS_CREATE As Long = &H4
Private Const ACCESS_EXEC As Long = &H8
Private Const ACCESS_DELETE As Long = &H10
Private Const ACCESS_ATRIB As Long = &H20
Private Const ACCESS_PERM As Long = &H40
Private Const ACCESS_ALL As Long = ACCESS_READ Or _
                                   ACCESS_WRITE Or _
                                   ACCESS_CREATE Or _
                                   ACCESS_EXEC Or _
                                   ACCESS_DELETE Or _
                                   ACCESS_ATRIB Or _
                                   ACCESS_PERM
'for use on Win NT/2000 only
Private Type SERVER_INFO_100
  sv100_platform_id As Long
  sv100_name As Long
End Type

'shi2_current_uses: number of current connections to the resource
'shi2_max_uses    : max concurrent connections resource can accommodate
'shi2_netname     : share name of a resource
'shi2_passwd      : share's password when
'                  (server running with share-level security)
'shi2_path        : local path for the shared resource
'shi2_permissions : shared resource's permissions
'                  (servers running with share-level security)
'shi2_remark      : string containing optional comment about the resource
'shi2_type        : the type of the shared resource
Private Type SHARE_INFO_2
  shi2_netname As Long
  shi2_type As Long
  shi2_remark As Long
  shi2_permissions As Long
  shi2_max_uses As Long
  shi2_current_uses As Long
  shi2_path As Long
  shi2_passwd As Long
End Type

Private 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

Private Declare Function NetShareEnum Lib "netapi32" _
  (ByVal servername As Long, _
   ByVal level As Long, _
   bufptr As Long, _
   ByVal prefmaxlen As Long, _
   entriesread As Long, _
   totalentries As Long, _
   resume_handle As Long) As Long
   
Private Declare Function NetApiBufferFree Lib "netapi32" _
   (ByVal Buffer As Long) As Long
     
Private 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

Private Declare Function SendMessage Lib "user32" _
   Alias "SendMessageA" _
  (ByVal hwnd As Long, _
   ByVal wMsg As Long, _
   ByVal wParam As Long, _
   lParam As Any) As Long


Private Sub Form_Load()

   ReDim TabArray(0 To 4) As Long
   
   TabArray(0) = 73
   TabArray(1) = 125
   TabArray(2) = 151
   TabArray(3) = 232
   
  'Clear any existing tabs
  'and set the list tabstops
   Call SendMessage(List1.hwnd, LB_SETTABSTOPS, 0&, ByVal 0&)
   Call SendMessage(List1.hwnd, LB_SETTABSTOPS, 4&, TabArray(0))
   List1.Refresh
   
   Command1.Caption = "Net Share Enum"
   Label1.Caption = "call success (0) or error :"
   Label2.Caption = ""

End Sub


Private Sub Command1_Click()

   Dim bufptr          As Long  'output
   Dim dwServer        As Long  'pointer to the server
   Dim dwEntriesread   As Long  'out
   Dim dwTotalentries  As Long  'out
   Dim dwResumehandle  As Long  'out
   Dim success         As Long
   Dim nStructSize     As Long
   Dim cnt             As Long
   Dim usrname         As String
   Dim bServer         As String
   Dim shi2            As SHARE_INFO_2
     
  'demo using the local machine
  bServer = "\\" & Environ$("COMPUTERNAME") & vbNullString
   
  'create pointer to the machine name
   dwServer = StrPtr(bServer)
   
   success = NetShareEnum(dwServer, _
                          2, _
                          bufptr, _
                          MAX_PREFERRED_LENGTH, _
                          dwEntriesread, _
                          dwTotalentries, _
                          dwResumehandle)

   List1.Clear
   Label2.Caption = success
   
   If success = NERR_SUCCESS And _
      success <> ERROR_MORE_DATA Then
     
      nStructSize = LenB(shi2)
     
      For cnt = 0 To dwEntriesread - 1
         
        'get one chunk of data and cast
        'into an SHARE_INFO_2 type, and
        'add the data to a list
         CopyMemory shi2, ByVal bufptr + (nStructSize * cnt), nStructSize

         List1.AddItem GetPointerToByteStringW(shi2.shi2_netname) & vbTab & _
                       GetConnectionType(shi2.shi2_type) & vbTab & _
                       GetConnectionPermissions(shi2.shi2_permissions) & vbTab & _
                       GetPointerToByteStringW(shi2.shi2_remark) & vbTab & _
                       GetPointerToByteStringW(shi2.shi2_path)  ' & vbTab & _

      Next
     
   End If
   
   Call NetApiBufferFree(bufptr)

End Sub


Private Function GetConnectionPermissions(ByVal dwPermissions As Long) As String

  'Permissions are only returned a shared
  'resource running with share-level security.
  'A server running user-level security ignores
  'this member, so the function returns
  '"not applicable".
   Dim tmp As String
   
   If (dwPermissions And ACCESS_READ) Then tmp = tmp & "R"
   If (dwPermissions And ACCESS_WRITE) Then tmp = tmp & " W"
   If (dwPermissions And ACCESS_CREATE) Then tmp = tmp & " C"
   If (dwPermissions And ACCESS_DELETE) Then tmp = tmp & " D"
   If (dwPermissions And ACCESS_EXEC) Then tmp = tmp & " E"
   If (dwPermissions And ACCESS_ATRIB) Then tmp = tmp & " A"
   If (dwPermissions And ACCESS_PERM) Then tmp = tmp & " P"

   If Len(tmp) = 0 Then tmp = "n/a"
 
   GetConnectionPermissions = tmp
   
   
End Function


Private Function GetConnectionType(ByVal dwConnectType As Long) As String

  'compare connection type value
   Select Case dwConnectType
      Case STYPE_DISKTREE: GetConnectionType = "disk drive"
      Case STYPE_PRINTQ:   GetConnectionType = "print queue"
      Case STYPE_DEVICE:   GetConnectionType = "communication device"
      Case STYPE_IPC:      GetConnectionType = "ipc"
      Case STYPE_SPECIAL:  GetConnectionType = "administrative"
      Case Else
         
        'weird case. On my NT2000 machines,
        'I have to do this to identify the
        'IPC$ share type
         Select Case (dwConnectType Xor STYPE_SPECIAL) 'rtns 3 if IPC
            Case STYPE_IPC: GetConnectionType = "ipc"
            Case Else:      GetConnectionType = "undefined"
         End Select
         
   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


У меня почему-то смотрит ресурсы только на локальном компе (на моем), а на другие компы - доступ запрещен (5) :( Может у тебя заработает.
8.3K
29 августа 2006 года
IT-Shark
33 / / 25.05.2006
2 Bard: Мне и нужно их смотреть на локальном компе!

Спасибо за заботу и поддержку!
Желаю Удачи!
Реклама на сайте | Обмен ссылками | Ссылки | Экспорт (RSS) | Контакты
Добавить статью | Добавить исходник | Добавить хостинг-провайдера | Добавить сайт в каталог