»áÔ±£º ÃÜÂ룺 ¡¡Ãâ·Ñ×¢²á | Íü¼ÇÃÜÂë | »áÔ±µÇ¼ ÍøÒ³¹¦ÄÜ£º ¼ÓÈëÊÕ²Ø ÉèΪÊ×Ò³ ÍøÕ¾ËÑË÷  
 °²È«¼¼Êõ¼¼ÊõÎĵµ
  ¡¤ °²È«ÅäÖÆ
  ¡¤ ¹¤¾ß½éÉÜ
  ¡¤ ºÚ¿Í½Ìѧ
  ¡¤ ·À»ðǽ
  ¡¤ Â©¶´·ÖÎö
  ¡¤ ÆƽâרÌâ
  ¡¤ ºÚ¿Í±à³Ì
  ¡¤ ÈëÇÖ¼ì²â
 °²È«¼¼ÊõÂÛ̳
  ¡¤ °²È«ÅäÖÆ
  ¡¤ ¹¤¾ß½éÉÜ
  ¡¤ ·À»ðǽ
  ¡¤ ºÚ¿ÍÈëÇÖ
  ¡¤ Â©¶´¼ì²â
  ¡¤ Æƽⷽ·¨
  ¡¤ É±¶¾×¨Çø
 °²È«¼¼Êõ¹¤¾ßÏÂÔØ
  ¡¤ É¨Ã蹤¾ß
  ¡¤ ¹¥»÷³ÌÐò
  ¡¤ ºóÃÅľÂí
  ¡¤ ¾Ü¾ø·þÎñ
  ¡¤ ¿ÚÁîÆƽâ
  ¡¤ ´úÀí³ÌÐò
  ¡¤ ·À»ðǽ
  ¡¤ ¼ÓÃܽâÃÜ
  ¡¤ ÈëÇÖ¼ì²â
  ¡¤ ¹¥·ÀÑÝʾ
¼¼ÊõÎĵµ > VBÎĵµ > ÍøÂç±à³Ì
WindowsÏ·ÃÎʹ²ÏíµÄ½â¾ö·½°¸
·¢±íÈÕÆÚ£º2005-02-24 13:23:03×÷Õߣº¶ ³ö´¦£ºCSDN  

ÓÉÓÚWin9x ¸ú WinNT²»Ò»Ñù,ËùÒԱȽÏÂé·³

×î¼òµ¥µÄÉèÖù²ÏíµÄ·½·¨×ÔÈ»ÊÇshell È»ºóʹÓÃNet Share ÒÔ¼° Net Use À´´´½¨Á¬½Ó,×îºóʹÓÿØÖÆ̨ÃüÁî½øÐÐcopy ÒÔ¼° delete (¾ÙÀýcopy \\192.168.5.11\d$\*.* d:\)
ºÜ¼òµ¥µÄ¿ÉÒÔʵÏÖ,°üÀ¨WinAPIµÄopen read ... ¶¼Ö§³ÖÕâÖÖ·ÃÎÊ·½Ê½.
±¾ÎĶÔÕâÖÖ·½·¨²»×öÏêϸÌÖÂÛ(Õâ¸ö±È½Ï¼òµ¥)

±¾ÎÄÌÖÂÛµÄÊÇÈçºÎÀûÓô¿´úÂëÒÔ¼°APIÀ´ÊµÏÖ¹²ÏíµÄ´´½¨Óë·ÃÎÊ.Ïà¹Ø²¿·Ö¸ÐÐËȤµÄ¿ÉÒÔ×Ô¼º·â×°³ÉÀà,Ï´ε÷ÓõÄʱºò¼òµ¥Ò»Ð©.

´óÌå²½Öè:
1 ½¨Á¢¹²Ïí
2 ½¨Á¢¼ÆËã»úÖ®¼äµÄÁ¬½Ó
3 ö¾ÙĿ¼,¶Á д µÈÎļþ²Ù×÷
4 ¹Ø±ÕÁ¬½Ó

1 ÈçºÎÉèÖù²Ïí

ÕâÊÇÎÒÒýÓñðÈ˵ÄÄ£¿é£¬£¨¶Ô²»Æð£¬Ô­×÷ÕßµÄÃû×Ö²»ÊÇÎÒɾµÄ£¬basÄÃÀ´Ê±ÒѾ­Ã»ÓÐÁË£©¡£
Option Explicit

'2000 ÏÂÓÃAPIÀ´ÊµÏÖĿ¼¹²Ïí¼°É¾³ý¹²Ïí

'¹²ÏíÀàÐÍ
Private Const STYPE_ALL       As Long = -1
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

'¹²ÏíÐÅÏ¢
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 NetShareAdd Lib "netapi32" _
                           (ByVal ServerName As Long, _
                            ByVal level As Long, _
                            buf As Any, _
                            parmerr As Long) As Long

'ɾ³ý¹²Ïí
Private Declare Function NetShareDel Lib "netapi32.dll" _
                           (ByVal ServerName As Long, _
                            ByVal ShareName As Long, _
                            ByVal dword As Long) As Long
                    

'ÉèÖù²Ïí(·µ»Ø0 Ϊ³É¹¦)
'²ÎÊý:
'sServer          ¼ÆËã»úÃû
'sSharePath       Òª¹²Ïí·¾¶
'sShareName       ÏÔʾµÄ¹²ÏíÃû
'sShareRemark     ±¸×¢
'sSharePw         ÃÜÂë
Private Function ShareAdd(sServer As String, _
                          sSharePath As String, _
                          sShareName As String, _
                          sShareRemark As String, _
                          sSharePw As String) As Long
  
   Dim lngServer   As Long
   Dim lngNetname  As Long
   Dim lngPath     As Long
   Dim lngRemark   As Long
   Dim lngPw       As Long
   Dim parmerr    As Long
   Dim si2        As SHARE_INFO_2
  
   lngServer = StrPtr(sServer)      'ת³ÉµØÖ·
   lngNetname = StrPtr(sShareName)
   lngPath = StrPtr(sSharePath)
  
   'Èç¹ûÓб¸×¢ÐÅÏ¢
   If Len(sShareRemark) > 0 Then
      lngRemark = StrPtr(sShareRemark)
   End If
  
   'Èç¹ûÓÐÃÜÂë
   If Len(sSharePw) > 0 Then
      lngPw = StrPtr(sSharePw)
   End If
     
  '³õʼ»¯¹²ÏíÐÅÏ¢
   With si2
      .shi2_netname = lngNetname
      .shi2_path = lngPath
      .shi2_remark = lngRemark
      .shi2_type = STYPE_DISKTREE
      .shi2_permissions = ACCESS_ALL
      .shi2_max_uses = -1
      .shi2_passwd = lngPw
   End With
                         
  'ÉèÖù²Ïí(Óû§Ãû,¹²ÏíÀàÐÍ,¹²ÏíÐÅÏ¢,)
   ShareAdd = NetShareAdd(lngServer, _
                          2, _
                          si2, _
                          parmerr)
                         
End Function

'ɾ³ý¹²Ïí(·µ»Ø0 Ϊ³É¹¦)
'²ÎÊý:
'sServer       ¼ÆËã»úÃû
'sShareName    ¹²ÏíÃû
Private Function DelShare(sServer As String, _
                          sShareName As String) As Long
  
   Dim lngServer   As Long       '¼ÆËã»úÃû
   Dim lngNetname  As Long       '¹²ÏíÃû

   lngServer = StrPtr(sServer)      'ת³ÉµØÖ·
   lngNetname = StrPtr(sShareName)

   'ɾ³ý¹²Ïí
   DelShare = NetShareDel(lngServer, lngNetname, 0)

End Function
£¨¸ÐлԴ´úÂëÌṩÕߣ©

 


ÓÉÓÚWin98ÓëWin2000µÄ²»Í¬,ÏìÓ¦µÄ´úÂëÒ²²»Ò»Ñù.
ÒÔÏÂÊÇwin9xµÄ

ÔÚ98Ͻ¨Á¢·ÃÎÊÀàÐÍΪÍêÈ«µÄ·ÃÎÊÃÜÂëΪ¡°¡±µÄ¹²ÏíÎļþ¼Ð
Option Explicit

Private Const NERR_SUCCESS As Long = 0&

' Share types
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

' Flags
Private Const SHI50F_RDONLY = &H1
Private Const SHI50F_FULL = &H2
Private Const SHI50F_DEPENDSON = SHI50F_RDONLY + SHI50F_FULL
Private Const SHI50F_ACCESSMASK = SHI50F_RDONLY + SHI50F_FULL
Private Const SHI50F_PERSIST = &H100 ' Partage persistant
Private Const SHI50F_SYSTEM = &H200 ' Partage cach?

' Permissions (Win ME/NT/2000/XP)
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

' Win 9x
Private Type SHARE_INFO_50
    shi50_netname(0 To 12) As Byte 'LM20_NNLEN + 1
    shi50_type As Byte 'EShareType
    shi50_flags As Integer
    shi50_remark As Long
    shi50_Path As Long
    shi50_rw_password(0 To 8) As Byte 'SHPWLEN + 1
    shi50_ro_password(0 To 8) As Byte 'SHPWLEN + 1
End Type

' Quelle systeme d'exploitation
Private Type OSVERSIONINFO
    dwOSVersionInfoSize As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128
End Type

Private Declare Function NetShareAdd95 Lib "SVRAPI" Alias "NetShareAdd" (ByVal servername As String, ByVal level As Integer, ByVal buf As Long, ByVal cbBuffer As Integer) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)

Private Sub cmdCreateShare_Click()
   
    Dim lngSuccess As Long
   
    ' Create the share

     'ÒªÌí¼ÓÉÏÏàÓ¦µÄtextbox
    lngSuccess = ShareAdd(UCase(txtComputerName.Text), UCase(txtLocalPath.Text), UCase(txtShareName.Text), txtShareDesc.Text)
    'lngSuccess = ShareAdd(txtComputerName.Text, txtLocalPath.Text, txtShareName.Text, txtShareDesc.Text, txtSharePassRo.Text, txtSharePassRw.Text)
   
    Select Case lngSuccess
       Case 0:    ' Share created successfully
       Case 2118'¹²ÏíÃûÒѾ­´æÔÚ£¬¾Í¸Ä¸Ä¹²ÏíÃû£¬ÎÒÕâËæ±ã²¹ÁËÒ»¸ö1
       lngSuccess = ShareAdd(UCase(txtComputerName.Text), UCase(txtLocalPath.Text), UCase(txtShareName.Text) + "1", txtShareDesc.Text)
       Case Else: MsgBox "Create error number " & lngSuccess, vbCritical, "Error"
    End Select

End Sub

Private Function ShareAdd(sServer As String, sSharePath As String, sShareName As String, sShareRemark As String) As Long

    Dim si50 As SHARE_INFO_50
    Dim iErrParam As Integer
    Dim lpszPath() As Byte
    Dim lpszRemark() As Byte
    Dim intFlags As Integer

intFlags = SHI50F_FULL Or SHI50F_PERSIST 'mode normal le partage est visible sur la machine
' flags = SHI50F_FULL Or SHI50F_PERSIST Or SHI50F_SYSTEM 'mode système partage invisible
lpszPath = StrConv(sSharePath, vbFromUnicode) & vbNullChar
lpszRemark = StrConv(sShareRemark, vbFromUnicode) & vbNullChar

With si50
    StrToByte sShareName, VarPtr(.shi50_netname(0))
    .shi50_type = STYPE_DISKTREE
    .shi50_remark = VarPtr(lpszRemark(0))
    .shi50_Path = VarPtr(lpszPath(0))
    StrToByte "", VarPtr(.shi50_ro_password(0))
    StrToByte "", VarPtr(.shi50_rw_password(0))
    .shi50_flags = intFlags
End With

ShareAdd = NetShareAdd95("", 50, ByVal VarPtr(si50), LenB(si50))
   
End Function

Private Sub StrToByte(strInput As String, ByVal lpByteArray As Long)
    Dim lpszInput() As Byte
    lpszInput = StrConv(strInput, vbFromUnicode) & vbNullChar
    CopyMemory ByVal lpByteArray, lpszInput(0), UBound(lpszInput)
End Sub


2 Á¬½ÓÔ¶³Ì¹²Ïí

ÏÂÒ»²½¾ÍÊÇÁ¬½Ó

Windows¶ÔÓÚ¹²ÏíµÄ·ÃÎÊÊÇÕâÑùµÄ(¼Ç²»Çå³öÁË)

a ÅжÏÔ¶³Ì¹²ÏíÊÇ·ñÓÐÃÜÂë(guestÊÇ·ñÔÊÐí)
b ÅжÏÔ¶³Ì¹²ÏíµÄÃÜÂëÊÇ·ñÓ뵱ǰÕÊ»§Ò»ÖÂ,»òÕßÊÇ·ñΪ¿ÕÃÜÂë
c ÓÃÓû§ÃûÃÜÂëÁ¬½Ó,²¢ÇҼǼÏÂÀ´Õâ¸öÃÜÂë,·½±ãÒÔºóʹÓÃ
d Èç¹ûÐèÒªÓ³ÉäÍøÂçÇý¶¯Æ÷,ÄÇôӳÉäÒ»¸öÅÌ·û

¿ÉÒÔÀûÓÃNet use ÃüÁî,µ«ÊÇ win98¸úwin2000²»Ò»Ñù,net use Ò²²»Ò»Ñù
ÒÔÏÂÊÇ´úÂëʵÏÖ
£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½
°ÑÏÂÃæ´úÂë·Åµ½moduleÖÐ
Option Explicit
    Const WN_Success = &H0
    Const WN_Not_Supported = &H1
    Const WN_Net_Error = &H2
    Const WN_Bad_Pointer = &H4
    Const WN_Bad_NetName = &H32
    Const WN_Bad_Password = &H6
    Const WN_Bad_Localname = &H33
    Const WN_Access_Denied = &H7
    Const WN_Out_Of_Memory = &HB
    Const WN_Already_Connected = &H34
    Public ErrorNum As Long
    Public ErrorMsg As String
    Public rc As Long
    Private Const ERROR_NO_CONNECTION = 8
    Private Const ERROR_NO_DISCONNECT = 9
    Private Type NETRESOURCE
    dwScope As Long
    dwType As Long
    dwDisplayType As Long
    dwUsage As Long
    lpLocalName As String
    lpRemoteName As String
    lpComment As String
    lpProvider As String
    End Type
    Private Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (lpNetResource As NETRESOURCE, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Long) As Long
    Const NO_ERROR = 0
    Const CONNECT_UPDATE_PROFILE = &H1
    Const RESOURCETYPE_DISK = &H1
    Const RESOURCETYPE_PRINT = &H2
    Const RESOURCETYPE_ANY = &H0
    Const RESOURCE_GLOBALNET = &H2
    Const RESOURCEDISPLAYTYPE_SHARE = &H3
    Const RESOURCEUSAGE_CONNECTABLE = &H1

    Public Function ConnectUserPassword(sDrive As String, sService As String, Optional sUser As String = "", Optional sPassword As String = "") As Boolean
    Dim NETR As NETRESOURCE
    Dim errInfo As Long
    With NETR
    .dwScope = RESOURCE_GLOBALNET
    .dwType = RESOURCETYPE_DISK
    .dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
    .dwUsage = RESOURCEUSAGE_CONNECTABLE
    .lpRemoteName = sDrive
    .lpLocalName = sService
    End With
    errInfo = WNetAddConnection2(NETR, sPassword, sUser, CONNECT_UPDATE_PROFILE)
    ConnectUserPassword = errInfo = NO_ERROR
    End Function


£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½
call ConnectUserPassword("\\servername", "", "password", "username")

Ï൱ÓÚ  net use \\servername  password /user:username

3  Îļþ²Ù×÷

windowsÖ§³Ö¶Ô \\192.168.5.1\¹²ÏíÃû\Îļþ µÄÖ±½Ó²Ù×÷,ºÜÃ÷ÏÔµÄ,±ÈÈçÓÃAPIÀ´²Ù×÷
ÓÃFSOÒ²ÊÇÒ»ÑùµÄ.Õâ¸öÀý×ÓÊÇÀûÓÃFSO½øÐвÙ×÷,¸ú±¾µØûÓÐʲôÁ½Ñù.

//1ÁгösharedirµÄÄÚÈÝ£º
Ê×ÏÈÒýÓÃMicrosoft Scripting Runtime
´°ÌåÉÏÒ»¸ötreeview£¬Ò»¸ölistbox£º
Option Explicit
Dim FSO As New FileSystemObject
Private Sub Form_Load()
    Dim mfolder As Folder
    Set mfolder = FSO.GetFolder("\\192.168.2.1\guo")
    Dim mnode As Node
    Set mnode = Me.TreeView1.Nodes.Add(, , mfolder.Path, mfolder.Path)
    Dim a As File
    For Each a In mfolder.Files
        Me.List1.AddItem a.Name
    Next
    Dim subfolder As Folder
    For Each subfolder In mfolder.SubFolders
        Me.TreeView1.Nodes.Add mnode, tvwChild, subfolder.Path, subfolder.Name
    Next
    Set subfolder = Nothing
    Set a = Nothing
    Set mfolder = Nothing
End Sub

 

Private Sub Form_Unload(Cancel As Integer)
Set FSO = Nothing
End Sub

Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
    On Error Resume Next
    Dim mfolder As Folder
    Set mfolder = FSO.GetFolder(Node.Key)
    Dim a As File
    List1.Clear
    For Each a In mfolder.Files
        Me.List1.AddItem a.Name
    Next
    Dim subfolder As Folder
    For Each subfolder In mfolder.SubFolders
        Me.TreeView1.Nodes.Add Node, tvwChild, subfolder.Path, subfolder.Name
    Next
    Set subfolder = Nothing
    Set a = Nothing
    Set mfolder = Nothing
End Sub


ÓÉÓÚFSOÓÐʱ»á±»¹ÜÀíÔ±½ûÓÃ(´ó¶àÊý²¡¶¾¶¼ÊÇÀûÓÃFSO),ËùÒÔ»¹Òª×¼±¸ºóÊÖ,Ò»ÏÂÊÇͨÓõİ취.

¾ÍÓÃÏֳɵÄÀý×Ó°É£º
'Create a form with a command button (command1), a list box (list1)
'and four text boxes (text1, text2, text3 and text4).
'Type in the first textbox a startingpath like c:\£¨ÕâÀïÄãÊäÈë¹²ÏíÎļþ¼ÐµÄ·¾¶£¬È磺
\\ns\mytestÊÔÊÔ£©
'and in the second textbox you put a pattern like *.* or *.txt

Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long

Const MAX_PATH = 260
Const MAXDWORD = &HFFFF
Const INVALID_HANDLE_VALUE = -1
Const FILE_ATTRIBUTE_ARCHIVE = &H20
Const FILE_ATTRIBUTE_DIRECTORY = &H10
Const FILE_ATTRIBUTE_HIDDEN = &H2
Const FILE_ATTRIBUTE_NORMAL = &H80
Const FILE_ATTRIBUTE_READONLY = &H1
Const FILE_ATTRIBUTE_SYSTEM = &H4
Const FILE_ATTRIBUTE_TEMPORARY = &H100

Private Type FILETIME
    dwLowDateTime As Long
    dwHighDateTime As Long
End Type

Private Type WIN32_FIND_DATA
    dwFileAttributes As Long
    ftCreationTime As FILETIME
    ftLastAccessTime As FILETIME
    ftLastWriteTime As FILETIME
    nFileSizeHigh As Long
    nFileSizeLow As Long
    dwReserved0 As Long
    dwReserved1 As Long
    cFileName As String * MAX_PATH
    cAlternate As String * 14
End Type
Function StripNulls(OriginalStr As String) As String
    If (InStr(OriginalStr, Chr(0)) > 0) Then
        OriginalStr = Left(OriginalStr, InStr(OriginalStr, Chr(0)) - 1)
    End If
    StripNulls = OriginalStr
End Function

Function FindFilesAPI(path As String, SearchStr As String, FileCount As Integer, DirCount As Integer)
    'KPD-Team 1999
    'E-Mail: KPDTeam@Allapi.net

    Dim FileName As String ' Walking filename variable...
    Dim DirName As String ' SubDirectory Name
    Dim dirNames() As String ' Buffer for directory name entries
    Dim nDir As Integer ' Number of directories in this path
    Dim I As Integer ' For-loop counter...
    Dim hSearch As Long ' Search Handle
    Dim WFD As WIN32_FIND_DATA
    Dim Cont As Integer
    If Right(path, 1) <> "\" Then path = path & "\"
    ' Search for subdirectories.
    nDir = 0
    ReDim dirNames(nDir)
    Cont = True
    hSearch = FindFirstFile(path & "*", WFD)
    If hSearch <> INVALID_HANDLE_VALUE Then
        Do While Cont
        DirName = StripNulls(WFD.cFileName)
        ' Ignore the current and encompassing directories.
        If (DirName <> ".") And (DirName <> "..") Then
            ' Check for directory with bitwise comparison.
            If GetFileAttributes(path & DirName) And FILE_ATTRIBUTE_DIRECTORY Then
                dirNames(nDir) = DirName
                DirCount = DirCount + 1
                nDir = nDir + 1
                ReDim Preserve dirNames(nDir)
            End If
        End If
        Cont = FindNextFile(hSearch, WFD) 'Get next subdirectory.
        Loop
        Cont = FindClose(hSearch)
    End If
    ' Walk through this directory and sum file sizes.
    hSearch = FindFirstFile(path & SearchStr, WFD)
    Cont = True
    If hSearch <> INVALID_HANDLE_VALUE Then
        While Cont
            FileName = StripNulls(WFD.cFileName)
            If (FileName <> ".") And (FileName <> "..") Then
                FindFilesAPI = FindFilesAPI + (WFD.nFileSizeHigh * MAXDWORD) + WFD.nFileSizeLow
                FileCount = FileCount + 1
                List1.AddItem path & FileName
            End If
            Cont = FindNextFile(hSearch, WFD) ' Get next file
        Wend
        Cont = FindClose(hSearch)
    End If
    ' If there are sub-directories...
    If nDir > 0 Then
        ' Recursively walk into them...
        For I = 0 To nDir - 1
            FindFilesAPI = FindFilesAPI + FindFilesAPI(path & dirNames(I) & "\", SearchStr, FileCount, DirCount)
        Next I
    End If
End Function
Sub Command1_Click()
    Dim SearchPath As String, FindStr As String
    Dim FileSize As Long
    Dim NumFiles As Integer, NumDirs As Integer
    Screen.MousePointer = vbHourglass
    List1.Clear
    List1.Visible = False
    SearchPath = Text1.Text
    FindStr = Text2.Text
    FileSize = FindFilesAPI(SearchPath, FindStr, NumFiles, NumDirs)
    Text3.Text = NumFiles & " Files found in " & NumDirs + 1 & " Directories"
    Text4.Text = "Size of files found under " & SearchPath & " = " & Format(FileSize, "#,###,###,##0") & " Bytes"
    Screen.MousePointer = vbDefault
    List1.Visible = True
End Sub

¸´ÖƵÄÀý×Ó

//2¡¢¸´ÖÆsharedirϵÄÎļþµ½±¾µØ
//3¡¢ÔõÑù²ÅÄÜʵÏÖÏñwindowsÄÇÑùµÄ½ø¶È¿ØÖÆ

´°ÌåÉÏÒ»¸ö°´Å¥£¬Ò»¸öProgressBar£ºOption Explicit
'\\192.168.2.1\guo\123.rar
Public Function CopyFile(Src As String, Dst As String, mProgressBar As ProgressBar) As Single
    
     Dim BTest As Single, FSize As Single
     Dim F1 As Integer, F2 As Integer
     Dim sArray() As Byte
     Dim buff As Integer
    
     Const BUFSIZE = 1024
    
     buff = 1024
    
     F1 = FreeFile
     Open Src For Binary Access Read As F1
     F2 = FreeFile
     Open Dst For Binary As F2
    
     FSize = LOF(F1)
     BTest = FSize - LOF(F2)
     ReDim sArray(BUFSIZE) As Byte
    
     Do
     If BTest < BUFSIZE Then
     buff = BTest
     ReDim sArray(buff) As Byte
     End If
    
     Get F1, , sArray
     Put F2, , sArray
    
     BTest = FSize - LOF(F2)
     If BTest < 0 Then
     mProgressBar.Value = 100
     Else
     mProgressBar.Value = (100 - Int(100 * BTest / FSize))
     End If
     Loop Until BTest <= 0
    
     Close F1
     Close F2
     CopyFile = FSize
    
    End Function

Private Sub Command1_Click()
'¸´ÖÆÎļþ d:\ms\room.exe µ½ d:\room1.exe
CopyFile "\\192.168.2.1\guo\123.rar", "d:\myroom2.exe", ProgressBar1
End Sub


ÐèÒªÖ¸³öµÄÊÇÒÔÉÏ´úÂë³É¹¦ÔËÐеÄÇ°ÌáÊǹ²ÏíÎļþ¼ÐµÄ·ÃÎÊÀàÐÍΪ¡°ÍêÈ«¡±£¬Èç¹ûÄãµÄ¹²ÏíÎļþ¼ÐµÄ·ÃÎÊÀàÐÍΪ¡°Ö»¶Á¡±£¬ÄãÐèÒªÔÚ³ÌÐòÔËÐÐʱ£¬¸Ä±äËüµÄ·ÃÎÊÀàÐÍΪΪ¡°ÍêÈ«¡±¡£¼ÈÈ»ÄãÒѾ­ÖªµÀÁË£º
ÈçºÎ¹²ÏíÎļþ¼Ð£¬ÕâÀïÎҾͲ»ÂÞàÂÁË

Æäʵ£¬·ÃÎÊÒ»¸ö·ÃÎÊÀàÐÍΪ¡°ÍêÈ«¡±µÄ¹²ÏíÎļþ¼Ð£¬ºÍ·ÃÎʱ¾µØÎļþûÓÐʲô²»Í¬

4 ¶Ï¿ªÁ¬½Ó

Õâ¸ö±È½Ï¼òµ¥....ÓÐÁ½ÖÖ·½·¨

'=============================================
Option Explicit
Private Const RESOURCETYPE_DISK = &H1
Private Const RESOURCETYPE_ANY = &H0
Private Const RESOURCETYPE_PRINT = &H2
Private Const RESOURCETYPE_UNKNOWN = &HFFFF
Private Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags As Long, ByVal fForce As Long) As Long

 Private Declare Function WNetDisconnectDialog Lib "mpr.dll" (ByVal hWnd As Long, ByVal dwType As Long) As Long

 Public Function DisconnectNetworkDialog() As Long
 DisconnectNetworkDialog = WNetDisconnectDialog(0&, RESOURCETYPE_DISK)
 End Function


Private Sub Command1_Click() 'µÚÒ»ÖÖ·½·¨
Call DisconnectNetworkDialog
End Sub

Private Sub Command2_Click()' µÚ¶þÖÖ·½·¨
Call WNetCancelConnection2("\\10.0.0.1\temp", 1, True)
End Sub


×ܽá:
ÏÖÔÚ¿ÉÒÔ˵ÎÊÌâÒѾ­½â¾öÁË
ËäÈ»»¹ÓÐһЩССµÄÎÊÌ⣬±ÈÈçÁгöÎļþÁбíʱÓÐʱ»áÒç³ö¡£Õâ¸öÎÒ»á×Ô¼ºÏë°ì·¨½â¾öµÄ
±¾À´Ö»ÏëÎÊÒ»ÏÂÈçºÎÁ¬½ÓµÄË­ÖªµÀÈÈÐĵÄrainstormmasterÁ¬98ÏµĹ²Ïí¶¼ÁгöÀ´ÁË¡£ÔٴθÐлrainstormmasterµÄ°ïÖú¡£
×ܽ᣺
Æäʵ»Ø¹ýÍ·À´¿´¿´£¬Õâ¸öÎÊÌâµÄ´ð°¸Æäʵ²¢²»À§ÄÑ¡£ÊÇÎÒÏëµÄÌ«¸´ÔÓÁË¡£Ã»Ïëµ½¼òµ¥µÄFindFirstFile¡¢FindNextFile½â¾öÁËÎÒµÄÎÊÌâ¡£»¹ÓÐÔ¶³ÌÎļþµÄ·ÃÎʾÓÈ»¿ÉÒÔÖ±½ÓOpen...
ÕæÊÇÓ¦ÁËÕâ¾ä»°£º¡°Ã»ÓÐ×ö²»µ½£¬Ö»ÓÐÏë²»µ½¡±

»¹ÓиÐл ¶¯Á¦¸ÛÍå ÌṩµÄmpr.dllµÄʹÓ÷½·¨¡£Ô­À´Ö»ÊÇÓ³ÉäÍøÂçÇý¶¯Æ÷£¬Ã»ÓÐÏëµ½²»ÓÃÓ³ÉäÒ²¿ÉÒÔ½¨Á¢Á¬½Ó¡£ÓÖÊÇÒ»¸ö¡°Ã»Ïëµ½¡±¡£½¨Òé´ó¼ÒÒÔºóÓöµ½ÎÊÌâʱ¶à¶à³¢ÊÔһϡ£Ëµ²»¶¨¾Í³É¹¦ÁËÄØ ^o^

 

 

¡¾·µ»Ø¶¥²¿¡¿ ¡¾´òÓ¡±¾Ò³¡¿ ¡¾¹Ø±Õ´°¿Ú¡¿

¹ØÓÚÎÒÃÇ / ¸øÎÒÁôÑÔ / °æȨ¾Ù±¨ / Òâ¼û½¨Òé / ÍøÕ¾±à³ÌQQȺ   
Copyright ©2003- 2024 Lihuasoft.net webmaster(at)lihuasoft.net ¼ÓÔØʱ¼ä 0.00212