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?
Re: How to clear network drive credentials in vb.net?
this sounds fishy to me,
why not ask the network administrator
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.
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.
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
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:
Imports AdysTech.CredentialManager
...
CredentialManager.RemoveCredentials("192.168.x.x", CredentialType.Windows)
...
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:
Public Declare Unicode Function CredDelete Lib "advapi32.dll" Alias "CredDeleteW" (ByVal TargetName As String, ByVal Type As Integer, ByVal Flags As Integer) As Boolean
...
Dim success = CredDelete("192.168.x.x", 2, 0)
...
In the CredDelete the parameter 2 means "domain password". Read more on pInvoke.net site.
Re: How to clear network drive credentials in vb.net?
Re: How to clear network drive credentials in vb.net?
peterst,
Quote:
Originally Posted by
peterst
You can add
AdysTech.CredentialManager NuGet library and then use it as follows:
VB.NET Code:
Imports AdysTech.CredentialManager
...
CredentialManager.RemoveCredentials("192.168.x.x", CredentialType.Windows)
...
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.
Re: How to clear network drive credentials in vb.net?
Quote:
Originally Posted by
mshaemadafa
peterst,
This is perfect! works flawlessly. Thanks!
I agree, looks like it is easy to use