Interface IMPR
An interface to methods of mpr.dll used by WindowsNetworkFileShare
public interface IMPR
Methods
AddConnection(NetResource, string, string, int)
Makes a connection to a network resource and can redirect a local device to the network resource.
P/Invoke call to mpr.dll - https://docs.microsoft.com/en-us/windows/desktop/api/winnetwk/nf-winnetwk-wnetaddconnection2aint AddConnection(WindowsNetworkFileShare.NetResource netResource, string password, string username, int flags)
Parameters
netResource
WindowsNetworkFileShare.NetResourceNetwork resource to interact with
password
stringPassword for making the network connection
username
stringUsername for making the network connection
flags
intA set of connection options - https://docs.microsoft.com/en-us/windows/desktop/api/winnetwk/nf-winnetwk-wnetaddconnection2a#parameters
Returns
- int
An integer representing the result - https://docs.microsoft.com/en-us/windows/desktop/api/winnetwk/nf-winnetwk-wnetaddconnection2a#return-value
CancelConnection(string, int, bool)
Cancels an existing network connection, removes remembered network connections that are not currently connected.
P/Invoke call to mpr.dll - https://docs.microsoft.com/en-us/windows/desktop/api/winnetwk/nf-winnetwk-wnetcancelconnection2aint CancelConnection(string name, int flags, bool force)
Parameters
name
stringPointer to a constant null-terminated string that specifies the name of either the redirected local device or the remote network resource to disconnect from.
If this parameter specifies a redirected local device, the function cancels only the specified device redirection. If the parameter specifies a remote network resource, all connections without devices are canceled.flags
intConnection type - https://docs.microsoft.com/en-us/windows/desktop/api/winnetwk/nf-winnetwk-wnetcancelconnection2a#parameters
force
boolSpecifies whether the disconnection should occur if there are open files or jobs on the connection. If this parameter is FALSE, the function fails if there are open files or jobs.
Returns
- int
An integer representing the result - https://docs.microsoft.com/en-us/windows/desktop/api/winnetwk/nf-winnetwk-wnetcancelconnection2a#return-value
GetLastError(out int, out StringBuilder, int, out StringBuilder, int)
Retrieves the most recent extended error code set by a WNet function
P/Invoke call to mpr.dll - https://docs.microsoft.com/en-us/windows/desktop/api/winnetwk/nf-winnetwk-wnetgetlasterroraint GetLastError(out int error, out StringBuilder errorBuf, int errorBufSize, out StringBuilder nameBuf, int nameBufSize)
Parameters
error
intThe error code reported by the network provider.
errorBuf
StringBuilderString variable to receive the description of the error
errorBufSize
intSize of error buffer
nameBuf
StringBuilderString variable to receive the network provider raising the error
nameBufSize
intSize of name buffer
Returns
- int
If the function succeeds, and it obtains the last error that the network provider reported, the return value is NO_ERROR.
If the caller supplies an invalid buffer, the return value is ERROR_INVALID_ADDRESS.
UseConnection(IntPtr, NetResource, string, string, int, string, string, string)
Makes a connection to a network resource. Can redirect a local device to a network resource.
P/Invoke call to mpr.dll - https://docs.microsoft.com/en-us/windows/desktop/api/winnetwk/nf-winnetwk-wnetuseconnectionaint UseConnection(IntPtr hwndOwner, WindowsNetworkFileShare.NetResource netResource, string password, string username, int flags, string lpAccessName, string lpBufferSize, string lpResult)
Parameters
hwndOwner
IntPtrHandle to a window that the provider of network resources can use as an owner window for dialog boxes
netResource
WindowsNetworkFileShare.NetResourceNetwork resource to interact with
password
stringA null-terminated string that specifies a password to be used in making the network connection
username
stringA null-terminated string that specifies a user name for making the connection
flags
intSet of bit flags describing the connection
lpAccessName
stringPointer to a buffer that receives system requests on the connection
lpBufferSize
stringPointer to a variable that specifies the size of the lpAccessName buffer, in characters.
If the call fails because the buffer is not large enough, the function returns the required buffer size in this locationlpResult
stringPointer to a variable that receives additional information about the connection
Returns
- int
An integer representing the result - https://docs.microsoft.com/en-us/windows/desktop/api/winnetwk/nf-winnetwk-wnetuseconnectiona#return-value