Example #1
0
 private static extern int WNetAddConnection2(NetResource netResource,
     string password, string username, int flags);
Example #2
0
        public NetworkConnection(string networkName,
            NetworkCredential credentials)
        {
            _networkName = networkName;

            var netResource = new NetResource()
            {
                Scope = ResourceScope.GlobalNetwork,
                ResourceType = ResourceType.Disk,
                DisplayType = ResourceDisplaytype.Share,
                RemoteName = networkName
            };

            var userName = string.IsNullOrEmpty(credentials.Domain)
                ? credentials.UserName
                : string.Format(@"{0}\{1}", credentials.Domain, credentials.UserName);

            var result = WNetAddConnection2(
                netResource,
                credentials.Password,
                userName,
                0x00000004);

            if (result != 0)
            {
                throw new Win32Exception(result, "Error connecting to remote share");
            }
        }
Example #3
0
 private static extern int WNetAddConnection2(NetResource netResource,
                                              string password, string username, int flags);