Results 1 to 28 of 28

Thread: VB Snippet - Map a Drive

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    VB Snippet - Map a Drive

    VB Code:
    1. Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszstrPassword As String, ByVal lpszLocalName As String) As Long
    2.  
    3. Dim strLocalDriveLetter As String
    4.  
    5. Dim strPassword As String
    6.  
    7. Dim strNetworkPathName As String
    8.  
    9.     strLocalDriveLetter = "Z:"                  'Local drive letter to be mapped
    10.  
    11.     strPassword = ""                            'specify network password if required
    12.  
    13.     strNetworkPathName = "\\NEWPATH\NEWPATH"   'path to network drive
    14.    
    15.     If WNetAddConnection(strNetworkPathName, strPassword, strLocalDriveLetter) > 0 Then
    16.  
    17.         MsgBox ("An Error occurred mapping the drive")
    18.  
    19.     Else
    20.  
    21.         MsgBox ("Drive successfully mapped!")
    22.  
    23.     End If
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  2. #2
    Member
    Join Date
    Jan 2003
    Location
    Between here and there
    Posts
    36
    nice! How would you modify this to prompt for a network drive to map? Like another server or share. If you hard code it, looks like you need to have all the servers the same name or create several instances

  3. #3
    Fanatic Member siyan's Avatar
    Join Date
    Jul 2001
    Location
    GOOOAAAAALLLLL!!!!!
    Posts
    869
    Use a bunch of inputboxes or a custom form.
    Unite, proletariat!

  4. #4
    Member
    Join Date
    Jan 2003
    Location
    Between here and there
    Posts
    36
    sometimes I wonder about myself

  5. #5
    Addicted Member Flip's Avatar
    Join Date
    Jun 2002
    Location
    Burke, VA
    Posts
    247

    another way

    another possible way (without api's) is through SHELL command 'subst'. Here is the help from the terminal:

    Code:
    H:\>help subst
    Associates a path with a drive letter.
    
    SUBST [drive1: [drive2:]path]
    SUBST drive1: /D
    
      drive1:        Specifies a virtual drive to which you want to assign a path.
      [drive2:]path  Specifies a physical drive and path you want to assign to
                     a virtual drive.
      /D             Deletes a substituted (virtual) drive.
    
    Type SUBST with no parameters to display a list of current virtual drives.
    And here is how you can use it:
    VB Code:
    1. ' map the windows folder to the S drive
    2. Shell("subst c:\windows s:"
    3. ' remove the map
    4. Shell("subst s: \D")

    This might be easier if you want to do it on one line...
    The "company" website My homepage: nerisoft.com
    scars heal but glory is forever

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Even another way - no vb.

    Create a bat file to map a drive.

    You could always shell out the .bat file in vb if you wanted.
    Code:
    @echo off
    echo Mapping Drive.......
    NET USE R: \\ServerName\ShareName /PERSISTENT:YES
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    Member
    Join Date
    Feb 2006
    Posts
    35

    Re: VB Snippet - Map a Drive

    Question: When I use the "NET USE" code if doesn't remove the drive icon. What can I do about? An yes, I hit F5 several times. When I click the icon a error message shows.

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: VB Snippet - Map a Drive

    Quote Originally Posted by nbmprivat
    Question: When I use the "NET USE" code if doesn't remove the drive icon. What can I do about? An yes, I hit F5 several times. When I click the icon a error message shows.
    So, it disconnects the drive but leaves the icon in place?

  9. #9
    Member
    Join Date
    Feb 2006
    Posts
    35

    Re: VB Snippet - Map a Drive

    Quote Originally Posted by Hack
    So, it disconnects the drive but leaves the icon in place?
    Yes...

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: VB Snippet - Map a Drive

    Have you tried using the API instead of NET USE?

  11. #11
    Member
    Join Date
    Feb 2006
    Posts
    35

    Re: VB Snippet - Map a Drive

    Nope... but I dropped the drivemapping solution. I just use the direct network path to start batch files.

  12. #12
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: VB Snippet - Map a Drive

    Quote Originally Posted by RobDog888
    Even another way - no vb.

    Create a bat file to map a drive.

    You could always shell out the .bat file in vb if you wanted.
    Code:
    @echo off
    echo Mapping Drive.......
    NET USE R: \\ServerName\ShareName /PERSISTENT:YES
    Hey I saw that today because of a new post.

    If you again don't want to Hardcode the values here is an extension of RD's code
    Code:
    @echo off
    echo Mapping Drive.......
    NET USE %1 %2 /PERSISTENT:YES
    If you save this file as MAPDRIVE.BAt then you can execute it by passing the drive and path like this
    Code:
    MAPDRIVE P: \\ServerName\ShareName
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  13. #13
    Frenzied Member Robbo's Avatar
    Join Date
    Jan 2001
    Location
    Bradford
    Posts
    1,143

    Re: VB Snippet - Map a Drive

    strNetworkPathName = "\\NEWPATH\NEWPATH" 'path to network drive


    the PC is on the network however its is under a different domain so doesnt pick it up, how do i modify strNetworkPathName = "\\NEWPATH\NEWPATH" if under different domain

    cheers
    -----------------------------------------------
    "The hall is rented,"
    "the orchestra is engaged,"
    "its now time to see if you can dance!"
    Q, Q-Who, Star Trek The Next Generation
    -----------------------------------------------
    General Work day

    -----------------------------------------------
    DOS, Win 95, Win 98 SE, Win ME, Win NT 4.0 SP6a, Windows 2000 SP3, Window XP SP1, Windows 7, Windows 8/8.1, Windows 10, Office 97 Pro, Office 2000 Pro, Office 2010, Office 2013, Office 2016, Office 2019, Visual Basic 6 (SP5), SQL, Oracle

  14. #14
    Frenzied Member Robbo's Avatar
    Join Date
    Jan 2001
    Location
    Bradford
    Posts
    1,143

    Re: VB Snippet - Map a Drive

    Quote Originally Posted by James Stanich
    VB Code:
    1. Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszstrPassword As String, ByVal lpszLocalName As String) As Long
    2.  
    3. Dim strLocalDriveLetter As String
    4.  
    5. Dim strPassword As String
    6.  
    7. Dim strNetworkPathName As String
    8.  
    9.     strLocalDriveLetter = "Z:"                  'Local drive letter to be mapped
    10.  
    11.     strPassword = ""                            'specify network password if required
    12.  
    13.     strNetworkPathName = "\\NEWPATH\NEWPATH"   'path to network drive
    14.    
    15.     If WNetAddConnection(strNetworkPathName, strPassword, strLocalDriveLetter) > 0 Then
    16.  
    17.         MsgBox ("An Error occurred mapping the drive")
    18.  
    19.     Else
    20.  
    21.         MsgBox ("Drive successfully mapped!")
    22.  
    23.     End If
    oh also how do u disconnect afterwards?
    Last edited by Robbo; Apr 5th, 2006 at 09:12 AM.
    -----------------------------------------------
    "The hall is rented,"
    "the orchestra is engaged,"
    "its now time to see if you can dance!"
    Q, Q-Who, Star Trek The Next Generation
    -----------------------------------------------
    General Work day

    -----------------------------------------------
    DOS, Win 95, Win 98 SE, Win ME, Win NT 4.0 SP6a, Windows 2000 SP3, Window XP SP1, Windows 7, Windows 8/8.1, Windows 10, Office 97 Pro, Office 2000 Pro, Office 2010, Office 2013, Office 2016, Office 2019, Visual Basic 6 (SP5), SQL, Oracle

  15. #15
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB Snippet - Map a Drive

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  16. #16
    Frenzied Member Robbo's Avatar
    Join Date
    Jan 2001
    Location
    Bradford
    Posts
    1,143

    Re: VB Snippet - Map a Drive

    Quote Originally Posted by RobDog888

    that using this method??

    Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszstrPassword As String, ByVal lpszLocalName As String) As Long

    Dim strLocalDriveLetter As String

    Dim strPassword As String

    Dim strNetworkPathName As String

    strLocalDriveLetter = "Z:" 'Local drive letter to be mapped

    strPassword = "" 'specify network password if required

    strNetworkPathName = "\\NEWPATH\NEWPATH" 'path to network drive

    If WNetAddConnection(strNetworkPathName, strPassword, strLocalDriveLetter) > 0 Then

    MsgBox ("An Error occurred mapping the drive")

    Else

    MsgBox ("Drive successfully mapped!")

    End If

    ??
    -----------------------------------------------
    "The hall is rented,"
    "the orchestra is engaged,"
    "its now time to see if you can dance!"
    Q, Q-Who, Star Trek The Next Generation
    -----------------------------------------------
    General Work day

    -----------------------------------------------
    DOS, Win 95, Win 98 SE, Win ME, Win NT 4.0 SP6a, Windows 2000 SP3, Window XP SP1, Windows 7, Windows 8/8.1, Windows 10, Office 97 Pro, Office 2000 Pro, Office 2010, Office 2013, Office 2016, Office 2019, Visual Basic 6 (SP5), SQL, Oracle

  17. #17
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB Snippet - Map a Drive

    No, the menu didnt sync so when I copied the url it was on another api I had lloked at. This one is the one - http://windowssdk.msdn.microsoft.com...asp?frame=true
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  18. #18
    Frenzied Member Robbo's Avatar
    Join Date
    Jan 2001
    Location
    Bradford
    Posts
    1,143

    Re: VB Snippet - Map a Drive

    Quote Originally Posted by RobDog888
    No, the menu didnt sync so when I copied the url it was on another api I had lloked at. This one is the one - http://windowssdk.msdn.microsoft.com...asp?frame=true

    still not sure what string is? just copy and paste if you like?
    -----------------------------------------------
    "The hall is rented,"
    "the orchestra is engaged,"
    "its now time to see if you can dance!"
    Q, Q-Who, Star Trek The Next Generation
    -----------------------------------------------
    General Work day

    -----------------------------------------------
    DOS, Win 95, Win 98 SE, Win ME, Win NT 4.0 SP6a, Windows 2000 SP3, Window XP SP1, Windows 7, Windows 8/8.1, Windows 10, Office 97 Pro, Office 2000 Pro, Office 2010, Office 2013, Office 2016, Office 2019, Visual Basic 6 (SP5), SQL, Oracle

  19. #19
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB Snippet - Map a Drive

    I think this is the correct conversion from C++ to VB6.
    VB Code:
    1. Private Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" (ByVal lpName As String, _
    2. ByVal dwFlags As Long, ByVal lpszLocalName As Boolean) As Long
    Here is the C++ code example of its use.

    http://windowssdk.msdn.microsoft.com...connection.asp
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  20. #20
    Frenzied Member Robbo's Avatar
    Join Date
    Jan 2001
    Location
    Bradford
    Posts
    1,143

    Re: VB Snippet - Map a Drive

    Quote Originally Posted by RobDog888
    I think this is the correct conversion from C++ to VB6.
    VB Code:
    1. Private Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" (ByVal lpName As String, _
    2. ByVal dwFlags As Long, ByVal lpszLocalName As Boolean) As Long
    Here is the C++ code example of its use.

    http://windowssdk.msdn.microsoft.com...connection.asp

    ok

    well have theses two

    Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszstrPassword As String, ByVal lpszLocalName As String) As Long
    Private Declare Function WNetCancelConnection Lib "mpr.dll" Alias "WNetCancelConnectionA" (ByVal lpszNetPath As String, ByVal lpszstrPassword As String, ByVal lpszLocalName As String) As Long

    so should i replace second with this?

    Private Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags As Long, ByVal lpszLocalName As Boolean) As Long
    -----------------------------------------------
    "The hall is rented,"
    "the orchestra is engaged,"
    "its now time to see if you can dance!"
    Q, Q-Who, Star Trek The Next Generation
    -----------------------------------------------
    General Work day

    -----------------------------------------------
    DOS, Win 95, Win 98 SE, Win ME, Win NT 4.0 SP6a, Windows 2000 SP3, Window XP SP1, Windows 7, Windows 8/8.1, Windows 10, Office 97 Pro, Office 2000 Pro, Office 2010, Office 2013, Office 2016, Office 2019, Visual Basic 6 (SP5), SQL, Oracle

  21. #21
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB Snippet - Map a Drive

    Did you look at the example in the link I posted?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  22. #22
    Frenzied Member Robbo's Avatar
    Join Date
    Jan 2001
    Location
    Bradford
    Posts
    1,143

    Re: VB Snippet - Map a Drive

    Quote Originally Posted by RobDog888
    Did you look at the example in the link I posted?

    ok thats in C++, will have a try see if can get it working if not will post the code cheers
    -----------------------------------------------
    "The hall is rented,"
    "the orchestra is engaged,"
    "its now time to see if you can dance!"
    Q, Q-Who, Star Trek The Next Generation
    -----------------------------------------------
    General Work day

    -----------------------------------------------
    DOS, Win 95, Win 98 SE, Win ME, Win NT 4.0 SP6a, Windows 2000 SP3, Window XP SP1, Windows 7, Windows 8/8.1, Windows 10, Office 97 Pro, Office 2000 Pro, Office 2010, Office 2013, Office 2016, Office 2019, Visual Basic 6 (SP5), SQL, Oracle

  23. #23
    Frenzied Member Robbo's Avatar
    Join Date
    Jan 2001
    Location
    Bradford
    Posts
    1,143

    Re: VB Snippet - Map a Drive

    ok

    Private Sub UNMAP_DRIVE()
    If WNetCancelConnection2(strNetworkPathName, strPassword, strLocalDriveLetter) = 0 Then
    MsgBox ("Mapped drive removed")
    End
    Else
    MsgBox (" not successfully unmapped!")
    End If
    End Sub

    not picking it up, what does WNetCancelConnection2 have to equal or should be?
    -----------------------------------------------
    "The hall is rented,"
    "the orchestra is engaged,"
    "its now time to see if you can dance!"
    Q, Q-Who, Star Trek The Next Generation
    -----------------------------------------------
    General Work day

    -----------------------------------------------
    DOS, Win 95, Win 98 SE, Win ME, Win NT 4.0 SP6a, Windows 2000 SP3, Window XP SP1, Windows 7, Windows 8/8.1, Windows 10, Office 97 Pro, Office 2000 Pro, Office 2010, Office 2013, Office 2016, Office 2019, Visual Basic 6 (SP5), SQL, Oracle

  24. #24
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB Snippet - Map a Drive

    Check the "Return Values" section of the api definition.

    http://windowssdk.msdn.microsoft.com...onnection2.asp

    I also think you have your paramaters wrong.

    Should be - "Drive letter", CONNECT_UPDATE_PROFILE, False
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  25. #25
    Frenzied Member Robbo's Avatar
    Join Date
    Jan 2001
    Location
    Bradford
    Posts
    1,143

    Re: VB Snippet - Map a Drive

    will have another mess see if i can get it to work, never used this command so like looking for a drawing pin in the dark, not sure as theres no help on it in VB
    -----------------------------------------------
    "The hall is rented,"
    "the orchestra is engaged,"
    "its now time to see if you can dance!"
    Q, Q-Who, Star Trek The Next Generation
    -----------------------------------------------
    General Work day

    -----------------------------------------------
    DOS, Win 95, Win 98 SE, Win ME, Win NT 4.0 SP6a, Windows 2000 SP3, Window XP SP1, Windows 7, Windows 8/8.1, Windows 10, Office 97 Pro, Office 2000 Pro, Office 2010, Office 2013, Office 2016, Office 2019, Visual Basic 6 (SP5), SQL, Oracle

  26. #26
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB Snippet - Map a Drive

    There shouldnt be that much to it...
    VB Code:
    1. If WNetCancelConnection2("Drive letter", CONNECT_UPDATE_PROFILE, False) = NO_ERROR Then
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  27. #27
    Frenzied Member Robbo's Avatar
    Join Date
    Jan 2001
    Location
    Bradford
    Posts
    1,143

    Re: VB Snippet - Map a Drive

    yippy

    this worked

    Private Sub UNMAP_DRIVE()
    If WNetCancelConnection2(strLocalDriveLetter, CONNECT_UPDATE_PROFILE, False) = 0 Then
    'MsgBox ("Mapped drive removed")
    End
    Else
    MsgBox ("Not successfully unmapped!")
    End If
    End Sub
    -----------------------------------------------
    "The hall is rented,"
    "the orchestra is engaged,"
    "its now time to see if you can dance!"
    Q, Q-Who, Star Trek The Next Generation
    -----------------------------------------------
    General Work day

    -----------------------------------------------
    DOS, Win 95, Win 98 SE, Win ME, Win NT 4.0 SP6a, Windows 2000 SP3, Window XP SP1, Windows 7, Windows 8/8.1, Windows 10, Office 97 Pro, Office 2000 Pro, Office 2010, Office 2013, Office 2016, Office 2019, Visual Basic 6 (SP5), SQL, Oracle

  28. #28
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB Snippet - Map a Drive

    Therre you go See isnt it more saisifying when you only get guidence and not everything handed to you on a silver platter. Now you will not forget this each time you need to map/unmap a drive.

    Note the False argument is not to force a disconnection if there is an open job or process using the resource.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width