using System; using System.Runtime.InteropServices; using System.Text; using Vanara.InteropServices; namespace Vanara.PInvoke { /// Items from the mpr.dll public static class Mpr { /// Flags used in the CONNECTDLGSTRUCT. // https://msdn.microsoft.com/en-us/library/windows/desktop/aa385332(v=vs.85).aspx [PInvokeData("Winnetwk.h", MSDNShortId = "aa385332")] [Flags] public enum CONN_DLG { /// /// Display a read-only path instead of allowing the user to type in a path. /// /// This flag should be set only if the lpRemoteName member of the NETRESOURCE structure pointed to by lpConnRes member is not /// NULL (or an empty string), and the CONNDLG_USE_MRU flag is not set. /// /// CONNDLG_RO_PATH = 0x00000001, /// Internal flag. Do not use. CONNDLG_CONN_POINT = 0x00000002, /// /// Enter the most recently used paths into the combination box. Set this value to simulate the WNetConnectionDialog function. /// CONNDLG_USE_MRU = 0x00000004, /// Show the check box allowing the user to restore the connection at logon. CONNDLG_HIDE_BOX = 0x00000008, /// Restore the connection at logon. CONNDLG_PERSIST = 0x00000010, /// Do not restore the connection at logon. CONNDLG_NOT_PERSIST = 0x00000020, } /// Option flags used with WNetAddConnection2. [PInvokeData("Winnetwk.h", MSDNShortId = "aa385413")] [Flags] public enum CONNECT { /// /// The network resource connection should be remembered. /// /// If this bit flag is set, the operating system automatically attempts to restore the connection when the user logs on. /// /// /// The operating system remembers only successful connections that redirect local devices. It does not remember connections that /// are unsuccessful or deviceless connections. (A deviceless connection occurs when the lpLocalName member is NULL or when it /// points to an empty string.) /// /// If this bit flag is clear, the operating system does not automatically restore the connection at logon. /// CONNECT_UPDATE_PROFILE = 0x00000001, /// /// The network resource connection should not be put in the recent connection list. If this flag is set and the connection is /// successfully added, the network resource connection will be put in the recent connection list only if it has a redirected /// local device associated with it. /// CONNECT_UPDATE_RECENT = 0x00000002, /// /// The network resource connection should not be remembered. If this flag is set, the operating system will not attempt to /// restore the connection when the user logs on again. /// CONNECT_TEMPORARY = 0x00000004, /// If this flag is set, the operating system may interact with the user for authentication purposes. CONNECT_INTERACTIVE = 0x00000008, /// /// This flag instructs the system not to use any default settings for user names or passwords without offering the user the /// opportunity to supply an alternative. This flag is ignored unless CONNECT_INTERACTIVE is also set. /// CONNECT_PROMPT = 0x00000010, CONNECT_NEED_DRIVE = 0x00000020, CONNECT_REFCOUNT = 0x00000040, /// /// This flag forces the redirection of a local device when making the connection. /// /// If the lpLocalName member of NETRESOURCE specifies a local device to redirect, this flag has no effect, because the operating /// system still attempts to redirect the specified device. When the operating system automatically chooses a local device, the /// dwType member must not be equal to RESOURCETYPE_ANY. /// /// /// If this flag is not set, a local device is automatically chosen for redirection only if the network requires a local device /// to be redirected. /// /// /// Windows Server 2003 and Windows XP: When the system automatically assigns network drive letters, letters are assigned /// beginning with Z:, then Y:, and ending with C:. This reduces collision between per-logon drive letters (such as network drive /// letters) and global drive letters (such as disk drives). Note that previous releases assigned drive letters beginning with C: /// and ending with Z:. /// /// CONNECT_REDIRECT = 0x00000080, CONNECT_LOCALDRIVE = 0x00000100, /// /// If this flag is set, then the operating system does not start to use a new media to try to establish the connection (initiate /// a new dial up connection, for example). /// CONNECT_CURRENT_MEDIA = 0x00000200, CONNECT_DEFERRED = 0x00000400, /// /// If this flag is set, the operating system prompts the user for authentication using the command line instead of a graphical /// user interface (GUI). This flag is ignored unless CONNECT_INTERACTIVE is also set. /// Windows 2000/NT and Windows Me/98/95: This value is not supported. /// CONNECT_COMMANDLINE = 0x00000800, /// /// If this flag is set, and the operating system prompts for a credential, the credential should be saved by the credential /// manager. If the credential manager is disabled for the caller's logon session, or if the network provider does not support /// saving credentials, this flag is ignored. This flag is also ignored unless you set the CONNECT_COMMANDLINE flag. /// Windows 2000/NT and Windows Me/98/95: This value is not supported. /// CONNECT_CMD_SAVECRED = 0x00001000, /// /// If this flag is set, and the operating system prompts for a credential, the credential is reset by the credential manager. If /// the credential manager is disabled for the caller's logon session, or if the network provider does not support saving /// credentials, this flag is ignored. This flag is also ignored unless you set the CONNECT_COMMANDLINE flag. /// Windows Vista: This value is supported on Windows Vista and later. /// CONNECT_CRED_RESET = 0x00002000, CONNECT_REQUIRE_INTEGRITY = 0x00004000, CONNECT_REQUIRE_PRIVACY = 0x00008000 } /// Info level for WNetGetUniversalName. [PInvokeData("Winnetwk.h", MSDNShortId = "aa385474")] public enum INFO_LEVEL { /// The function stores a UNIVERSAL_NAME_INFO structure in the buffer. UNIVERSAL_NAME_INFO_LEVEL = 0x00000001, /// The function stores a REMOTE_NAME_INFO structure in the buffer. REMOTE_NAME_INFO_LEVEL = 0x00000002 } /// Characteristics of the network provider software. [PInvokeData("Winnetwk.h", MSDNShortId = "aa385349")] [Flags] public enum NETINFO { /// The network provider is running as a 16-bit Windows network driver. NETINFO_DLL16 = 0x00000001, /// The network provider requires a redirected local disk drive device to access server file systems. NETINFO_DISKRED = 0x00000004, /// The network provider requires a redirected local printer port to access server file systems. NETINFO_PRINTERRED = 0x00000008, } /// The display options for the network object in a network browsing user interface. public enum NETRESOURCEDisplayType : uint { /// The method used to display the object does not matter. RESOURCEDISPLAYTYPE_GENERIC = 0x00000000, /// The object should be displayed as a domain. RESOURCEDISPLAYTYPE_DOMAIN = 0x00000001, /// The object should be displayed as a server. RESOURCEDISPLAYTYPE_SERVER = 0x00000002, /// The object should be displayed as a share. RESOURCEDISPLAYTYPE_SHARE = 0x00000003, /// The object should be displayed as a file. RESOURCEDISPLAYTYPE_FILE = 0x00000004, /// The object should be displayed as a group. RESOURCEDISPLAYTYPE_GROUP = 0x00000005, /// The object should be displayed as a network. RESOURCEDISPLAYTYPE_NETWORK = 0x00000006, /// The object should be displayed as a logical root for the entire network. RESOURCEDISPLAYTYPE_ROOT = 0x00000007, /// The object should be displayed as a administrative share. RESOURCEDISPLAYTYPE_SHAREADMIN = 0x00000008, /// The object should be displayed as a directory. RESOURCEDISPLAYTYPE_DIRECTORY = 0x00000009, /// /// The object should be displayed as a tree. This display type was used for a NetWare Directory Service (NDS) tree by the /// NetWare Workstation service supported on Windows XP and earlier. /// RESOURCEDISPLAYTYPE_TREE = 0x0000000A, /// /// The object should be displayed as a Netware Directory Service container. This display type was used by the NetWare /// Workstation service supported on Windows XP and earlier. /// RESOURCEDISPLAYTYPE_NDSCONTAINER = 0x0000000B, } /// The scope of the enumeration. public enum NETRESOURCEScope : uint { /// Enumerate currently connected resources. The dwUsage member cannot be specified. RESOURCE_CONNECTED = 0x00000001, /// Enumerate all resources on the network. The dwUsage member is specified. RESOURCE_GLOBALNET = 0x00000002, /// Enumerate remembered (persistent) connections. The dwUsage member cannot be specified. RESOURCE_REMEMBERED = 0x00000003, /// Enumerate recent connections. The dwUsage member cannot be specified. RESOURCE_RECENT = 0x00000004, /// ? RESOURCE_CONTEXT = 0x00000005, } /// The type of resource. public enum NETRESOURCEType : uint { /// All resources. RESOURCETYPE_ANY = 0x00000000, /// Disk resources. RESOURCETYPE_DISK = 0x00000001, /// Print resources. RESOURCETYPE_PRINT = 0x00000002, /// Reserved resources. RESOURCETYPE_RESERVED = 0x00000008, /// Neither a disk or print resource. RESOURCETYPE_UNKNOWN = 0xFFFFFFFF, } /// A set of bit flags describing how the resource can be used. [Flags] public enum NETRESOURCEUsage : uint { /// /// The resource is a connectable resource; the name pointed to by the lpRemoteName member can be passed to the WNetAddConnection /// function to make a network connection. /// RESOURCEUSAGE_CONNECTABLE = 0x00000001, /// /// The resource is a container resource; the name pointed to by the lpRemoteName member can be passed to the WNetOpenEnum /// function to enumerate the resources in the container. /// RESOURCEUSAGE_CONTAINER = 0x00000002, /// The resource is not a local device. RESOURCEUSAGE_NOLOCALDEVICE = 0x00000004, /// The resource is a sibling. This value is not used by Windows. RESOURCEUSAGE_SIBLING = 0x00000008, /// /// The resource must be attached. This value specifies that a function to enumerate resource this should fail if the caller is /// not authenticated, even if the network permits enumeration without authentication. /// RESOURCEUSAGE_ATTACHED = 0x00000010, /// All valid values. RESOURCEUSAGE_ALL = (RESOURCEUSAGE_CONNECTABLE | RESOURCEUSAGE_CONTAINER | RESOURCEUSAGE_ATTACHED), /// Reserved RESOURCEUSAGE_RESERVED = 0x80000000 } /// A set of bit flags describing the connection. [PInvokeData("Winnetwk.h", MSDNShortId = "aa385345")] [Flags] public enum WNCON : uint { /// /// In the absence of information about the actual connection, the information returned applies to the performance of the network /// card. If this flag is not set, information is being returned for the current connection with the resource, with any routing /// degradation taken into consideration. /// WNCON_FORNETCARD = 0x00000001, /// /// The connection is not being routed. If this flag is not set, the connection may be going through routers that limit /// performance. Consequently, if WNCON_FORNETCARD is set, actual performance may be much less than the information returned. /// WNCON_NOTROUTED = 0x00000002, /// /// The connection is over a medium that is typically slow (for example, over a modem using a normal quality phone line). You /// should not set the WNCON_SLOWLINK bit if the dwSpeed member is set to a nonzero value. /// WNCON_SLOWLINK = 0x00000004, /// /// Some of the information returned is calculated dynamically, so reissuing this request may return different (and more current) information. /// WNCON_DYNAMIC = 0x00000008, } /// /// The MultinetGetConnectionPerformance function returns information about the expected performance of a connection used to /// access a network resource. /// /// /// /// A pointer to a NETRESOURCE structure that specifies the network resource. The following members have specific meanings in /// this context. /// /// /// /// /// Member /// Meaning /// /// /// lpLocalName /// /// A pointer to a buffer that specifies a local device, such as "F:" or "LPT1", that is /// redirected to a network resource to be queried. If this member is NULL or an empty string, the network resource is specified in /// the lpRemoteName member. If this flag specifies a local device, lpRemoteName is ignored. /// /// /// /// lpRemoteName /// /// A pointer to a network resource to query. The resource must currently have an established connection. For example, if the /// resource is a file on a file server, then having the file open will ensure the connection. /// /// /// /// lpProvider /// /// Usually set to NULL, but can be a pointer to the owner (provider) of the resource if the network on which the resource resides is /// known. If the lpProvider member is not NULL, the system attempts to return information only about the named network. /// /// /// /// /// /// A pointer to the NETCONNECTINFOSTRUCT structure that receives the data. /// /// If the function succeeds, the return value is NO_ERROR. /// If the function fails, the return value is a system error code, such as one of the following values. /// /// /// /// Return code /// Description /// /// /// ERROR_NOT_SUPPORTED /// The network resource does not supply this information. /// /// /// ERROR_NOT_CONNECTED /// /// The lpLocalName member of the NETRESOURCE structure pointed to by the lpNetResource parameter does not specify a redirected /// device, or the lpRemoteName member does not specify the name of a resource that is currently connected. /// /// /// /// ERROR_NO_NET_OR_BAD_PATH /// /// The operation could not be completed, either because a network component is not started, or because the specified resource name /// is not recognized. /// /// /// /// ERROR_BAD_DEVICE /// The local device specified by the lpLocalName member is invalid. /// /// /// ERROR_BAD_NET_NAME /// /// The network name cannot be found. This error is returned if the lpLocalName member of the NETRESOURCE structure pointed to by the /// lpNetResource parameter was NULL and the lpRemoteName member of the NETRESOURCE structure pointed to by the lpNetResource was /// also or NULL or could not recognized by any network. /// /// /// /// ERROR_INVALID_ADDRESS /// /// An attempt to access an invalid address. This error is returned if the lpNetResource or lpNetConnectInfoStruct parameters were NULL. /// /// /// /// ERROR_INVALID_PARAMETER /// /// A bad parameter was passed. This error is returned if the lpNetConnectInfoStruct parameter does not point to a /// NETCONNECTINFOSTRUCT structure in which the cbStructure member is filled with the proper structure size. /// /// /// /// ERROR_NO_NETWORK /// The network is unavailable. /// /// /// ERROR_EXTENDED_ERROR /// A network-specific error occurred. To obtain a description of the error, call WNetGetLastError. /// /// /// /// // DWORD MultinetGetConnectionPerformance( _In_ LPNETRESOURCE lpNetResource, _Out_ LPNETCONNECTINFOSTRUCT lpNetConnectInfoStruct); https://msdn.microsoft.com/en-us/library/windows/desktop/aa385342(v=vs.85).aspx [DllImport(Lib.Mpr, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("Winnetwk.h", MSDNShortId = "aa385342")] public static extern uint MultinetGetConnectionPerformance(ref NETRESOURCE lpNetResource, out NETCONNECTINFOSTRUCT lpNetConnectInfoStruct); /// /// The WNetAddConnection function enables the calling application to connect a local device to a network resource. A /// successful connection is persistent, meaning that the system automatically restores the connection during subsequent logon operations. /// /// /// A pointer to a constant null-terminated string that specifies the network resource to connect to. /// /// /// /// A pointer to a constant null-terminated string that specifies the password to be used to make a connection. This parameter /// is usually the password associated with the current user. /// /// If this parameter is NULL, the default password is used. If the string is empty, no password is used. /// Windows Me/98/95: This parameter must be NULL or an empty string. /// /// /// A pointer to a constant null-terminated string that specifies the name of a local device to be redirected, such as "F:" or /// "LPT1". The string is treated in a case-insensitive manner. If the string is NULL, a connection to the network resource is /// made without redirecting the local device. /// /// /// If the function succeeds, the return value is NO_ERROR. /// If the function fails, the return value is a system error code, such as one of the following values. /// /// /// /// Return code /// Description /// /// /// ERROR_ACCESS_DENIED /// The caller does not have access to the network resource. /// /// /// ERROR_ALREADY_ASSIGNED /// The device specified in the lpLocalName parameter is already connected. /// /// /// ERROR_BAD_DEV_TYPE /// The device type and the resource type do not match. /// /// /// ERROR_BAD_DEVICE /// The value specified in the lpLocalName parameter is invalid. /// /// /// ERROR_BAD_NET_NAME /// The value specified in the lpRemoteName parameter is not valid or cannot be located. /// /// /// ERROR_BAD_PROFILE /// The user profile is in an incorrect format. /// /// /// ERROR_CANNOT_OPEN_PROFILE /// The system is unable to open the user profile to process persistent connections. /// /// /// ERROR_DEVICE_ALREADY_REMEMBERED /// An entry for the device specified in the lpLocalName parameter is already in the user profile. /// /// /// ERROR_EXTENDED_ERROR /// A network-specific error occurred. To obtain a description of the error, call the WNetGetLastError function. /// /// /// ERROR_INVALID_PASSWORD /// The specified password is invalid. /// /// /// ERROR_NO_NET_OR_BAD_PATH /// The operation cannot be performed because a network component is not started or because a specified name cannot be used. /// /// /// ERROR_NO_NETWORK /// The network is unavailable. /// /// /// /// // DWORD WNetAddConnection( _In_ LPCTSTR lpRemoteName, _In_ LPCTSTR lpPassword, _In_ LPCTSTR lpLocalName); https://msdn.microsoft.com/en-us/library/windows/desktop/aa385410(v=vs.85).aspx [DllImport(Lib.Mpr, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("Winnetwk.h", MSDNShortId = "aa385410")] public static extern Win32Error WNetAddConnection(string lpRemoteName, string lpPassword, string lpLocalName); /// /// /// The WNetAddConnection2 function makes a connection to a network resource and can redirect a local device to the network resource. /// /// /// The WNetAddConnection2 function supersedes the WNetAddConnection function. If you can pass a handle to a window /// that the provider of network resources can use as an owner window for dialog boxes, call the WNetAddConnection3 function instead. /// /// /// /// /// A pointer to a NETRESOURCE structure that specifies details of the proposed connection, such as information about the /// network resource, the local device, and the network resource provider. /// /// You must specify the following members of the NETRESOURCE structure. /// /// /// /// Member /// Meaning /// /// /// dwType /// /// The type of network resource to connect to. If the lpLocalName member points to a nonempty string, this member can be equal to /// RESOURCETYPE_DISK or RESOURCETYPE_PRINT.If lpLocalName is NULL, or if it points to an empty string, dwType can be equal to /// RESOURCETYPE_DISK, RESOURCETYPE_PRINT, or RESOURCETYPE_ANY.Although this member is required, its information may be ignored by /// the network service provider. /// /// /// /// lpLocalName /// /// A pointer to a null-terminated string that specifies the name of a local device to redirect, such as "F:" or /// "LPT1". The string is treated in a case-insensitive manner.If the string is empty, or if lpLocalName is NULL, /// the function makes a connection to the network resource without redirecting a local device. /// /// /// /// lpRemoteName /// /// A pointer to a null-terminated string that specifies the network resource to connect to. The string can be up to MAX_PATH /// characters in length, and must follow the network provider's naming conventions. /// /// /// /// lpProvider /// /// A pointer to a null-terminated string that specifies the network provider to connect to. If lpProvider is NULL, or if it points /// to an empty string, the operating system attempts to determine the correct provider by parsing the string pointed to by the /// lpRemoteName member.If this member is not NULL, the operating system attempts to make a connection only to the named network /// provider.You should set this member only if you know the network provider you want to use. Otherwise, let the operating system /// determine which provider the network name maps to. /// /// /// /// /// The WNetAddConnection2 function ignores the other members of the NETRESOURCE structure. /// /// /// A pointer to a constant null-terminated string that specifies a password to be used in making the network connection. /// /// If lpPassword is NULL, the function uses the current default password associated with the user specified by the lpUserName parameter. /// /// If lpPassword points to an empty string, the function does not use a password. /// /// If the connection fails because of an invalid password and the CONNECT_INTERACTIVE value is set in the dwFlags parameter, the /// function displays a dialog box asking the user to type the password. /// /// Windows Me/98/95: This parameter must be NULL or an empty string. /// /// /// A pointer to a constant null-terminated string that specifies a user name for making the connection. /// /// If lpUserName is NULL, the function uses the default user name. (The user context for the process provides the default /// user name.) /// /// /// The lpUserName parameter is specified when users want to connect to a network resource for which they have been assigned a user /// name or account other than the default user name or account. /// /// The user-name string represents a security context. It may be specific to a network provider. /// Windows Me/98/95: This parameter must be NULL or an empty string. /// /// /// /// A set of connection options. The possible values for the connection options are defined in the Winnetwk.h header file. The /// following values can currently be used. /// /// /// /// /// Value /// Meaning /// /// /// CONNECT_UPDATE_PROFILE0x00000001 /// /// The network resource connection should be remembered. If this bit flag is set, the operating system automatically attempts to /// restore the connection when the user logs on. The operating system remembers only successful connections that redirect local /// devices. It does not remember connections that are unsuccessful or deviceless connections. (A deviceless connection occurs when /// the lpLocalName member is NULL or points to an empty string.)If this bit flag is clear, the operating system does not try to /// restore the connection when the user logs on. /// /// /// /// CONNECT_UPDATE_RECENT0x00000002 /// /// The network resource connection should not be put in the recent connection list. If this flag is set and the connection is /// successfully added, the network resource connection will be put in the recent connection list only if it has a redirected local /// device associated with it. /// /// /// /// CONNECT_TEMPORARY0x00000004 /// /// The network resource connection should not be remembered. If this flag is set, the operating system will not attempt to restore /// the connection when the user logs on again. /// /// /// /// CONNECT_INTERACTIVE0x00000008 /// If this flag is set, the operating system may interact with the user for authentication purposes. /// /// /// CONNECT_PROMPT0x00000010 /// /// This flag instructs the system not to use any default settings for user names or passwords without offering the user the /// opportunity to supply an alternative. This flag is ignored unless CONNECT_INTERACTIVE is also set. /// /// /// /// CONNECT_REDIRECT0x00000080 /// /// This flag forces the redirection of a local device when making the connection.If the lpLocalName member of NETRESOURCE specifies /// a local device to redirect, this flag has no effect, because the operating system still attempts to redirect the specified /// device. When the operating system automatically chooses a local device, the dwType member must not be equal to /// RESOURCETYPE_ANY.If this flag is not set, a local device is automatically chosen for redirection only if the network requires a /// local device to be redirected.Windows Server 2003 and Windows XP: When the system automatically assigns network drive letters, /// letters are assigned beginning with Z:, then Y:, and ending with C:. This reduces collision between per-logon drive letters (such /// as network drive letters) and global drive letters (such as disk drives). Note that earlier versions of Windows assigned drive /// letters beginning with C: and ending with Z:. /// /// /// /// CONNECT_CURRENT_MEDIA0x00000200 /// /// If this flag is set, then the operating system does not start to use a new media to try to establish the connection (initiate a /// new dial up connection, for example). /// /// /// /// CONNECT_COMMANDLINE0x00000800 /// /// If this flag is set, the operating system prompts the user for authentication using the command line instead of a graphical user /// interface (GUI). This flag is ignored unless CONNECT_INTERACTIVE is also set.Windows XP: This value is supported on Windows XP /// and later. /// /// /// /// CONNECT_CMD_SAVECRED0x00001000 /// /// If this flag is set, and the operating system prompts for a credential, the credential should be saved by the credential manager. /// If the credential manager is disabled for the caller's logon session, or if the network provider does not support saving /// credentials, this flag is ignored. This flag is ignored unless CONNECT_INTERACTIVE is also set. This flag is also ignored unless /// you set the CONNECT_COMMANDLINE flag.Windows XP: This value is supported on Windows XP and later. /// /// /// /// CONNECT_CRED_RESET0x00002000 /// /// If this flag is set, and the operating system prompts for a credential, the credential is reset by the credential manager. If the /// credential manager is disabled for the caller's logon session, or if the network provider does not support saving /// credentials, this flag is ignored. This flag is also ignored unless you set the CONNECT_COMMANDLINE flag.Windows Vista: This /// value is supported on Windows Vista and later. /// /// /// /// /// /// /// If the function succeeds, the return value is NO_ERROR. /// If the function fails, the return value can be one of the following error codes or one of the system error codes. /// /// /// /// Return code /// Description /// /// /// ERROR_ACCESS_DENIED /// The caller does not have access to the network resource. /// /// /// ERROR_ALREADY_ASSIGNED /// The local device specified by the lpLocalName member is already connected to a network resource. /// /// /// ERROR_BAD_DEV_TYPE /// The type of local device and the type of network resource do not match. /// /// /// ERROR_BAD_DEVICE /// /// The specified device name is not valid. This error is returned if the lpLocalName member of the NETRESOURCE structure pointed to /// by the lpNetResource parameter specifies a device that is not redirectable. /// /// /// /// ERROR_BAD_NET_NAME /// /// The network name cannot be found. This value is returned if the lpRemoteName member of the NETRESOURCE structure pointed to by /// the lpNetResource parameter specifies a resource that is not acceptable to any network resource provider, either because the /// resource name is empty, not valid, or because the named resource cannot be located. /// /// /// /// ERROR_BAD_PROFILE /// The user profile is in an incorrect format. /// /// /// ERROR_BAD_PROVIDER /// /// The specified network provider name is not valid. This error is returned if the lpProvider member of the NETRESOURCE structure /// pointed to by the lpNetResource parameter specifies a value that does not match any network provider. /// /// /// /// ERROR_BAD_USERNAME /// The specified user name is not valid. /// /// /// ERROR_BUSY /// The router or provider is busy, possibly initializing. The caller should retry. /// /// /// ERROR_CANCELLED /// /// The attempt to make the connection was canceled by the user through a dialog box from one of the network resource providers, or /// by a called resource. /// /// /// /// ERROR_CANNOT_OPEN_PROFILE /// The system is unable to open the user profile to process persistent connections. /// /// /// ERROR_DEVICE_ALREADY_REMEMBERED /// /// The local device name has a remembered connection to another network resource. This error is returned if an entry for the device /// specified by lpLocalName member of the NETRESOURCE structure pointed to by the lpNetResource parameter specifies a value that is /// already in the user profile for a different connection than that specified in the lpNetResource parameter. /// /// /// /// ERROR_EXTENDED_ERROR /// A network-specific error occurred. Call the WNetGetLastError function to obtain a description of the error. /// /// /// ERROR_INVALID_ADDRESS /// /// An attempt was made to access an invalid address. This error is returned if the dwFlags parameter specifies a value of /// CONNECT_REDIRECT, but the lpLocalName member of the NETRESOURCE structure pointed to by the lpNetResource parameter was unspecified. /// /// /// /// ERROR_INVALID_PARAMETER /// /// A parameter is incorrect. This error is returned if the dwType member of the NETRESOURCE structure pointed to by the /// lpNetResource parameter specifies a value other than RESOURCETYPE_DISK, RESOURCETYPE_PRINT, or RESOURCETYPE_ANY. This error is /// also returned if the dwFlags parameter specifies an incorrect or unknown value. /// /// /// /// ERROR_INVALID_PASSWORD /// The specified password is invalid and the CONNECT_INTERACTIVE flag is not set. /// /// /// ERROR_LOGON_FAILURE /// A logon failure because of an unknown user name or a bad password. /// /// /// ERROR_NO_NET_OR_BAD_PATH /// /// No network provider accepted the given network path. This error is returned if no network provider recognized the lpRemoteName /// member of the NETRESOURCE structure pointed to by the lpNetResource parameter. /// /// /// /// ERROR_NO_NETWORK /// The network is unavailable. /// /// /// Other /// Use FormatMessage to obtain the message string for the returned error. /// /// /// /// // DWORD WNetAddConnection2( _In_ LPNETRESOURCE lpNetResource, _In_ LPCTSTR lpPassword, _In_ LPCTSTR lpUsername, _In_ DWORD dwFlags); https://msdn.microsoft.com/en-us/library/windows/desktop/aa385413(v=vs.85).aspx [DllImport(Lib.Mpr, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("Winnetwk.h", MSDNShortId = "aa385413")] public static extern Win32Error WNetAddConnection2(ref NETRESOURCE lpNetResource, string lpPassword, string lpUsername, CONNECT dwFlags); /// /// /// The WNetAddConnection3 function makes a connection to a network resource. The function can redirect a local device to the /// network resource. /// /// /// The WNetAddConnection3 function is similar to the WNetAddConnection2 function. The main difference is that /// WNetAddConnection3 has an additional parameter, a handle to a window that the provider of network resources can use as an /// owner window for dialog boxes. The WNetAddConnection2 function and the WNetAddConnection3 function supersede the /// WNetAddConnection function. /// /// /// /// /// A handle to a window that the provider of network resources can use as an owner window for dialog boxes. Use this parameter if /// you set the CONNECT_INTERACTIVE value in the dwFlags parameter. /// /// /// The hwndOwner parameter can be NULL. If it is, a call to WNetAddConnection3 is equivalent to calling the /// WNetAddConnection2 function. /// /// /// /// /// A pointer to a NETRESOURCE structure that specifies details of the proposed connection, such as information about the /// network resource, the local device, and the network resource provider. /// /// You must specify the following members of the NETRESOURCE structure. /// /// /// /// Member /// Meaning /// /// /// dwType /// /// The type of network resource to connect to. If the lpLocalName member points to a nonempty string, this member can be equal to /// RESOURCETYPE_DISK or RESOURCETYPE_PRINT.If lpLocalName is NULL, or if it points to an empty string, dwType can be equal to /// RESOURCETYPE_DISK, RESOURCETYPE_PRINT, or RESOURCETYPE_ANY.Although this member is required, its information may be ignored by /// the network service provider. /// /// /// /// lpLocalName /// /// A pointer to a null-terminated string that specifies the name of a local device to redirect, such as "F:" or /// "LPT1". The string is treated in a case-insensitive manner.If the string is empty or if lpLocalName is NULL, /// the function makes a connection to the network resource without redirecting a local device. /// /// /// /// lpRemoteName /// /// A pointer to a null-terminated string that specifies the network resource to connect to. The string can be up to MAX_PATH /// characters in length, and must follow the network provider's naming conventions. /// /// /// /// lpProvider /// /// A pointer to a null-terminated string that specifies the network provider to connect to.If lpProvider is NULL, or if it points to /// an empty string, the operating system attempts to determine the correct provider by parsing the string pointed to by the /// lpRemoteName member.If this member is not NULL, the operating system attempts to make a connection only to the named network /// provider.You should set this member only if you know which network provider you want to use. Otherwise, let the operating system /// determine which network provider the network name maps to. /// /// /// /// /// The WNetAddConnection3 function ignores the other members of the NETRESOURCE structure. /// /// /// A pointer to a null-terminated string that specifies a password to be used in making the network connection. /// /// If lpPassword is NULL, the function uses the current default password associated with the user specified by the lpUserName parameter. /// /// If lpPassword points to an empty string, the function does not use a password. /// /// If the connection fails because of an invalid password and the CONNECT_INTERACTIVE value is set in the dwFlags parameter, the /// function displays a dialog box asking the user to type the password. /// /// Windows Me/98/95: This parameter must be NULL or an empty string. /// /// /// A pointer to a null-terminated string that specifies a user name for making the connection. /// /// If lpUserName is NULL, the function uses the default user name. (The user context for the process provides the default /// user name.) /// /// /// The lpUserName parameter is specified when users want to connect to a network resource for which they have been assigned a user /// name or account other than the default user name or account. /// /// The user-name string represents a security context. It may be specific to a network provider. /// Windows Me/98/95: This parameter must be NULL or an empty string. /// /// /// A set of connection options. The following values are currently defined. /// /// /// /// Value /// Meaning /// /// /// CONNECT_INTERACTIVE /// If this flag is set, the operating system may interact with the user for authentication purposes. /// /// /// CONNECT_PROMPT /// /// This flag instructs the system not to use any default settings for user names or passwords without offering the user the /// opportunity to supply an alternative. This flag is ignored unless CONNECT_INTERACTIVE is also set. /// /// /// /// CONNECT_REDIRECT /// /// This flag forces the redirection of a local device when making the connection. If the lpLocalName member of NETRESOURCE specifies /// a local device to redirect, this flag has no effect, because the operating system still attempts to redirect the specified /// device. When the operating system automatically chooses a local device, the dwType member must not be equal to /// RESOURCETYPE_ANY.If this flag is not set, a local device is automatically chosen for redirection only if the network requires a /// local device to be redirected.Windows Server 2003 and Windows XP: When the system automatically assigns network drive letters, /// letters are assigned beginning with Z:, then Y:, and ending with C:. This reduces collision between per-logon drive letters (such /// as network drive letters) and global drive letters (such as disk drives). Note that earlier versions of Windows assigned drive /// letters beginning with C: and ending with Z:. /// /// /// /// CONNECT_UPDATE_PROFILE /// /// The network resource connection should be remembered.If this bit flag is set, the operating system automatically attempts to /// restore the connection when the user logs on.The operating system remembers only successful connections that redirect local /// devices. It does not remember connections that are unsuccessful or deviceless connections. (A deviceless connection occurs when /// the lpLocalName member is NULL or when it points to an empty string.)If this bit flag is clear, the operating system does not /// automatically restore the connection at logon. /// /// /// /// CONNECT_COMMANDLINE /// /// If this flag is set, the operating system prompts the user for authentication using the command line instead of a graphical user /// interface (GUI). This flag is ignored unless CONNECT_INTERACTIVE is also set.Windows 2000/NT and Windows Me/98/95: This value is /// not supported. /// /// /// /// CONNECT_CMD_SAVECRED /// /// If this flag is set, and the operating system prompts for a credential, the credential should be saved by the credential manager. /// If the credential manager is disabled for the caller's logon session, or if the network provider does not support saving /// credentials, this flag is ignored. This flag is also ignored unless you set the CONNECT_COMMANDLINE flag.Windows 2000/NT and /// Windows Me/98/95: This value is not supported. /// /// /// /// /// /// /// If the function succeeds, the return value is NO_ERROR. /// If the function fails, the return value is a system error code, such as one of the following values. /// /// /// /// Return code /// Description /// /// /// ERROR_ACCESS_DENIED /// The caller does not have access to the network resource. /// /// /// ERROR_ALREADY_ASSIGNED /// The local device specified by the lpLocalName member is already connected to a network resource. /// /// /// ERROR_BAD_DEV_TYPE /// The type of local device and the type of network resource do not match. /// /// /// ERROR_BAD_DEVICE /// The value specified by lpLocalName is invalid. /// /// /// ERROR_BAD_NET_NAME /// /// The value specified by the lpRemoteName member is not acceptable to any network resource provider, either because the resource /// name is invalid, or because the named resource cannot be located. /// /// /// /// ERROR_BAD_PROFILE /// The user profile is in an incorrect format. /// /// /// ERROR_BAD_PROVIDER /// The value specified by the lpProvider member does not match any provider. /// /// /// ERROR_BUSY /// The router or provider is busy, possibly initializing. The caller should retry. /// /// /// ERROR_CANCELLED /// /// The attempt to make the connection was canceled by the user through a dialog box from one of the network resource providers, or /// by a called resource. /// /// /// /// ERROR_CANNOT_OPEN_PROFILE /// The system is unable to open the user profile to process persistent connections. /// /// /// ERROR_DEVICE_ALREADY_REMEMBERED /// An entry for the device specified by the lpLocalName member is already in the user profile. /// /// /// ERROR_EXTENDED_ERROR /// A network-specific error occurred. Call the WNetGetLastError function to obtain a description of the error. /// /// /// ERROR_INVALID_PASSWORD /// The specified password is invalid and the CONNECT_INTERACTIVE flag is not set. /// /// /// ERROR_NO_NET_OR_BAD_PATH /// The operation cannot be performed because a network component is not started or because a specified name cannot be used. /// /// /// ERROR_NO_NETWORK /// The network is unavailable. /// /// /// /// // DWORD WNetAddConnection3( _In_ HWND hwndOwner, _In_ LPNETRESOURCE lpNetResource, _In_ LPTSTR lpPassword, _In_ LPTSTR lpUserName, // _In_ DWORD dwFlags); https://msdn.microsoft.com/en-us/library/windows/desktop/aa385418(v=vs.85).aspx [DllImport(Lib.Mpr, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("Winnetwk.h", MSDNShortId = "aa385418")] public static extern Win32Error WNetAddConnection3(HandleRef hwndOwner, ref NETRESOURCE lpNetResource, string lpPassword, string lpUserName, CONNECT dwFlags); /// /// /// The WNetCancelConnection2 function cancels an existing network connection. You can also call the function to remove /// remembered network connections that are not currently connected. /// /// The WNetCancelConnection2 function supersedes the WNetCancelConnection function. /// /// /// /// Pointer 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. /// /// /// /// Connection type. The following values are defined. /// /// /// /// Value /// Meaning /// /// /// 0 /// /// The system does not update information about the connection. If the connection was marked as persistent in the registry, the /// system continues to restore the connection at the next logon. If the connection was not marked as persistent, the function /// ignores the setting of the CONNECT_UPDATE_PROFILE flag. /// /// /// /// CONNECT_UPDATE_PROFILE /// /// The system updates the user profile with the information that the connection is no longer a persistent one. The system will not /// restore this connection during subsequent logon operations. (Disconnecting resources using remote names has no effect on /// persistent connections.) /// /// /// /// /// /// /// Specifies 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. /// /// /// If the function succeeds, the return value is NO_ERROR. /// If the function fails, the return value is a system error code, such as one of the following values. /// /// /// /// Return code /// Description /// /// /// ERROR_BAD_PROFILE /// The user profile is in an incorrect format. /// /// /// ERROR_CANNOT_OPEN_PROFILE /// The system is unable to open the user profile to process persistent connections. /// /// /// ERROR_DEVICE_IN_USE /// The device is in use by an active process and cannot be disconnected. /// /// /// ERROR_EXTENDED_ERROR /// A network-specific error occurred. To obtain a description of the error, call the WNetGetLastError function. /// /// /// ERROR_NOT_CONNECTED /// /// The name specified by the lpName parameter is not a redirected device, or the system is not currently connected to the device /// specified by the parameter. /// /// /// /// ERROR_OPEN_FILES /// There are open files, and the fForce parameter is FALSE. /// /// /// /// // DWORD WNetCancelConnection2( _In_ LPCTSTR lpName, _In_ DWORD dwFlags, _In_ BOOL fForce); https://msdn.microsoft.com/en-us/library/windows/desktop/aa385427(v=vs.85).aspx [DllImport(Lib.Mpr, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("Winnetwk.h", MSDNShortId = "aa385427")] public static extern Win32Error WNetCancelConnection2(string lpName, CONNECT dwFlags, [MarshalAs(UnmanagedType.Bool)] bool fForce); /// /// The WNetCloseEnum function ends a network resource enumeration started by a call to the WNetOpenEnum function. /// /// /// Handle that identifies an enumeration instance. This handle must be returned by the WNetOpenEnum function. /// /// /// If the function succeeds, the return value is NO_ERROR. /// If the function fails, the return value is a system error code, such as one of the following values. /// /// /// /// Return code /// Description /// /// /// ERROR_NO_NETWORK /// /// The network is unavailable. (This condition is tested before the handle specified in the hEnum parameter is tested for validity.) /// /// /// /// ERROR_INVALID_HANDLE /// The hEnum parameter does not specifiy a valid handle. /// /// /// ERROR_EXTENDED_ERROR /// A network-specific error occurred. To obtain a description of the error, call the WNetGetLastError function. /// /// /// /// // DWORD WNetCloseEnum( _In_ HANDLE hEnum); https://msdn.microsoft.com/en-us/library/windows/desktop/aa385431(v=vs.85).aspx [DllImport(Lib.Mpr, SetLastError = true, ExactSpelling = true)] [PInvokeData("Winnetwk.h", MSDNShortId = "aa385431")] public static extern Win32Error WNetCloseEnum(IntPtr hEnum); /// /// The WNetConnectionDialog function starts a general browsing dialog box for connecting to network resources. The function /// requires a handle to the owner window for the dialog box. /// /// Handle to the owner window for the dialog box. /// /// Resource type to allow connections to. This parameter can be the following value. /// /// /// /// Value /// Meaning /// /// /// RESOURCETYPE_DISK /// Connections to disk resources. /// /// /// /// /// /// If the function succeeds, the return value is NO_ERROR. If the user cancels the dialog box, the function returns –1. /// If the function fails, the return value is a system error code, such as one of the following values. /// /// /// /// Return code /// Description /// /// /// ERROR_EXTENDED_ERROR /// A network-specific error occurred. To obtain a description of the error, call the WNetGetLastError function. /// /// /// ERROR_INVALID_PASSWORD /// The specified password is invalid. /// /// /// ERROR_NO_NETWORK /// The network is unavailable. /// /// /// ERROR_NOT_ENOUGH_MEMORY /// There is insufficient memory to start the dialog box. /// /// /// /// // DWORD WNetConnectionDialog( _In_ HWND hwnd, _In_ DWORD dwType); https://msdn.microsoft.com/en-us/library/windows/desktop/aa385433(v=vs.85).aspx [DllImport(Lib.Mpr, SetLastError = true, ExactSpelling = true)] [PInvokeData("Winnetwk.h", MSDNShortId = "aa385433")] public static extern Win32Error WNetConnectionDialog(HandleRef hwnd, uint dwType); /// /// The WNetConnectionDialog1 function brings up a general browsing dialog for connecting to network resources. The function /// requires a CONNECTDLGSTRUCT to establish the dialog box parameters. /// /// /// Pointer to a CONNECTDLGSTRUCT structure. The structure establishes the browsing dialog parameters. /// /// /// /// If the user cancels the dialog box, the function returns –1. If the function is successful, it returns NO_ERROR. Also, if the /// call is successful, the dwDevNum member of the CONNECTDLGSTRUCT structure contains the number of the connected device. /// /// /// Typically this dialog returns an error only if the user cannot enter a dialog session. This is because errors that occur after a /// dialog session are reported to the user directly. If the function fails, the return value is a system error code, such as one of /// the following values. /// /// /// /// /// Return code /// Description /// /// /// ERROR_INVALID_PARAMETER /// /// Both the CONNDLG_RO_PATH and the CONNDLG_USE_MRU dialog box options are set. (Dialog box options are specified by the dwFlags /// member of the CONNECTDLGSTRUCT structure.) -or-Both the CONNDLG_PERSIST and the CONNDLG_NOT_PERSIST dialog box options are /// set.-or-The CONNDLG_RO_PATH dialog box option is set and the lpRemoteName member of the NETRESOURCE structure does not point to a /// remote network. (The CONNECTDLGSTRUCT structure points to a NETRESOURCE structure.) /// /// /// /// ERROR_BAD_DEV_TYPE /// The dwType member of the NETRESOURCE structure is not set to RESOURCETYPE_DISK. /// /// /// ERROR_BUSY /// The network provider is busy (possibly initializing). The caller should retry. /// /// /// ERROR_NO_NETWORK /// The network is unavailable. /// /// /// ERROR_NOT_ENOUGH_MEMORY /// There is insufficient memory to display the dialog box. /// /// /// ERROR_EXTENDED_ERROR /// A network-specific error occurred. Call WNetGetLastError to obtain a description of the error. /// /// /// /// // DWORD WNetConnectionDialog1( _Inout_ LPCONNECTDLGSTRUCT lpConnDlgStruct); https://msdn.microsoft.com/en-us/library/windows/desktop/aa385436(v=vs.85).aspx [DllImport(Lib.Mpr, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("Winnetwk.h", MSDNShortId = "aa385436")] public static extern Win32Error WNetConnectionDialog1(ref CONNECTDLGSTRUCT lpConnDlgStruct); /// /// The WNetDisconnectDialog function starts a general browsing dialog box for disconnecting from network resources. The /// function requires a handle to the owner window for the dialog box. /// /// Handle to the owner window for the dialog box. /// /// Resource type to disconnect from. This parameter can have the following value. /// /// /// /// Value /// Meaning /// /// /// RESOURCETYPE_DISK /// Disconnects from disk resources. /// /// /// /// /// /// If the function succeeds, the return value is NO_ERROR. If the user cancels the dialog box, the return value is –1. /// If the function fails, the return value is a system error code, such as one of the following values. /// /// /// /// Return code /// Description /// /// /// ERROR_EXTENDED_ERROR /// A network-specific error occurred. To obtain a description of the error, call the WNetGetLastError function. /// /// /// ERROR_NO_NETWORK /// The network is unavailable. /// /// /// ERROR_NOT_ENOUGH_MEMORY /// There is insufficient memory to start the dialog box. /// /// /// /// // DWORD WNetDisconnectDialog( _In_ HWND hwnd, _In_ DWORD dwType); https://msdn.microsoft.com/en-us/library/windows/desktop/aa385440(v=vs.85).aspx [DllImport(Lib.Mpr, SetLastError = true, ExactSpelling = true)] [PInvokeData("Winnetwk.h", MSDNShortId = "aa385440")] public static extern Win32Error WNetDisconnectDialog(HandleRef hwnd, uint dwType); /// /// The WNetDisconnectDialog1 function attempts to disconnect a network resource. If the underlying network returns /// ERROR_OPEN_FILES, the function prompts the user for confirmation. If there is any error, the function informs the user. The /// function requires a DISCDLGSTRUCT to specify the parameters for the disconnect attempt. /// /// /// Pointer to a DISCDLGSTRUCT structure. The structure specifies the behavior for the disconnect attempt. /// /// /// If the function succeeds, the return value is NO_ERROR. If the user cancels the dialog box, the return value is –1. /// If the function fails, the return value is a system error code, such as one of the following values. /// /// /// /// Return code /// Description /// /// /// ERROR_CANCELLED /// When the system prompted the user for a decision about disconnecting, the user elected not to disconnect. /// /// /// ERROR_OPEN_FILES /// Unable to disconnect because the user is actively using the connection. /// /// /// ERROR_BUSY /// The network provider is busy (possibly initializing). The caller should retry. /// /// /// ERROR_NO_NETWORK /// The network is unavailable. /// /// /// ERROR_NOT_ENOUGH_MEMORY /// There is insufficient memory to start the dialog box. /// /// /// ERROR_EXTENDED_ERROR /// A network-specific error occurred. Call the WNetGetLastError function to obtain a description of the error. /// /// /// /// // DWORD WNetDisconnectDialog1( _In_ LPDISCDLGSTRUCT lpConnDlgStruct); https://msdn.microsoft.com/en-us/library/windows/desktop/aa385443(v=vs.85).aspx [DllImport(Lib.Mpr, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("Winnetwk.h", MSDNShortId = "aa385443")] public static extern Win32Error WNetDisconnectDialog1(ref DISCDLGSTRUCT lpConnDlgStruct); /// /// The WNetEnumResource function continues an enumeration of network resources that was started by a call to the /// WNetOpenEnum function. /// /// /// Handle that identifies an enumeration instance. This handle must be returned by the WNetOpenEnum function. /// /// /// /// Pointer to a variable specifying the number of entries requested. If the number requested is –1, the function returns as many /// entries as possible. /// /// /// If the function succeeds, on return the variable pointed to by this parameter contains the number of entries actually read. /// /// /// /// /// Pointer to the buffer that receives the enumeration results. The results are returned as an array of NETRESOURCE /// structures. Note that the buffer you allocate must be large enough to hold the structures, plus the strings to which their /// members point. For more information, see the following Remarks section. /// /// /// The buffer is valid until the next call using the handle specified by the hEnum parameter. The order of NETRESOURCE /// structures in the array is not predictable. /// /// /// /// Pointer to a variable that specifies the size of the lpBuffer parameter, in bytes. If the buffer is too small to receive even one /// entry, this parameter receives the required size of the buffer. /// /// /// If the function succeeds, the return value is one of the following values. /// /// /// /// Return code /// Description /// /// /// NO_ERROR /// /// The enumeration succeeded, and the buffer contains the requested data. The calling application can continue to call /// WNetEnumResource to complete the enumeration. /// /// /// /// ERROR_NO_MORE_ITEMS /// There are no more entries. The buffer contents are undefined. /// /// /// /// If the function fails, the return value is a system error code, such as one of the following values. /// /// /// /// Return code /// Description /// /// /// ERROR_MORE_DATA /// More entries are available with subsequent calls. For more information, see the following Remarks section. /// /// /// ERROR_INVALID_HANDLE /// The handle specified by the hEnum parameter is not valid. /// /// /// ERROR_NO_NETWORK /// The network is unavailable. (This condition is tested before hEnum is tested for validity.) /// /// /// ERROR_EXTENDED_ERROR /// A network-specific error occurred. To obtain a description of the error, call the WNetGetLastError function. /// /// /// /// // DWORD WNetEnumResource( _In_ HANDLE hEnum, _Inout_ LPDWORD lpcCount, _Out_ LPVOID lpBuffer, _Inout_ LPDWORD lpBufferSize); https://msdn.microsoft.com/en-us/library/windows/desktop/aa385449(v=vs.85).aspx [DllImport(Lib.Mpr, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("Winnetwk.h", MSDNShortId = "aa385449")] public static extern Win32Error WNetEnumResource(IntPtr hEnum, ref uint lpcCount, IntPtr lpBuffer, ref uint lpBufferSize); /// The WNetGetConnection function retrieves the name of the network resource associated with a local device. /// /// Pointer to a constant null-terminated string that specifies the name of the local device to get the network name for. /// /// Pointer to a null-terminated string that receives the remote name used to make the connection. /// /// Pointer to a variable that specifies the size of the buffer pointed to by the lpRemoteName parameter, in characters. If the /// function fails because the buffer is not large enough, this parameter returns the required buffer size. /// /// /// If the function succeeds, the return value is NO_ERROR. /// If the function fails, the return value is a system error code, such as one of the following values. /// /// /// /// Return code /// Description /// /// /// ERROR_BAD_DEVICE /// The string pointed to by the lpLocalName parameter is invalid. /// /// /// ERROR_NOT_CONNECTED /// The device specified by lpLocalName is not a redirected device. For more information, see the following Remarks section. /// /// /// ERROR_MORE_DATA /// /// The buffer is too small. The lpnLength parameter points to a variable that contains the required buffer size. More entries are /// available with subsequent calls. /// /// /// /// ERROR_CONNECTION_UNAVAIL /// /// The device is not currently connected, but it is a persistent connection. For more information, see the following Remarks section. /// /// /// /// ERROR_NO_NETWORK /// The network is unavailable. /// /// /// ERROR_EXTENDED_ERROR /// A network-specific error occurred. To obtain a description of the error, call the WNetGetLastError function. /// /// /// ERROR_NO_NET_OR_BAD_PATH /// /// None of the providers recognize the local name as having a connection. However, the network is not available for at least one /// provider to whom the connection may belong. /// /// /// /// /// // DWORD WNetGetConnection( _In_ LPCTSTR lpLocalName, _Out_ LPTSTR lpRemoteName, _Inout_ LPDWORD lpnLength); https://msdn.microsoft.com/en-us/library/windows/desktop/aa385453(v=vs.85).aspx [DllImport(Lib.Mpr, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("Winnetwk.h", MSDNShortId = "aa385453")] public static extern Win32Error WNetGetConnection(string lpLocalName, StringBuilder lpRemoteName, ref uint lpnLength); /// /// The WNetGetLastError function retrieves the most recent extended error code set by a WNet function. The network provider /// reported this error code; it will not generally be one of the errors included in the SDK header file WinError.h. /// /// /// Pointer to a variable that receives the error code reported by the network provider. The error code is specific to the network provider. /// /// Pointer to the buffer that receives the null-terminated string describing the error. /// /// Size of the buffer pointed to by the lpErrorBuf parameter, in characters. If the buffer is too small for the error string, the /// string is truncated but still null-terminated. A buffer of at least 256 characters is recommended. /// /// /// Pointer to the buffer that receives the null-terminated string identifying the network provider that raised the error. /// /// /// Size of the buffer pointed to by the lpNameBuf parameter, in characters. If the buffer is too small for the error string, the /// string is truncated but still null-terminated. /// /// /// 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. /// // DWORD WNetGetLastError( _Out_ LPDWORD lpError, _Out_ LPTSTR lpErrorBuf, _In_ DWORD nErrorBufSize, _Out_ LPTSTR lpNameBuf, _In_ // DWORD nNameBufSize); https://msdn.microsoft.com/en-us/library/windows/desktop/aa385459(v=vs.85).aspx [DllImport(Lib.Mpr, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("Winnetwk.h", MSDNShortId = "aa385459")] public static extern Win32Error WNetGetLastError(out uint lpError, StringBuilder lpErrorBuf, uint nErrorBufSize, StringBuilder lpNameBuf, uint nNameBufSize); /// /// The WNetGetNetworkInformation function returns extended information about a specific network provider whose name was /// returned by a previous network enumeration. /// /// /// Pointer to a constant null-terminated string that contains the name of the network provider for which information is required. /// /// Pointer to a NETINFOSTRUCT structure. The structure describes characteristics of the network. /// /// If the function succeeds, the return value is NO_ERROR. /// If the function fails, the return value is a system error code, such as one of the following values. /// /// /// /// Return code /// Description /// /// /// ERROR_BAD_PROVIDER /// The lpProvider parameter does not match any running network provider. /// /// /// ERROR_BAD_VALUE /// The cbStructure member of the NETINFOSTRUCT structure does not contain a valid structure size. /// /// /// /// // DWORD WNetGetNetworkInformation( _In_ LPCTSTR lpProvider, _Out_ LPNETINFOSTRUCT lpNetInfoStruct); https://msdn.microsoft.com/en-us/library/windows/desktop/aa385461(v=vs.85).aspx [DllImport(Lib.Mpr, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("Winnetwk.h", MSDNShortId = "aa385461")] public static extern Win32Error WNetGetNetworkInformation(string lpProvider, out NETINFOSTRUCT lpNetInfoStruct); /// The WNetGetProviderName function obtains the provider name for a specific type of network. /// /// /// Network type that is unique to the network. If two networks claim the same type, the function returns the name of the provider /// loaded first. Only the high word of the network type is used. If a network reports a subtype in the low word, it is ignored. /// /// You can find a complete list of network types in the header file Winnetwk.h. /// /// Pointer to a buffer that receives the network provider name. /// /// /// Size of the buffer passed to the function, in characters. If the return value is ERROR_MORE_DATA, lpBufferSize returns the buffer /// size required (in characters) to hold the provider name. /// /// /// Windows Me/98/95: The size of the buffer is in bytes, not characters. Also, the buffer must be at least 1 byte long. /// /// /// /// If the function succeeds, the return value is NO_ERROR. /// If the function fails, the return value is a system error code, such as one of the following values. /// /// /// /// Return code /// Description /// /// /// ERROR_MORE_DATA /// The buffer is too small to hold the network provider name. /// /// /// ERROR_NO_NETWORK /// The network is unavailable. /// /// /// ERROR_INVALID_ADDRESS /// The lpProviderName parameter or the lpBufferSize parameter is invalid. /// /// /// /// // DWORD WNetGetProviderName( _In_ DWORD dwNetType, _Out_ LPTSTR lpProviderName, _Inout_ LPDWORD lpBufferSize); https://msdn.microsoft.com/en-us/library/windows/desktop/aa385464(v=vs.85).aspx [DllImport(Lib.Mpr, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("Winnetwk.h", MSDNShortId = "aa385464")] public static extern Win32Error WNetGetProviderName(uint dwNetType, StringBuilder lpProviderName, ref uint lpBufferSize); /// /// When provided with a remote path to a network resource, the WNetGetResourceInformation function identifies the network /// provider that owns the resource and obtains information about the type of the resource. The function is typically used in /// conjunction with the WNetGetResourceParent function to parse and interpret a network path typed in by a user. /// /// /// Pointer to a NETRESOURCE structure that specifies the network resource for which information is required. /// /// The lpRemoteName member of the structure should specify the remote path name of the resource, typically one typed in by a /// user. The lpProvider and dwType members should also be filled in if known, because this operation can be memory /// intensive, especially if you do not specify the dwType member. If you do not know the values for these members, you should /// set them to NULL. All other members of the NETRESOURCE structure are ignored. /// /// /// /// /// Pointer to the buffer to receive the result. On successful return, the first portion of the buffer is a NETRESOURCE /// structure representing that portion of the input resource path that is accessed through the WNet functions, rather than through /// system functions specific to the input resource type. (The remainder of the buffer contains the variable-length strings to which /// the members of the NETRESOURCE structure point.) /// /// /// For example, if the input remote resource path is \\server\share\dir1\dir2, then the output NETRESOURCE structure contains /// information about the resource \\server\share. The \dir1\dir2 portion of the path is accessed through the file management /// functions. The lpRemoteName, lpProvider, dwType, dwDisplayType, and dwUsage members of /// NETRESOURCE are returned, with all other members set to NULL. /// /// /// The lpRemoteName member is returned in the same syntax as the one returned from an enumeration by the /// WNetEnumResource function. This allows the caller to perform a string comparison to determine whether the resource passed /// to WNetGetResourceInformation is the same as the resource returned by a separate call to WNetEnumResource. /// /// /// /// Pointer to a location that, on entry, specifies the size of the lpBuffer buffer, in bytes. The buffer you allocate must be large /// enough to hold the NETRESOURCE structure, plus the strings to which its members point. If the buffer is too small for the /// result, this location receives the required buffer size, and the function returns ERROR_MORE_DATA. /// /// /// /// If the function returns successfully, this parameter points to a string in the output buffer that specifies the part of the /// resource that is accessed through system functions. (This applies only to functions specific to the resource type rather than the /// WNet functions.) /// /// /// For example, if the input remote resource name is \\server\share\dir1\dir2, the lpRemoteName member of the output /// NETRESOURCE structure points to \\server\share. Also, the lplpSystem parameter points to \dir1\dir2. Both strings are /// stored in the buffer pointed to by the lpBuffer parameter. /// /// /// /// If the function succeeds, the return value is NO_ERROR. /// If the function fails, the return value is a system error code, such as one of the following values. /// /// /// /// Return code /// Description /// /// /// ERROR_BAD_NET_NAME /// The input lpRemoteName member is not an existing network resource for any network. /// /// /// ERROR_BAD_DEV_TYPE /// The input dwType member does not match the type of resource specified by the lpRemoteName member. /// /// /// ERROR_EXTENDED_ERROR /// A network-specific error occurred. Call WNetGetLastError to obtain a description of the error. /// /// /// ERROR_MORE_DATA /// The buffer pointed to by the lpBuffer parameter is too small. /// /// /// ERROR_NO_NETWORK /// The network is unavailable. /// /// /// /// // DWORD WNetGetResourceInformation( _In_ LPNETRESOURCE lpNetResource, _Out_ LPVOID lpBuffer, _Inout_ LPDWORD lpcbBuffer, _Out_ // LPTSTR *lplpSystem); https://msdn.microsoft.com/en-us/library/windows/desktop/aa385469(v=vs.85).aspx [DllImport(Lib.Mpr, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("Winnetwk.h", MSDNShortId = "aa385469")] public static extern Win32Error WNetGetResourceInformation(ref NETRESOURCE lpNetResource, IntPtr lpBuffer, ref uint lpcbBuffer, out string lplpSystem); /// /// /// The WNetGetResourceParent function returns the parent of a network resource in the network browse hierarchy. Browsing /// begins at the location of the specified network resource. /// /// /// Call the WNetGetResourceInformation and WNetGetResourceParent functions to move up the network hierarchy. Call the /// WNetOpenEnum function to move down the hierarchy. /// /// /// /// Pointer to a NETRESOURCE structure that specifies the network resource for which the parent name is required. /// /// Specify the members of the input NETRESOURCE structure as follows. The caller typically knows the values to provide for /// the lpProvider and dwType members after previous calls to WNetGetResourceInformation or WNetGetResourceParent. /// /// /// /// /// Member /// Meaning /// /// /// dwType /// This member should be filled in if known; otherwise, it should be set to NULL. /// /// /// lpRemoteName /// This member should specify the remote name of the network resource whose parent is required. /// /// /// lpProvider /// /// This member should specify the network provider that owns the resource. This member is required; otherwise, the function could /// produce incorrect results. /// /// /// /// /// All other members of the NETRESOURCE structure are ignored. /// /// /// /// Pointer to a buffer to receive a single NETRESOURCE structure that represents the parent resource. The function returns /// the lpRemoteName, lpProvider, dwType, dwDisplayType, and dwUsage members of the structure; all /// other members are set to NULL. /// /// /// The lpRemoteName member points to the remote name for the parent resource. This name uses the same syntax as the one /// returned from an enumeration by the WNetEnumResource function. The caller can perform a string comparison to determine /// whether the WNetGetResourceParent resource is the same as that returned by WNetEnumResource. If the input resource /// has no parent on any of the networks, the lpRemoteName member is returned as NULL. /// /// /// The presence of the RESOURCEUSAGE_CONNECTABLE bit in the dwUsage member indicates that you can connect to the parent /// resource, but only when it is available on the network. /// /// /// /// Pointer to a location that, on entry, specifies the size of the lpBuffer buffer, in bytes. If the buffer is too small to hold the /// result, this location receives the required buffer size, and the function returns ERROR_MORE_DATA. /// /// /// If the function succeeds, the return value is NO_ERROR. /// If the function fails, the return value is a system error code, such as one of the following values. /// /// /// /// Return code /// Description /// /// /// ERROR_ACCESS_DENIED /// The caller does not have access to the network resource. /// /// /// ERROR_BAD_NET_NAME /// The input lpRemoteName member is not an existing network resource for any network. /// /// /// ERROR_BAD_PROVIDER /// The input lpProvider member does not match any installed network provider. /// /// /// ERROR_MORE_DATA /// The buffer pointed to by the lpBuffer parameter is too small. /// /// /// ERROR_NOT_AUTHENTICATED /// The caller does not have the necessary permissions to obtain the name of the parent. /// /// /// /// // DWORD WNetGetResourceParent( _In_ LPNETRESOURCE lpNetResource, _Out_ LPVOID lpBuffer, _Inout_ LPDWORD lpcbBuffer); https://msdn.microsoft.com/en-us/library/windows/desktop/aa385470(v=vs.85).aspx [DllImport(Lib.Mpr, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("Winnetwk.h", MSDNShortId = "aa385470")] public static extern Win32Error WNetGetResourceParent(ref NETRESOURCE lpNetResource, IntPtr lpBuffer, ref uint lpcbBuffer); /// /// The WNetGetUniversalName function takes a drive-based path for a network resource and returns an information structure /// that contains a more universal form of the name. /// /// /// A pointer to a constant null-terminated string that is a drive-based path for a network resource. /// /// For example, if drive H has been mapped to a network drive share, and the network resource of interest is a file named Sample.doc /// in the directory \Win32\Examples on that share, the drive-based path is H:\Win32\Examples\Sample.doc. /// /// /// /// /// The type of structure that the function stores in the buffer pointed to by the lpBuffer parameter. This parameter can be one of /// the following values defined in the Winnetwk.h header file. /// /// /// /// /// Value /// Meaning /// /// /// UNIVERSAL_NAME_INFO_LEVEL /// The function stores a UNIVERSAL_NAME_INFO structure in the buffer. /// /// /// REMOTE_NAME_INFO_LEVEL /// The function stores a REMOTE_NAME_INFO structure in the buffer. /// /// /// /// The UNIVERSAL_NAME_INFO structure points to a Universal Naming Convention (UNC) name string. /// /// The REMOTE_NAME_INFO structure points to a UNC name string and two additional connection information strings. For more /// information, see the following Remarks section. /// /// /// A pointer to a buffer that receives the structure specified by the dwInfoLevel parameter. /// /// A pointer to a variable that specifies the size, in bytes, of the buffer pointed to by the lpBuffer parameter. /// /// If the function succeeds, it sets the variable pointed to by lpBufferSize to the number of bytes stored in the buffer. If the /// function fails because the buffer is too small, this location receives the required buffer size, and the function returns ERROR_MORE_DATA. /// /// /// /// If the function succeeds, the return value is NO_ERROR. /// If the function fails, the return value is a system error code, such as one of the following values. /// /// /// /// Return code /// Description /// /// /// ERROR_BAD_DEVICE /// The string pointed to by the lpLocalPath parameter is invalid. /// /// /// ERROR_CONNECTION_UNAVAIL /// There is no current connection to the remote device, but there is a remembered (persistent) connection to it. /// /// /// ERROR_EXTENDED_ERROR /// A network-specific error occurred. Use the WNetGetLastError function to obtain a description of the error. /// /// /// ERROR_MORE_DATA /// /// The buffer pointed to by the lpBuffer parameter is too small. The function sets the variable pointed to by the lpBufferSize /// parameter to the required buffer size. More entries are available with subsequent calls. /// /// /// /// ERROR_NOT_SUPPORTED /// /// The dwInfoLevel parameter is set to UNIVERSAL_NAME_INFO_LEVEL, but the network provider does not support UNC names. (None of the /// network providers support this function.) /// /// /// /// ERROR_NO_NET_OR_BAD_PATH /// /// None of the network providers recognize the local name as having a connection. However, the network is not available for at least /// one provider to whom the connection may belong. /// /// /// /// ERROR_NO_NETWORK /// The network is unavailable. /// /// /// ERROR_NOT_CONNECTED /// The device specified by the lpLocalPath parameter is not redirected. /// /// /// /// // DWORD WNetGetUniversalName( _In_ LPCTSTR lpLocalPath, _In_ DWORD dwInfoLevel, _Out_ LPVOID lpBuffer, _Inout_ LPDWORD // lpBufferSize); https://msdn.microsoft.com/en-us/library/windows/desktop/aa385474(v=vs.85).aspx [DllImport(Lib.Mpr, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("Winnetwk.h", MSDNShortId = "aa385474")] public static extern Win32Error WNetGetUniversalName(string lpLocalPath, INFO_LEVEL dwInfoLevel, IntPtr lpBuffer, ref uint lpBufferSize); /// /// The WNetGetUser function retrieves the current default user name, or the user name used to establish a network connection. /// /// /// /// A pointer to a constant null-terminated string that specifies either the name of a local device that has been redirected /// to a network resource, or the remote name of a network resource to which a connection has been made without redirecting a local device. /// /// If this parameter is NULL or the empty string, the system returns the name of the current user for the process. /// /// A pointer to a buffer that receives the null-terminated user name. /// /// A pointer to a variable that specifies the size of the lpUserName buffer, in characters. If the call fails because the buffer is /// not large enough, this variable contains the required buffer size. /// /// /// If the function succeeds, the return value is NO_ERROR. /// If the function fails, the return value is a system error code, such as one of the following values. /// /// /// /// Return code /// Description /// /// /// ERROR_NOT_CONNECTED /// The device specified by the lpName parameter is not a redirected device or a connected network name. /// /// /// ERROR_MORE_DATA /// More entries are available with subsequent calls. /// /// /// ERROR_NO_NETWORK /// The network is unavailable. /// /// /// ERROR_EXTENDED_ERROR /// A network-specific error occurred. To obtain a description of the error, call the WNetGetLastError function. /// /// /// ERROR_NO_NET_OR_BAD_PATH /// /// None of the providers recognize the local name as having a connection. However, the network is not available for at least one /// provider to whom the connection may belong. /// /// /// /// /// // DWORD WNetGetUser( _In_ LPCTSTR lpName, _Out_ LPTSTR lpUserName, _Inout_ LPDWORD lpnLength); https://msdn.microsoft.com/en-us/library/windows/desktop/aa385476(v=vs.85).aspx [DllImport(Lib.Mpr, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("Winnetwk.h", MSDNShortId = "aa385476")] public static extern Win32Error WNetGetUser(string lpName, StringBuilder lpUserName, ref uint lpnLength); /// /// The WNetOpenEnum function starts an enumeration of network resources or existing connections. You can continue the /// enumeration by calling the WNetEnumResource function. /// /// /// Scope of the enumeration. This parameter can be one of the following values. /// /// /// /// Value /// Meaning /// /// /// RESOURCE_CONNECTED /// /// Enumerate all currently connected resources. The function ignores the dwUsage parameter. For more information, see the following /// Remarks section. /// /// /// /// RESOURCE_CONTEXT /// /// Enumerate only resources in the network context of the caller. Specify this value for a Network Neighborhood view. The function /// ignores the dwUsage parameter. /// /// /// /// RESOURCE_GLOBALNET /// Enumerate all resources on the network. /// /// /// RESOURCE_REMEMBERED /// Enumerate all remembered (persistent) connections. The function ignores the dwUsage parameter. /// /// /// /// /// /// Resource types to be enumerated. This parameter can be a combination of the following values. /// /// /// /// Value /// Meaning /// /// /// RESOURCETYPE_ANY /// All resources. This value cannot be combined with RESOURCETYPE_DISK or RESOURCETYPE_PRINT. /// /// /// RESOURCETYPE_DISK /// All disk resources. /// /// /// RESOURCETYPE_PRINT /// All print resources. /// /// /// /// If a network provider cannot distinguish between print and disk resources, it can enumerate all resources. /// /// /// Resource usage type to be enumerated. This parameter can be a combination of the following values. /// /// /// /// Value /// Meaning /// /// /// 0 /// All resources. /// /// /// RESOURCEUSAGE_CONNECTABLE /// All connectable resources. /// /// /// RESOURCEUSAGE_CONTAINER /// All container resources. /// /// /// RESOURCEUSAGE_ATTACHED /// /// Setting this value forces WNetOpenEnum to fail if the user is not authenticated. The function fails even if the network allows /// enumeration without authentication. /// /// /// /// RESOURCEUSAGE_ALL /// Setting this value is equivalent to setting RESOURCEUSAGE_CONNECTABLE, RESOURCEUSAGE_CONTAINER, and RESOURCEUSAGE_ATTACHED. /// /// /// /// /// This parameter is ignored unless the dwScope parameter is equal to RESOURCE_GLOBALNET. For more information, see the following /// Remarks section. /// /// /// /// /// Pointer to a NETRESOURCE structure that specifies the container to enumerate. If the dwScope parameter is not /// RESOURCE_GLOBALNET, this parameter must be NULL. /// /// /// If this parameter is NULL, the root of the network is assumed. (The system organizes a network as a hierarchy; the root is /// the topmost container in the network.) /// /// /// If this parameter is not NULL, it must point to a NETRESOURCE structure. This structure can be filled in by the /// application or it can be returned by a call to the WNetEnumResource function. The NETRESOURCE structure must /// specify a container resource; that is, the RESOURCEUSAGE_CONTAINER value must be specified in the dwUsage parameter. /// /// /// To enumerate all network resources, an application can begin the enumeration by calling WNetOpenEnum with the /// lpNetResource parameter set to NULL, and then use the returned handle to call WNetEnumResource to enumerate /// resources. If one of the resources in the NETRESOURCE array returned by the WNetEnumResource function is a /// container resource, you can call WNetOpenEnum to open the resource for further enumeration. /// /// /// Pointer to an enumeration handle that can be used in a subsequent call to WNetEnumResource. /// /// If the function succeeds, the return value is NO_ERROR. /// If the function fails, the return value is a system error code, such as one of the following values. /// /// /// /// Return code /// Description /// /// /// ERROR_NOT_CONTAINER /// The lpNetResource parameter does not point to a container. /// /// /// ERROR_INVALID_PARAMETER /// Either the dwScope or the dwType parameter is invalid, or there is an invalid combination of parameters. /// /// /// ERROR_NO_NETWORK /// The network is unavailable. /// /// /// ERROR_EXTENDED_ERROR /// A network-specific error occurred. To obtain a description of the error, call the WNetGetLastError function. /// /// /// ERROR_INVALID_ADDRESS /// A remote network resource name supplied in the NETRESOURCE structure resolved to an invalid network address. /// /// /// /// // DWORD WNetOpenEnum( _In_ DWORD dwScope, _In_ DWORD dwType, _In_ DWORD dwUsage, _In_ LPNETRESOURCE lpNetResource, _Out_ LPHANDLE // lphEnum); https://msdn.microsoft.com/en-us/library/windows/desktop/aa385478(v=vs.85).aspx [DllImport(Lib.Mpr, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("Winnetwk.h", MSDNShortId = "aa385478")] public static extern Win32Error WNetOpenEnum(NETRESOURCEScope dwScope, NETRESOURCEType dwType, NETRESOURCEUsage dwUsage, ref NETRESOURCE lpNetResource, out IntPtr lphEnum); /// /// The WNetOpenEnum function starts an enumeration of network resources or existing connections. You can continue the /// enumeration by calling the WNetEnumResource function. /// /// /// Scope of the enumeration. This parameter can be one of the following values. /// /// /// /// Value /// Meaning /// /// /// RESOURCE_CONNECTED /// /// Enumerate all currently connected resources. The function ignores the dwUsage parameter. For more information, see the following /// Remarks section. /// /// /// /// RESOURCE_CONTEXT /// /// Enumerate only resources in the network context of the caller. Specify this value for a Network Neighborhood view. The function /// ignores the dwUsage parameter. /// /// /// /// RESOURCE_GLOBALNET /// Enumerate all resources on the network. /// /// /// RESOURCE_REMEMBERED /// Enumerate all remembered (persistent) connections. The function ignores the dwUsage parameter. /// /// /// /// /// /// Resource types to be enumerated. This parameter can be a combination of the following values. /// /// /// /// Value /// Meaning /// /// /// RESOURCETYPE_ANY /// All resources. This value cannot be combined with RESOURCETYPE_DISK or RESOURCETYPE_PRINT. /// /// /// RESOURCETYPE_DISK /// All disk resources. /// /// /// RESOURCETYPE_PRINT /// All print resources. /// /// /// /// If a network provider cannot distinguish between print and disk resources, it can enumerate all resources. /// /// /// Resource usage type to be enumerated. This parameter can be a combination of the following values. /// /// /// /// Value /// Meaning /// /// /// 0 /// All resources. /// /// /// RESOURCEUSAGE_CONNECTABLE /// All connectable resources. /// /// /// RESOURCEUSAGE_CONTAINER /// All container resources. /// /// /// RESOURCEUSAGE_ATTACHED /// /// Setting this value forces WNetOpenEnum to fail if the user is not authenticated. The function fails even if the network allows /// enumeration without authentication. /// /// /// /// RESOURCEUSAGE_ALL /// Setting this value is equivalent to setting RESOURCEUSAGE_CONNECTABLE, RESOURCEUSAGE_CONTAINER, and RESOURCEUSAGE_ATTACHED. /// /// /// /// /// This parameter is ignored unless the dwScope parameter is equal to RESOURCE_GLOBALNET. For more information, see the following /// Remarks section. /// /// /// /// /// Pointer to a NETRESOURCE structure that specifies the container to enumerate. If the dwScope parameter is not /// RESOURCE_GLOBALNET, this parameter must be NULL. /// /// /// If this parameter is NULL, the root of the network is assumed. (The system organizes a network as a hierarchy; the root is /// the topmost container in the network.) /// /// /// If this parameter is not NULL, it must point to a NETRESOURCE structure. This structure can be filled in by the /// application or it can be returned by a call to the WNetEnumResource function. The NETRESOURCE structure must /// specify a container resource; that is, the RESOURCEUSAGE_CONTAINER value must be specified in the dwUsage parameter. /// /// /// To enumerate all network resources, an application can begin the enumeration by calling WNetOpenEnum with the /// lpNetResource parameter set to NULL, and then use the returned handle to call WNetEnumResource to enumerate /// resources. If one of the resources in the NETRESOURCE array returned by the WNetEnumResource function is a /// container resource, you can call WNetOpenEnum to open the resource for further enumeration. /// /// /// Pointer to an enumeration handle that can be used in a subsequent call to WNetEnumResource. /// /// If the function succeeds, the return value is NO_ERROR. /// If the function fails, the return value is a system error code, such as one of the following values. /// /// /// /// Return code /// Description /// /// /// ERROR_NOT_CONTAINER /// The lpNetResource parameter does not point to a container. /// /// /// ERROR_INVALID_PARAMETER /// Either the dwScope or the dwType parameter is invalid, or there is an invalid combination of parameters. /// /// /// ERROR_NO_NETWORK /// The network is unavailable. /// /// /// ERROR_EXTENDED_ERROR /// A network-specific error occurred. To obtain a description of the error, call the WNetGetLastError function. /// /// /// ERROR_INVALID_ADDRESS /// A remote network resource name supplied in the NETRESOURCE structure resolved to an invalid network address. /// /// /// /// // DWORD WNetOpenEnum( _In_ DWORD dwScope, _In_ DWORD dwType, _In_ DWORD dwUsage, _In_ LPNETRESOURCE lpNetResource, _Out_ LPHANDLE // lphEnum); https://msdn.microsoft.com/en-us/library/windows/desktop/aa385478(v=vs.85).aspx [DllImport(Lib.Mpr, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("Winnetwk.h", MSDNShortId = "aa385478")] public static extern Win32Error WNetOpenEnum(NETRESOURCEScope dwScope, NETRESOURCEType dwType, NETRESOURCEUsage dwUsage, IntPtr lpNetResource, out IntPtr lphEnum); /// /// Sets extended error information. Network providers should call this function instead of SetLastError. /// /// When necessary, the Multiple Provider Router (MPR) calls SetLastError to set the Windows error returned from a network provider. /// /// /// /// The error that occurred. This is a network-specific error code. /// /// /// String that describes the network-specific error. /// /// /// TBD /// /// /// This function does not return a value. /// /// /// This function is implemented by the Windows operating system and can be called by network providers. /// /// A provider should use this function to report errors that contain provider-specific information. The error information is saved /// until it is overwritten by another call to WNetSetLastError in the same thread. /// /// The recommended way for a provider function to handle general errors is to use the following statement. /// /// In this statement, providerError is a Windows error code, such as one of the return codes listed for the provider API in this document. /// /// For provider-specific errors, a provider should do the following. /// In this case, providerError is the provider-specific error code. /// /// Providers do not need to call SetLastError before returning from a provider function. The MPR calls SetLastError to set /// the Windows error returned from a provider when necessary to satisfy applications. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/npapi/nf-npapi-wnetsetlasterrora void WNetSetLastErrorA( DWORD err, LPSTR // lpError, LPSTR lpProviders ); [DllImport(Lib.Mpr, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("npapi.h", MSDNShortId = "ee472f01-de44-4c47-9ae5-8bbac74de78b")] public static extern void WNetSetLastError(uint err, string lpError, string lpProviders); /// /// /// The WNetUseConnection function makes a connection to a network resource. The function can redirect a local device to a /// network resource. /// /// /// The WNetUseConnection function is similar to the WNetAddConnection3 function. The main difference is that /// WNetUseConnection can automatically select an unused local device to redirect to the network resource. /// /// /// /// Handle to a window that the provider of network resources can use as an owner window for dialog boxes. Use this parameter if you /// set the CONNECT_INTERACTIVE value in the dwFlags parameter. /// /// /// /// Pointer to a NETRESOURCE structure that specifies details of the proposed connection. The structure contains information /// about the network resource, the local device, and the network resource provider. /// /// You must specify the following members of the NETRESOURCE structure. /// /// /// /// Member /// Meaning /// /// /// dwType /// /// Specifies the type of resource to connect to. It is most efficient to specify a resource type in this member, such as /// RESOURCETYPE_DISK or RESOURCETYPE_PRINT. However, if the lpLocalName member is NULL, or if it points to an empty string and /// CONNECT_REDIRECT is not set, dwType can be RESOURCETYPE_ANY.This method works only if the function does not automatically choose /// a device to redirect to the network resource.Although this member is required, its information may be ignored by the network /// service provider. /// /// /// /// lpLocalName /// /// Pointer to a null-terminated string that specifies the name of a local device to be redirected, such as "F:" or /// "LPT1". The string is treated in a case-insensitive manner. If the string is empty, or if lpLocalName is NULL, /// a connection to the network occurs without redirection.If the CONNECT_REDIRECT value is set in the dwFlags parameter, or if the /// network requires a redirected local device, the function chooses a local device to redirect and returns the name of the device in /// the lpAccessName parameter. /// /// /// /// lpRemoteName /// /// Pointer to a null-terminated string that specifies the network resource to connect to. The string can be up to MAX_PATH /// characters in length, and it must follow the network provider's naming conventions. /// /// /// /// lpProvider /// /// Pointer to a null-terminated string that specifies the network provider to connect to. If lpProvider is NULL, or if it points to /// an empty string, the operating system attempts to determine the correct provider by parsing the string pointed to by the /// lpRemoteName member. If this member is not NULL, the operating system attempts to make a connection only to the named network /// provider.You should set this member only if you know the network provider you want to use. Otherwise, let the operating system /// determine which provider the network name maps to. /// /// /// /// /// /// The WNetUseConnection function ignores the other members of the NETRESOURCE structure. For more information, see /// the descriptions following for the dwFlags parameter. /// /// /// /// Pointer to a constant null-terminated string that specifies a password to be used in making the network connection. /// If lpPassword is NULL, the function uses the current default password associated with the user specified by lpUserID. /// If lpPassword points to an empty string, the function does not use a password. /// /// If the connection fails because of an invalid password and the CONNECT_INTERACTIVE value is set in the dwFlags parameter, the /// function displays a dialog box asking the user to type the password. /// /// /// /// Pointer to a constant null-terminated string that specifies a user name for making the connection. /// /// If lpUserID is NULL, the function uses the default user name. (The user context for the process provides the default user name.) /// /// /// The lpUserID parameter is specified when users want to connect to a network resource for which they have been assigned a user /// name or account other than the default user name or account. /// /// The user-name string represents a security context. It may be specific to a network provider. /// /// /// Set of bit flags describing the connection. This parameter can be any combination of the following values. /// /// /// /// Value /// Meaning /// /// /// CONNECT_INTERACTIVE /// If this flag is set, the operating system may interact with the user for authentication purposes. /// /// /// CONNECT_PROMPT /// /// This flag instructs the system not to use any default settings for user names or passwords without offering the user the /// opportunity to supply an alternative. This flag is ignored unless CONNECT_INTERACTIVE is also set. /// /// /// /// CONNECT_REDIRECT /// /// This flag forces the redirection of a local device when making the connection. If the lpLocalName member of NETRESOURCE specifies /// a local device to redirect, this flag has no effect, because the operating system still attempts to redirect the specified /// device. When the operating system automatically chooses a local device, the dwType member must not be equal to /// RESOURCETYPE_ANY.If this flag is not set, a local device is automatically chosen for redirection only if the network requires a /// local device to be redirected.Windows XP: When the system automatically assigns network drive letters, letters are assigned /// beginning with Z:, then Y:, and ending with C:. This reduces collision between per-logon drive letters (such as network drive /// letters) and global drive letters (such as disk drives). Note that previous releases assigned drive letters beginning with C: and /// ending with Z:. /// /// /// /// CONNECT_UPDATE_PROFILE /// /// This flag instructs the operating system to store the network resource connection. If this bit flag is set, the operating system /// automatically attempts to restore the connection when the user logs on. The system remembers only successful connections that /// redirect local devices. It does not remember connections that are unsuccessful or deviceless connections. (A deviceless /// connection occurs when lpLocalName is NULL or when it points to an empty string.)If this bit flag is clear, the operating system /// does not automatically restore the connection at logon. /// /// /// /// CONNECT_COMMANDLINE /// /// If this flag is set, the operating system prompts the user for authentication using the command line instead of a graphical user /// interface (GUI). This flag is ignored unless CONNECT_INTERACTIVE is also set.Windows 2000/NT and Windows Me/98/95: This value is /// not supported. /// /// /// /// CONNECT_CMD_SAVECRED /// /// If this flag is set, and the operating system prompts for a credential, the credential should be saved by the credential manager. /// If the credential manager is disabled for the caller's logon session, or if the network provider does not support saving /// credentials, this flag is ignored. This flag is also ignored unless you set the CONNECT_COMMANDLINE flag.Windows 2000/NT and /// Windows Me/98/95: This value is not supported. /// /// /// /// /// /// /// Pointer to a buffer that receives system requests on the connection. This parameter can be NULL. /// /// If this parameter is specified, and the lpLocalName member of the NETRESOURCE structure specifies a local device, /// this buffer receives the local device name. If lpLocalName does not specify a device and the network requires a local /// device redirection, or if the CONNECT_REDIRECT value is set, this buffer receives the name of the redirected local device. /// /// /// Otherwise, the name copied into the buffer is that of a remote resource. If specified, this buffer must be at least as large as /// the string pointed to by the lpRemoteName member. /// /// /// /// Pointer 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 location. For more information, see the descriptions of /// the lpAccessName parameter and the ERROR_MORE_DATA error code in the Return Values section. /// /// /// Pointer to a variable that receives additional information about the connection. This parameter can be the following value. /// /// /// /// Value /// Meaning /// /// /// CONNECT_LOCALDRIVE /// /// If this flag is set, the connection was made using a local device redirection. If the lpAccessName parameter points to a buffer, /// the local device name is copied to the buffer. /// /// /// /// /// /// /// If the function succeeds, the return value is NO_ERROR. /// If the function fails, the return value is a system error code, such as one of the following values. /// /// /// /// Return code /// Description /// /// /// ERROR_ACCESS_DENIED /// The caller does not have access to the network resource. /// /// /// ERROR_ALREADY_ASSIGNED /// The local device specified by the lpLocalName member is already connected to a network resource. /// /// /// ERROR_BAD_DEVICE /// The value specified by lpLocalName is invalid. /// /// /// ERROR_BAD_NET_NAME /// /// The value specified by the lpRemoteName member is not acceptable to any network resource provider because the resource name is /// invalid, or because the named resource cannot be located. /// /// /// /// ERROR_BAD_PROVIDER /// The value specified by the lpProvider member does not match any provider. /// /// /// ERROR_CANCELLED /// /// The attempt to make the connection was canceled by the user through a dialog box from one of the network resource providers, or /// by a called resource. /// /// /// /// ERROR_EXTENDED_ERROR /// A network-specific error occurred. To obtain a description of the error, call the WNetGetLastError function. /// /// /// ERROR_INVALID_ADDRESS /// The caller passed in a pointer to a buffer that could not be accessed. /// /// /// ERROR_INVALID_PARAMETER /// This error is a result of one of the following conditions: /// /// /// ERROR_INVALID_PASSWORD /// The specified password is invalid and the CONNECT_INTERACTIVE flag is not set. /// /// /// ERROR_MORE_DATA /// /// The lpAccessName buffer is too small. If a local device is redirected, the buffer needs to be large enough to contain the local /// device name. Otherwise, the buffer needs to be large enough to contain either the string pointed to by lpRemoteName, or the name /// of the connectable resource whose alias is pointed to by lpRemoteName. If this error is returned, then no connection has been made. /// /// /// /// ERROR_NO_MORE_ITEMS /// The operating system cannot automatically choose a local redirection because all the valid local devices are in use. /// /// /// ERROR_NO_NET_OR_BAD_PATH /// /// The operation could not be completed, either because a network component is not started, or because the specified resource name /// is not recognized. /// /// /// /// ERROR_NO_NETWORK /// The network is unavailable. /// /// /// /// // DWORD WNetUseConnection( _In_ HWND hwndOwner, _In_ LPNETRESOURCE lpNetResource, _In_ LPCTSTR lpPassword, _In_ LPCTSTR lpUserID, // _In_ DWORD dwFlags, _Out_ LPTSTR lpAccessName, _Inout_ LPDWORD lpBufferSize, _Out_ LPDWORD lpResult); https://msdn.microsoft.com/en-us/library/windows/desktop/aa385482(v=vs.85).aspx [DllImport(Lib.Mpr, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("Winnetwk.h", MSDNShortId = "aa385482")] public static extern Win32Error WNetUseConnection(HandleRef hwndOwner, ref NETRESOURCE lpNetResource, string lpPassword, string lpUserID, CONNECT dwFlags, StringBuilder lpAccessName, ref uint lpBufferSize, out uint lpResult); /// /// The CONNECTDLGSTRUCT structure is used by the WNetConnectionDialog1 function to establish browsing dialog box parameters. /// // typedef struct { DWORD cbStructure; HWND hwndOwner; LPNETRESOURCE lpConnRes; DWORD dwFlags; DWORD dwDevNum;} CONNECTDLGSTRUCT, // *LPCONNECTDLGSTRUCT; https://msdn.microsoft.com/en-us/library/windows/desktop/aa385332(v=vs.85).aspx [PInvokeData("Winnetwk.h", MSDNShortId = "aa385332")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct CONNECTDLGSTRUCT { /// /// Type: DWORD /// The size, in bytes, of the CONNECTDLGSTRUCT structure. The caller must supply this value. /// public uint cbStructure; /// /// Type: HWND /// The handle to the owner window for the dialog box. /// public IntPtr hwndOwner; /// /// Type: LPNETRESOURCE /// A pointer to a NETRESOURCE structure. /// /// If the lpRemoteName member of NETRESOURCE is specified, it will be entered into the path field of the dialog /// box. With the exception of the dwType member, all other members of the NETRESOURCE structure must be set to /// NULL. The dwType member must be equal to RESOURCETYPE_DISK. /// /// The system does not support the RESOURCETYPE_PRINT flag for browsing and connecting to print resources. /// public IntPtr lpConnRes; /// /// Type: DWORD /// /// A set of bit flags that describe options for the dialog box display. This member can be a combination of the following values. /// /// /// /// /// Value /// Meaning /// /// /// SidTypeUser /// The account is a user account. /// /// /// CONNDLG_RO_PATH /// /// Display a read-only path instead of allowing the user to type in a path. This flag should be set only if the lpRemoteName /// member of the NETRESOURCE structure pointed to by lpConnRes member is not NULL (or an empty string), and the CONNDLG_USE_MRU /// flag is not set. /// /// /// /// CONNDLG_CONN_POINT /// Internal flag. Do not use. /// /// /// CONNDLG_USE_MRU /// Enter the most recently used paths into the combination box. Set this value to simulate the WNetConnectionDialog function. /// /// /// CONNDLG_HIDE_BOX /// Show the check box allowing the user to restore the connection at logon. /// /// /// CONNDLG_PERSIST /// Restore the connection at logon. /// /// /// CONNDLG_NOT_PERSIST /// Do not restore the connection at logon. /// /// /// /// For more information, see the following Remarks section. /// public CONN_DLG dwFlags; /// /// Type: DWORD /// /// If the call to the WNetConnectionDialog1 function is successful, this member returns the number of the connected /// device. The value is 1 for A:, 2 for B:, 3 for C:, and so on. If the user made a deviceless connection, the value is –1. /// /// public uint dwDevNum; } /// /// The DISCDLGSTRUCT structure is used in the WNetDisconnectDialog1 function. The structure contains required /// information for the disconnect attempt. /// // typedef struct _DISCDLGSTRUCT { DWORD cbStructure; HWND hwndOwner; LPTSTR lpLocalName; LPTSTR lpRemoteName; DWORD dwFlags;} // DISCDLGSTRUCT, *LPDISCDLGSTRUCT; https://msdn.microsoft.com/en-us/library/windows/desktop/aa385339(v=vs.85).aspx [PInvokeData("Winnetwk.h", MSDNShortId = "aa385339")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct DISCDLGSTRUCT { /// /// Type: DWORD /// The size, in bytes, of the DISCDLGSTRUCT structure. The caller must supply this value. /// public uint cbStructure; /// /// Type: HWND /// A handle to the owner window of the dialog box. /// public IntPtr hwndOwner; /// /// Type: LPTSTR /// /// A pointer to a NULL-terminated string that specifies the local device name that is redirected to the network resource, /// such as "F:" or "LPT1". /// /// public string lpLocalName; /// /// Type: LPTSTR /// /// A pointer to a NULL-terminated string that specifies the name of the network resource to disconnect. This member can /// be NULL if the lpLocalName member is specified. When lpLocalName is specified, the connection to the network /// resource redirected from lpLocalName is disconnected. /// /// public string lpRemoteName; /// /// Type: DWORD /// A set of bit flags describing the connection. This member can be a combination of the following values. /// /// /// /// Value /// Meaning /// /// /// DISC_UPDATE_PROFILE /// /// If this value is set, the specified connection is no longer a persistent one (automatically restored every time the user logs /// on). This flag is valid only if the lpLocalName member specifies a local device. /// /// /// /// DISC_NO_FORCE /// /// If this value is not set, the system applies force when attempting to disconnect from the network resource. This situation /// typically occurs when the user has files open over the connection. This value means that the user will be informed if there /// are open files on the connection, and asked if he or she still wants to disconnect. If the user wants to proceed, the /// disconnect procedure re-attempts with additional force. /// /// /// /// /// public uint dwFlags; } /// /// The NETCONNECTINFOSTRUCT structure contains information about the expected performance of a connection used to access a /// network resource. The information is returned by the MultinetGetConnectionPerformance function. /// // typedef struct _NETCONNECTINFOSTRUCT { DWORD cbStructure; DWORD dwFlags; DWORD dwSpeed; DWORD dwDelay; DWORD dwOptDataSize;} // NETCONNECTINFOSTRUCT, *LPNETCONNECTINFOSTRUCT; https://msdn.microsoft.com/en-us/library/windows/desktop/aa385345(v=vs.85).aspx [PInvokeData("Winnetwk.h", MSDNShortId = "aa385345")] [StructLayout(LayoutKind.Sequential)] public struct NETCONNECTINFOSTRUCT { /// /// Type: DWORD /// The size, in bytes, of the NETCONNECTINFOSTRUCT structure. The caller must supply this value. /// public uint cbStructure; /// /// Type: DWORD /// A set of bit flags describing the connection. This member can be one or more of the following values. /// /// /// /// Value /// Meaning /// /// /// WNCON_FORNETCARD /// /// In the absence of information about the actual connection, the information returned applies to the performance of the network /// card. If this flag is not set, information is being returned for the current connection with the resource, with any routing /// degradation taken into consideration. /// /// /// /// WNCON_NOTROUTED /// /// The connection is not being routed. If this flag is not set, the connection may be going through routers that limit /// performance. Consequently, if WNCON_FORNETCARD is set, actual performance may be much less than the information returned. /// /// /// /// WNCON_SLOWLINK /// /// The connection is over a medium that is typically slow (for example, over a modem using a normal quality phone line). You /// should not set the WNCON_SLOWLINK bit if the dwSpeed member is set to a nonzero value. /// /// /// /// WNCON_DYNAMIC /// /// Some of the information returned is calculated dynamically, so reissuing this request may return different (and more current) information. /// /// /// /// /// public WNCON dwFlags; /// /// Type: DWORD /// Speed of the media to the network resource, in 100 bits-per-second (bps). /// /// For example, a 1200 baud point-to-point link returns 12. A value of zero indicates that no information is available. A value /// of one indicates that the actual value is greater than the maximum that can be represented by the member. /// /// public uint dwSpeed; /// /// Type: DWORD /// /// One-way delay time that the network introduces when sending information, in milliseconds. (The delay is the time between when /// the network begins sending data and the time that the data starts being received.) This delay is in addition to any latency /// incorporated in the calculation of the dwSpeed member; therefore the value of this member is zero for most resources. /// /// /// A value of zero indicates that no information is available. A value of one indicates that the actual value is greater than /// the maximum that can be represented by the member. /// /// public uint dwDelay; /// /// Type: DWORD /// Size of data that an application should use when making a single request to the network resource, in bytes. /// /// For example, for a disk network resource, this value might be 2048 or 512 when writing a block of data. A value of zero /// indicates that no information is available. /// /// public uint dwOptDataSize; } /// /// The NETINFOSTRUCT structure contains information describing the network provider returned by the /// WNetGetNetworkInformation function. /// // typedef struct _NETINFOSTRUCT { DWORD cbStructure; DWORD dwProviderVersion; DWORD dwStatus; DWORD dwCharacteristics; ULONG_PTR // dwHandle; WORD wNetType; DWORD dwPrinters; DWORD dwDrives;} NETINFOSTRUCT, *LPNETINFOSTRUCT; https://msdn.microsoft.com/en-us/library/windows/desktop/aa385349(v=vs.85).aspx [PInvokeData("Winnetwk.h", MSDNShortId = "aa385349")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct NETINFOSTRUCT { /// /// Type: DWORD /// /// The size, in bytes, of the NETINFOSTRUCT structure. The caller must supply this value to indicate the size of the /// structure passed in. Upon return, it has the size of the structure filled in. /// /// public uint cbStructure; /// /// Type: DWORD /// The version number of the network provider software. /// public uint dwProviderVersion; /// /// Type: DWORD /// The current status of the network provider software. This member can be one of the following values. /// /// /// /// Value /// Meaning /// /// /// NO_ERROR /// The network is running. /// /// /// ERROR_NO_NETWORK /// The network is unavailable. /// /// /// ERROR_BUSY /// /// The network is not currently able to service requests, but it should become available shortly. (This value typically /// indicates that the network is starting up.) /// /// /// /// /// public Win32Error dwStatus; /// /// Type: DWORD /// Characteristics of the network provider software. This value is zero. /// Windows Me/98/95: This member can be one or more of the following values. /// /// /// /// Value /// Meaning /// /// /// NETINFO_DLL16 /// The network provider is running as a 16-bit Windows network driver. /// /// /// NETINFO_DISKRED /// The network provider requires a redirected local disk drive device to access server file systems. /// /// /// NETINFO_PRINTERRED /// The network provider requires a redirected local printer port to access server file systems. /// /// /// /// public NETINFO dwCharacteristics; /// /// Type: ULONG_PTR /// An instance handle for the network provider or for the 16-bit Windows network driver. /// public IntPtr dwHandle; /// /// Type: WORD /// /// The network type unique to the running network. This value associates resources with a specific network when the resources /// are persistent or stored in links. You can find a complete list of network types in the header file Winnetwk.h. /// /// public ushort wNetType; /// /// Type: DWORD /// /// A set of bit flags indicating the valid print numbers for redirecting local printer devices, with the low-order bit /// corresponding to LPT1. /// /// Windows Me/98/95: This value is always set to –1. /// public uint dwPrinters; /// /// Type: DWORD /// /// A set of bit flags indicating the valid local disk devices for redirecting disk drives, with the low-order bit corresponding /// to A:. /// /// Windows Me/98/95: This value is always set to –1. /// public uint dwDrives; } /// The NETRESOURCE structure contains information about a network resource. // typedef struct _NETRESOURCE { DWORD dwScope; DWORD dwType; DWORD dwDisplayType; DWORD dwUsage; LPTSTR lpLocalName; LPTSTR // lpRemoteName; LPTSTR lpComment; LPTSTR lpProvider;} NETRESOURCE; https://msdn.microsoft.com/en-us/library/windows/desktop/aa385353(v=vs.85).aspx [PInvokeData("Winnetwk.h", MSDNShortId = "aa385353")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct NETRESOURCE { /// The scope of the enumeration. public NETRESOURCEScope dwScope; /// The type of resource. public NETRESOURCEType dwType; /// The display options for the network object in a network browsing user interface. public NETRESOURCEDisplayType dwDisplayType; /// /// A set of bit flags describing how the resource can be used. Note that this member can be specified only if the dwScope member /// is equal to RESOURCE_GLOBALNET. /// public NETRESOURCEUsage dwUsage; /// /// If the dwScope member is equal to RESOURCE_CONNECTED or RESOURCE_REMEMBERED, this member is a pointer to a null-terminated /// character string that specifies the name of a local device. This member is NULL if the connection does not use a device. /// public StrPtrAuto lpLocalName; /// /// If the entry is a network resource, this member is a pointer to a null-terminated character string that specifies the remote /// network name. /// /// If the entry is a current or persistent connection, lpRemoteName member points to the network name associated with the name /// pointed to by the lpLocalName member. /// /// The string can be MAX_PATH characters in length, and it must follow the network provider's naming conventions. /// public StrPtrAuto lpRemoteName; /// A pointer to a NULL-terminated string that contains a comment supplied by the network provider. public StrPtrAuto lpComment; /// /// A pointer to a NULL-terminated string that contains the name of the provider that owns the resource. This member can be NULL /// if the provider name is unknown. To retrieve the provider name, you can call the WNetGetProviderName function. /// public StrPtrAuto lpProvider; } /// /// The REMOTE_NAME_INFO structure contains path and name information for a network resource. The structure contains a member /// that points to a Universal Naming Convention (UNC) name string for the resource, and two members that point to additional network /// connection information strings. /// // typedef struct _REMOTE_NAME_INFO { LPTSTR lpUniversalName; LPTSTR lpConnectionName; LPTSTR lpRemainingPath;} REMOTE_NAME_INFO; https://msdn.microsoft.com/en-us/library/windows/desktop/aa385366(v=vs.85).aspx [PInvokeData("Winnetwk.h", MSDNShortId = "aa385366")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct REMOTE_NAME_INFO { /// Pointer to the null-terminated UNC name string that identifies a network resource. public string lpUniversalName; /// /// Pointer to a null-terminated string that is the name of a network connection. For more information, see the following Remarks section. /// public string lpConnectionName; /// Pointer to a null-terminated name string. For more information, see the following Remarks section. public string lpRemainingPath; } /// /// The UNIVERSAL_NAME_INFO structure contains a pointer to a Universal Naming Convention (UNC) name string for a network resource. /// // typedef struct _UNIVERSAL_NAME_INFO { LPTSTR lpUniversalName;} UNIVERSAL_NAME_INFO; https://msdn.microsoft.com/en-us/library/windows/desktop/aa385379(v=vs.85).aspx [PInvokeData("Winnetwk.h", MSDNShortId = "aa385379")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct UNIVERSAL_NAME_INFO { /// Pointer to the null-terminated UNC name string that identifies a network resource. public string lpUniversalName; } } }