Quantcast
Channel: User lfx - Stack Overflow
Viewing all articles
Browse latest Browse all 39

How to open connection to local network path protected by password in smart way? (Whith C#)

$
0
0

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


Viewing all articles
Browse latest Browse all 39

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>