Exemplo n.º 1
0
        public static string NetAddConnection(string server, string username, string password)
        {
            Win32Utils.NETRESOURCE netResource = new Win32Utils.NETRESOURCE();
            netResource.dwDisplayType = 1;
            netResource.dwScope       = 0;
            netResource.dwType        = 0;
            netResource.dwUsage       = 2;
            netResource.LocalName     = "";
            netResource.RemoteName    = Win32Utils.GetWNetServerString(server);
            netResource.Provider      = (string)null;
            string username1;
            string domain;

            Win32Utils.SplitUsernameAndDomain(username, out username1, out domain);
            username = !string.IsNullOrEmpty(domain) ? username1 + "@" + domain : server.Replace(':', '-') + "\\" + username1;
            int    num = Win32Utils.WNetAddConnection2(ref netResource, password, username, 0);
            string str;

            switch (num)
            {
            case 0:
            case 1219:
            case 71:
                str = (string)null;
                break;

            default:
                str = Win32Utils.FormatWin32ErrorMessage((uint)num);
                break;
            }
            return(str);
        }
Exemplo n.º 2
0
 public static void NetCancelConnection(string server)
 {
     Win32Utils.WNetCancelConnection2(Win32Utils.GetWNetServerString(server), 0, true);
 }