How to open connection to local network path protected by password in smart way? (Whith C#)
- by lfx
Hi, I developing program witch have to write some data in file whom are stored in network computer witch are protected by password.
Now I'm doing this way - open connection with cmd then write data.
static bool ConnectToSrv()
{
String myUser = "domain.local\\user";
String myPass = "pwd";
String cmdString = "net use \\\\otherPC\\folder\\ /user:" + myUser + " " + myPass;
try
{
ManagementClass processClass = new ManagementClass("Win32_Process");
object[] methodArgs = { cmdString, null, null, 0 };
object result = processClass.InvokeMethod("Create", methodArgs);
return true;
}
catch (System.Exception error)
{
return false;
}
}
public void writeDate(string data){ }
I believe there must by better way. I mean the .NET way.
Does anybody know how to do it? :)
Thanks