Logo
Anglais Russe Allemand Français Espagnol Italien
contactprivacy
   Support Forums
chart
• Adjust flexgrid cell
• Animation
• Centering form text
• Coffee machine
• Creating fileshares
• Creating shortcuts
• Custom buttons
• Directory browser
• Disable mouse events
• File search by ext
• File transfer
• File watcher
• Formatting flexgrid
• Get Content Type
• Get HTML source
• Get modem port
• HTTP proxy
• ipconfig
• Large file split/merge
• MAPI
• MCI Sound Player
• Menu with images
• MP3 normalizer
• Net Send
• Netstat 2000
• No duplicate entries
• Outlook Address Book
• Set font color
• Shapes
• SOAP test
• Text-to-image
• Text file viewer
• Text find/replace
• UPS component
• View NT groups
• Word template
• Writing DNS control
    • Using DNS control
• Writing SMTP control
    • Sending email
    • Mailing list
• Writing WhoIs control
    • Using WhoIs control
• View HTML source
OISV - Organization of Independent Software Vendors - Contributing Member
VB projects - Creating/deleting file shares

Description: Writing the program that creates/deletes file shares on local system
Minimum requirements: vb5, ADSI
Download: source code
Screenshot:
shares (3017 bytes)
Project: Standard EXE
Controls: lst (listbox), txtName (textbox), cmdAdd (button), cmdRemove (button), Drive1 (drivelistbox), Dir1 (dirlistbox)
Additional project references: Active DS Type Library
Code:
Dim strHost As String
Dim aHost As IADsContainer
Dim aLAN As IADsContainer
Dim aShare As IADsFileShare
Dim bFirst As Boolean

Private Sub cmdAdd_Click()
    On Error Resume Next
    If txtName = "" Then
        MsgBox "Unable to create share"
    Else
        Set aShare = aLAN.Create("fileshare", txtName)
        If Err <> 0 Then
            MsgBox "Unable to create share"
        Else
            aShare.Path = Dir1.List(Dir1.ListIndex)
            aShare.SetInfo
            GetShares
        End If
    End If
End Sub

Private Sub cmdRemove_Click()
    If lst.ListIndex <> -1 Then
        aLAN.Delete "fileshare", lst.List(lst.ListIndex)
        GetShares
    End If
End Sub

Private Sub Drive1_Change()
    Dir1.Path = Drive1.Drive & "\"
End Sub

Private Sub Form_Load()
    strHost = wsTCP.LocalHostName
    GetShares
End Sub

Private Sub GetShares()
    lst.Clear
    Me.MousePointer = 11
    Set aHost = GetObject("WinNT://" & strHost & ",computer")
    Set aLAN = aHost.GetObject("FileService", "lanmanserver")
    Me.MousePointer = 0
    For Each aShare In aLAN
        lst.AddItem aShare.Name
    Next
    lst.ListIndex = 0
End Sub

Private Sub lst_Click()
    Dim strPath As String
    txtName = lst.List(lst.ListIndex)
    Me.MousePointer = 11
    Set aShare = aLAN.GetObject("fileshare", txtName)
    strPath = aShare.Get("Path")
    Drive1.Drive = Left(strPath, InStr(strPath, ":"))
    Dir1.Path = strPath
    Me.MousePointer = 0
End Sub

Copyright © 1996-2010 OstroSoft. Tous droits réservés. info@ostrosoft.com