1

In Windows, when using a local PC account and trying to access the network printer share (ie typing "\printershare" in the Run window), a box pops up asking for a domain user's username and password.

Put in a domain user's username and password, and then the printer share appears using the domain user's credentials.

How can this be achieved via C#?

I have tried the following methods:


var printerShare = new DirectoryEntry(@"\\printershare\", "username", "password");

var printerShare = new DirectoryEntry(@"WinNT://printershare\", "username", "password");

var printerShare = new DirectoryEntry(@"WinNT:\\printershare\", "username", "password");

var printerShare = new DirectoryEntry("LDAP://printershare.corp.domain.com", "username", "password");

var printerShare = new DirectoryEntry("LDAP:\\printershare.corp.domain.com", "username", "password");

Unfortunately, none of them work. Mapping a network directory or folder would be simple.

But the fact that there are no folders is what is making me scratch my head.

Anyone know what I'm doing wrong here?

Kyle Trauberman
  • 25,414
  • 13
  • 85
  • 121
JohnnyRockets
  • 91
  • 1
  • 4

1 Answers1

0

Check out this question (specifically the NetworkConnection class):

How to provide user name and password when connecting to a network share

Community
  • 1
  • 1
prestomanifesto
  • 12,528
  • 5
  • 34
  • 50