Results 1 to 9 of 9

Thread: How to clear network drive credentials in vb.net?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2020
    Posts
    9

    Question How to clear network drive credentials in vb.net?

    in windows, you can see Stored User Names and Passwords by running rundll32.exe keymgr.dll, KRShowKeyMgr in cmd. Then, you can select a specific network drive and Remove its credentials.

    Is there a way to clear specific network drive's credentials programatically in .net? either by running some shell command, creating a process, or by importing some .net library?
    Last edited by mshaemadafa; Jun 23rd, 2020 at 09:09 AM.

  2. #2
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,046

    Re: How to clear network drive credentials in vb.net?

    this sounds fishy to me,
    why not ask the network administrator
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2020
    Posts
    9

    Re: How to clear network drive credentials in vb.net?

    well I am the network administrator, and I'm trying to build the program that would let users clear network drive's credentials on their own. For instance, someone is logged on \\abcdefg\shared with Account1( username1, password1). Account2(username2, password2) has different privileges, and at the moment he wants to connect to the network drive with that account. The only way to disconnect from \\abcdefg\shared is to clear the network drive credentials using keymgr.dll.

    Even if user won't ever switch the accounts, I still want him to be able to disconnect from the network drive completely, and for that, clearing the network credentials is an essential step. Even when I delete the network drive by net use \\abcdefg\shared \delete, username and password is still cached, and needs to be cleared using keymgr.dll

    Of course I can run rundll32.exe keymgr.dll, KRShowKeyMgr using Shell command and ask users to clear the network credentials on their own, but it's risky as they might accidentally delete something else.
    Last edited by mshaemadafa; Jun 23rd, 2020 at 01:04 PM.

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: How to clear network drive credentials in vb.net?

    I can certainly see the point. I'm glad I don't deal with that stuff, though. I would expect that it would be possible. Hopefully, somebody who has dealt with this more will have an answer.
    My usual boring signature: Nothing

  5. #5
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,046

    Re: How to clear network drive credentials in vb.net?

    here a Link to Powershell
    https://gallery.technet.microsoft.co...lsPas-981564bf


    or with the CMDKey
    put this in a Batchfile
    Code:
    For /F “tokens=1,2 delims= ” %%G in (‘cmdkey /list ^| findstr Target’) do  cmdkey /delete %%H
    see if it picks up everything

    good luck
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  6. #6
    Fanatic Member
    Join Date
    Jun 2019
    Posts
    557

    Re: How to clear network drive credentials in vb.net?

    You can add AdysTech.CredentialManager NuGet library and then use it as follows:
    VB.NET Code:
    1. Imports AdysTech.CredentialManager
    2.  
    3. ...
    4. CredentialManager.RemoveCredentials("192.168.x.x", CredentialType.Windows)
    5. ...

    You have to set the proper target name (192.168.x.x).


    If you don't want full credentials management (e.g. enumerating all credentials, etc.), you can just declare the external function:
    VB.NET Code:
    1. Public Declare Unicode Function CredDelete Lib "advapi32.dll" Alias "CredDeleteW" (ByVal TargetName As String, ByVal Type As Integer, ByVal Flags As Integer) As Boolean
    2.  
    3. ...
    4. Dim success = CredDelete("192.168.x.x", 2, 0)
    5. ...
    In the CredDelete the parameter 2 means "domain password". Read more on pInvoke.net site.

  7. #7

  8. #8

    Thread Starter
    New Member
    Join Date
    Jun 2020
    Posts
    9

    Re: How to clear network drive credentials in vb.net?

    peterst,
    Quote Originally Posted by peterst View Post
    You can add AdysTech.CredentialManager NuGet library and then use it as follows:
    VB.NET Code:
    1. Imports AdysTech.CredentialManager
    2.  
    3. ...
    4. CredentialManager.RemoveCredentials("192.168.x.x", CredentialType.Windows)
    5. ...

    You have to set the proper target name (192.168.x.x).
    This is perfect! works flawlessly. Thanks!

    ident and ChrisE's answers seem to be a proper solution, too but probably this is the simplest way.
    Last edited by mshaemadafa; Jun 24th, 2020 at 08:24 AM.

  9. #9
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,046

    Re: How to clear network drive credentials in vb.net?

    Quote Originally Posted by mshaemadafa View Post
    peterst,


    This is perfect! works flawlessly. Thanks!
    I agree, looks like it is easy to use
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

Tags for this Thread

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