public NamedPipeConnection(string server, NetworkCredential credential) { // Argument validation: Validator.AssertNotNullOrWhiteSpace(server, "server"); Validator.AssertNotNull(credential, "credential"); this.Server = server; // Disconnect from the IPC share first in case of a preexisting connection. Ignore any errors. this.DoDisconnect(); // Connect NetResource resource = new NetResource(this.ShareName); // TODO: Use Credential.Domain Win32ErrorCode result = NativeMethods.WNetAddConnection2(ref resource, credential.SecurePassword, credential.UserName, NetConnectOptions.Temporary); Validator.AssertSuccess(result); }
private static extern Win32ErrorCode WNetAddConnection2([In] ref NetResource netResource, [In] SafeUnicodeSecureStringPointer password, [In][MarshalAs(UnmanagedType.LPWStr)] string userName, NetConnectOptions flags);
internal static Win32ErrorCode WNetAddConnection2(ref NetResource netResource, SecureString password, string userName, NetConnectOptions flags) { using (SafeUnicodeSecureStringPointer passwordPointer = new SafeUnicodeSecureStringPointer(password)) { return WNetAddConnection2(ref netResource, passwordPointer, userName, flags); } }