"Run as different user" Visual Studio, cannot clear cached TFS credentials

Viewed 24572

Update I managed to solve it by getting my user granted permissions to remotely connect to the desktop using credential set 2 and thus being able to remove the stored credentials from Credential Manager.


I log onto my server with one set of credentials and open Visual Studio 2012 using "Run as different user" (Shift + Right-click) as I need a second set of credentials to deploy to my dev. env. SharePoint site.

I have previously done above and then connected to TFS using a third set of credentials, as the my user (second set credentials) didn't have access yet. Now my user have access and I wish to use these credentials instead.
TFS automatically logs me in with the third set credentials every time I open VS using "Run as different user" - However, if I open VS normally without using "Run as different user" I get prompted for login to the TFS.

I have tried checking the Windows credentials and there is nothing there. And I can't log onto the server using the second set credentials as only the first set can access the server with Remote Desktop.

So how do I "clear" cached TFS credentials when using "Run as different user"?

5 Answers

I ran into this issue as well, but clearing out the AppData settings didn't help.

I had created a console application to connect to TFS and it prompted me for credentials the first time I ran it. After that, the credentials were stored and would supersede any other credentials I provided. I finally figured out that VS had added a registry entry in:

HKEY_CURRENT_USER\Software\Microsoft\VSCommon\14.0\ClientServices\TokenStorage\VisualStudio\VssApp

Deleting the key worked, but I also discovered that one can accomplish the same programmatically:

var clientCredentails = new VssClientCredentialStorage();

// URI of the target TFS server
var tfsUri = new Uri("https://[username].visualstudio.com/DefaultCollection/");

// Find the cached credentials
var federatedCredentials = clientCredentails.RetrieveToken(tfsUri, VssCredentialsType.Federated);

// Remove the credentials from the cache
clientCredentails.RemoveToken(tfsUri, federatedCredentials);
Related