コード例 #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);
        }
コード例 #2
0
 public static extern int WNetAddConnection2(ref Win32Utils.NETRESOURCE netResource, [MarshalAs(UnmanagedType.LPWStr)] string password, [MarshalAs(UnmanagedType.LPWStr)] string username, [MarshalAs(UnmanagedType.U4)] int flags);