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

Posted by lfx on Stack Overflow See other posts from Stack Overflow or by lfx
Published on 2009-08-14T09:04:12Z Indexed on 2010/05/20 7:50 UTC
Read the original article Hit count: 231

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about c#

Related posts about Windows