0

I am trying to map a network drive on to the server inside a windows service written in c#. I tried using net.exe with below code

        System.Diagnostics.Process p = new System.Diagnostics.Process();
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.CreateNoWindow = true;
        p.StartInfo.RedirectStandardError = true;
        p.StartInfo.RedirectStandardOutput = true;

        p.StartInfo.FileName = "net.exe";
        p.StartInfo.Arguments = " use " + DriveLetter + Path + " " + Password + " /user:" + Username;
        p.Start();
        p.WaitForExit();

the arguments basically translate to " use X: \\192.45.xx.xxx\sharename "xxxx" /user: domainname\username"

i get a "network name not found" error when this executes. The server i am trying to access is on a different domain than the one my app is sitting on, which is why i think i get that error.

Does anyone know how i can get past this and map a shared folder from another domain on to my local computer?

I'd greatly appreciate any help

Thanks Karthik

karry
  • 3,270
  • 3
  • 18
  • 31

1 Answers1

1

the arguments basically translate to " use X: \192.45.xx.xxx\sharename "xxxx" /user: domainname\username"

Assuming everything else is correct, this error is caused by specifying one backslash before the IP address -- you need 2 backslashes.

enter image description here

update

In response to your comments, clearly you are authenticated to access resources this other domain. Unless it is wide open, it is unlikely that the Windows Service, which is probably running under a system account, can access those resources.

As a troubleshooting step, change your service to run under your account, and see if that makes a difference.

Community
  • 1
  • 1
Jay
  • 56,361
  • 10
  • 99
  • 123
  • Idont think the syntax is the issue...something with the fact that the connection i am trying to make is on a different domain. i am successful in mapping the folder on windows using the 'map a network drive' tool, but having issues when i use net.exe – karry Sep 19 '11 at 02:56
  • Jay... thanks fr your update! I had considered that but the problem is that the app actually uses SQL filestream to put files on to a server within the same domain. For SQL Filestream to work, we need to implement "trusted connection". So, mapping a network drive looks like the only option to me...unless there is something i dont know of! – karry Sep 19 '11 at 03:32
  • @karry I'm suggesting that the windows service that is hosting your application cannot access the other machine at all because it is not running as a known user. If you can access it, you should try making the service run under your account. If that turns out to be the issue, then we can work from there. – Jay Sep 19 '11 at 03:44
  • Jay...I also tried running the same 'net' command as in my original question on command prompt on the machine. same problem. – karry Sep 19 '11 at 04:11
  • @karry It sounds like the problem has nothing to do with c# or windows services or mapping drives -- you're just unable to access a machine via IP address. That is more of an IT issue than a developer issue -- maybe you'll have more luck on ServerFault.com? – Jay Sep 19 '11 at 04:49
  • thanks Jay...that's what i am inclined towards thinking. I will try ServerFault.com and see what it turns out to be. – karry Sep 19 '11 at 14:24