0

Here is my code:

int numOfLines1 = File.ReadAllLines(@"\\RADSpSC2\ARADA\BACKUP\Outbound\20131203\ECOMMDEMAND_20131202_ASPS.txt").Length;
Console.WriteLine(numOfLines1.ToString());

int numofLines2 = File.ReadAllLines(@"\\RADSpSC2\ARADA\BACKUP\Outbound\20131203\ECOMMDEMAND_20131202_BSPS").Length;
Console.WriteLine(numofLines2.ToString());
Console.ReadLine();

But It is giving me error like logon failure and bad username or password. I am trying to enter \\RADSpSC2 server from different server.

So how can It be possible to provide username and password inside the code?

crthompson
  • 15,653
  • 6
  • 58
  • 80
Debopam
  • 19
  • 1
  • 5

1 Answers1

0

You have to authenticate your process session through the target server.

To accomplish that you have to implement exactly what the "NET USE" shell command does by executing a PInvoke to the WNetAddConnection2 (before) and WNetCancelConnection2A (after) APIs.

For example : "net use \RADSpSC2\ARADA /user: " and then "net use \RADSpSC2\ARADA /delete".

You might read this article and omit the drive letter to create only the session without mapping the network drive.

Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74
  • Devil .. What will be the changed script for this ? – Debopam Jan 03 '14 at 07:28
  • Sorry, but I didn't understand your question. Could you explain it better? Do you want if provide you the coding for your example? – Antonio Petricca Jan 03 '14 at 07:30
  • devil Yes please share the coding for example. – Debopam Jan 03 '14 at 07:49
  • Unfortunately, I have no time to code, I am at work now. I suggest you to implement it by yourself using the article I have mentioned as reference. The steps are simply: connect to the share by the API example (with non drive letter), read the text file, p/invoke the cancel connection API (by the same example). – Antonio Petricca Jan 03 '14 at 08:31