using System; using System.Runtime.InteropServices; namespace Vanara.PInvoke { /// Functions, structures and constants from ws2_32.h. public static partial class Ws2_32 { /// /// The WSCWriteNameSpaceOrder function changes the order of available Windows Sockets (Winsock) 2 namespace providers. The /// order of the namespace providers determines the priority of the namespace when enumerated or queried for name resolution. /// /// /// An array of NSProviderId elements as found in the WSANAMESPACE_INFOstructure. The order of the NSProviderId /// elements is the new priority ordering for the namespace providers. /// /// The number of elements in the NSProviderId array. /// /// /// The function returns ERROR_SUCCESS (zero) if the routine is successful. Otherwise, it returns a specific error code. /// /// /// /// Error code /// Meaning /// /// /// WSAEFAULT /// The NSProviderId array is not fully contained within process address space. /// /// /// WSAEINVAL /// One or more of the arguments are input parameters were invalid, no action was taken. /// /// /// WSANO_RECOVERY /// /// A nonrecoverable error occurred. This error is returned under several conditions including the following: the user lacks the /// administrative privileges required to write to the Winsock registry or another application is currently writing to the namespace /// provider catalog. /// /// /// /// WSASYSCALLFAILURE /// A system call that should never fail has failed. /// /// /// WSATRY_AGAIN /// The function is called by another thread or process. /// /// /// WSA_NOT_ENOUGH_MEMORY /// Insufficient memory was available to perform the operation. /// /// /// (other) /// The function may return any registry error code. /// /// /// /// /// /// Namespace providers are installed using the WSCInstallNameSpace function. The order in which namespace providers are initially /// installed governs the default order in which they are enumerated through WSAEnumNameSpaceProviders. More importantly, this order /// also governs the order in which namespace providers are considered when a client requests name resolution. The order of /// namespace providers can be changed using the WSCWriteNameSpaceOrder function. On 64-bit platforms, the /// WSCWriteNameSpaceOrder32 function is provided to allow 64-bit processes to change the order of namespace providers in the 32-bit /// namespace provider catalog. On 64-bit platforms, namespace providers are installed in the 32-bit namespace provider catalog /// using the WSCInstallNameSpace32 function. /// /// /// The current namespace provider catalog is stored in the registry under the following registry key: /// HKEY_LOCAL_MACHINE<b>SYSTEM<b>Current Control Set<b>Services<b>Winsock2<b>Parameters<b>NameSpace_Catalog5 /// /// /// A client request for name resolution uses the WSALookupServiceBegin, WSALookupServiceNext, and WSALookupServiceEnd routines. The /// dwNameSpace member of the WSAQUERYSET structure passed to WSALookupServiceBegin is set to the identifier of a /// single namespace (NS_DNS, for example) in which to constrain the search, or NS_ALL to include all namespaces. If multiple /// namespace providers support a specific namespace ( NS_DNS, for example), then the results from all namespace providers /// that match the requested dwNameSpace are returned unless the lpNSProviderId member is set to a specific namespace /// provider. The results from all namespace providers is returned if NS_ALL is specified for the dwNameSpace member. The /// order that the results are returned is dependent on the namespace provider order in the catalog. /// /// /// The Windows SDK includes an application called SpOrder.exe that allows the catalog of installed namespace providers to be /// displayed. Windows Sockets 2 includes the ws2_32.dll that exports the WSCWriteNameSpaceOrder function for reordering /// namespace providers in the catalog. This interface can be imported by linking with WS2_32.lib. For computers running on Windows /// XP with Service Pack 2 (SP2) and Windows Server 2003 with Service Pack 1 (SP1) and later, the netsh.exe winsock show /// catalog command will display both the protocol and namespace providers installed on the system. /// /// /// WSCWriteNameSpaceOrder can only be called by a user logged on as a member of the Administrators group. If /// WSCWriteNameSpaceOrder is called by a user that is not a member of the Administrators group, the function call will fail /// and WSANO_RECOVERY is returned in the lpErrno parameter. /// /// /// For computers running on Windows Vista and Windows Vista, this function can also fail because of user account control (UAC). If /// an application that contains this function is executed by a user logged on as a member of the Administrators group other than /// the Administrator, this call will fail unless the application has been marked in the manifest file with a /// requestedExecutionLevel set to requireAdministrator. If the application on Windows Vista and Windows Vista lacks /// this setting in the manifest file used to build the executable file, a user logged on as a member of the Administrators group /// other than the Administrator must then be executing the application in an enhanced shell as the Administrator ( RunAs /// administrator) for this function to succeed. /// /// The following list describes scenarios in which the WSCWriteNameSpaceOrder function could fail: /// /// /// The dwNumberOfEntries parameter is not equal to the number of registered namespace providers. /// /// /// The NSProviderId array contains an invalid namespace provider identifier. /// /// /// The NSProviderId array does not contain all valid namespace provider identifiers exactly one time. /// /// /// The function cannot access the registry (for example, insufficient user permissions). /// /// /// Another process (or thread) is currently calling the function. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/sporder/nf-sporder-wscwritenamespaceorder int WSCWriteNameSpaceOrder( IN // LPGUID lpProviderId, IN DWORD dwNumberOfEntries ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("sporder.h", MSDNShortId = "00a06104-570f-4cd5-9520-bc73516ac7a5")] public static extern int WSCWriteNameSpaceOrder([In, MarshalAs(UnmanagedType.LPArray)] Guid[] lpProviderId, [In] uint dwNumberOfEntries); /// /// The WSCWriteNameSpaceOrder32 function changes the order of available Windows Sockets (Winsock) 2 namespace providers in a /// 32-bit catalog. The order of the namespace providers determines the priority of the namespace when enumerated or queried for /// name resolution. /// /// /// An array of NSProviderId elements as found in the WSANAMESPACE_INFOstructure. The order of the NSProviderId /// elements is the new priority ordering for the namespace providers. /// /// The number of elements in the NSProviderId array. /// /// /// The function returns ERROR_SUCCESS (zero) if the routine is successful. Otherwise, it returns a specific error code. /// /// /// /// Error code /// Meaning /// /// /// WSAEFAULT /// The NSProviderId array is not fully contained within process address space. /// /// /// WSAEINVAL /// Input parameters were invalid, no action was taken. /// /// /// WSANO_RECOVERY /// /// A nonrecoverable error occurred. This error is returned under several conditions including the following: the Winsock registry /// could not be opened, the user lacks the administrative privileges required to write to the Winsock registry, or another /// application is currently writing to the namespace provider catalog. /// /// /// /// WSASYSCALLFAILURE /// A system call that should never fail has failed. /// /// /// WSATRY_AGAIN /// The function is called by another thread or process. /// /// /// WSA_NOT_ENOUGH_MEMORY /// Insufficient memory was available to perform the operation. /// /// /// (other) /// The function may return any registry error code. /// /// /// /// /// /// Namespace providers are installed on 64-bit platforms in a 32-bit namespace provider catalog using the WSCInstallNameSpace32 /// function. The order in which namespace providers in a 32-bit catalog are initially installed governs the default order in which /// they are enumerated through WSCEnumNameSpaceProviders32. More importantly, this order also governs the order in which namespace /// providers are considered when a client requests name resolution. On 64-bit platforms, the WSCWriteNameSpaceOrder32 /// function is provided to allow 64-bit processes to change the order of namespace providers in the 32-bit namespace provider /// catalog. The order of namespace providers in the native catalog can be changed using the WSCWriteNameSpaceOrder function. /// /// /// The current namespace provider catalog is stored in the registry under the following registry key: /// HKEY_LOCAL_MACHINE<b>SYSTEM<b>Current Control Set<b>Services<b>Winsock2<b>Parameters<b>NameSpace_Catalog5 /// /// /// A client request for name resolution uses the WSALookupServiceBegin, WSALookupServiceNext, and WSALookupServiceEnd routines. The /// dwNameSpace member of the WSAQUERYSET structure passed to WSALookupServiceBegin is set to the identifier of a /// single namespace ( NS_DNS, for example) in which to constrain the search, or NS_ALL to include all namespaces. If /// multiple namespace providers support a specific namespace (for example, NS_DNS), then the results from all namespace /// providers that match the requested dwNameSpace are returned unless the lpNSProviderId member is set to a specific /// namespace provider. The results from all namespace providers is returned if NS_ALL is specified for the /// dwNameSpace member. The order that the results are returned depends on the namespace provider order in the catalog. /// /// /// The Windows SDK includes an application called SpOrder.exe that allows the catalog of installed namespace providers to be /// displayed. Winsock 2 includes the ws2_32.DLL on 64-bit platforms that exports the WSCWriteNameSpaceOrder32 function for /// reordering namespace providers in the 32-bit namespace provider catalog. This interface can be imported by linking with /// WS2_32.lib. For computers running on Windows XP with Service Pack 2 (SP2) and Windows Server 2003 with Service Pack 1 (SP1) and /// later, the netsh.exe winsock show catalog command will display both the protocol and namespace providers installed. The /// native 64-bit catalog is displayed first followed by the 32-bit provider catalogs (denoted with a 32 after their name). /// /// /// WSCWriteNameSpaceOrder32 can only be called by a user logged on as a member of the Administrators group. If /// WSCWriteNameSpaceOrder32 is called by a user that is not a member of the Administrators group, the function call will /// fail and WSANO_RECOVERY is returned in the lpErrno parameter. /// /// /// For computers running on Windows Vista and Windows Vista, this function can also fail because of user account control (UAC). If /// an application that contains this function is executed by a user logged on as a member of the Administrators group other than /// the Administrator, this call will fail unless the application has been marked in the manifest file with a /// requestedExecutionLevel set to requireAdministrator. If the application on Windows Vista and Windows Vista lacks /// this setting in the manifest file used to build the executable file, a user logged on as a member of the Administrators group /// other than the Administrator must then be executing the application in an enhanced shell as the Administrator ( RunAs /// administrator) for this function to succeed. /// /// The following list describes scenarios in which the WSCWriteNameSpaceOrder32 function could fail: /// /// /// The dwNumberOfEntries parameter is not equal to the number of registered namespace providers. /// /// /// The NSProviderId array contains an invalid namespace provider identifier. /// /// /// The NSProviderId array does not contain all valid namespace provider identifiers exactly one time. /// /// /// The function is not able to access the registry for some reason (insufficient user permissions, for example). /// /// /// Another process, or thread, is currently calling the function. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/sporder/nf-sporder-wscwritenamespaceorder32 int WSCWriteNameSpaceOrder32( IN // LPGUID lpProviderId, IN DWORD dwNumberOfEntries ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("sporder.h", MSDNShortId = "a5b15d28-8137-42bf-8f2a-7c6b5a8a63c2")] public static extern int WSCWriteNameSpaceOrder32([In, MarshalAs(UnmanagedType.LPArray)] Guid[] lpProviderId, [In] uint dwNumberOfEntries); /// /// The WSCWriteProviderOrder function is used to reorder the available transport providers. The order of the protocols /// determines the priority of a protocol when being enumerated or selected for use. /// /// /// A pointer to an array of CatalogEntryId elements found in the WSAPROTOCOL_INFO structure. The order of the /// CatalogEntryId elements is the new priority ordering for the protocols. /// /// The number of elements in the lpwdCatalogEntryId array. /// /// /// The function returns ERROR_SUCCESS (zero) if the routine is successful. Otherwise, it returns a specific error code. /// /// /// /// Error code /// Meaning /// /// /// WSAEINVAL /// One or more of the arguments are invalid, no action was taken. /// /// /// WSANO_RECOVERY /// /// A nonrecoverable error occurred. This error is returned under several conditions including the following: the user lacks the /// administrative privileges required to write to the Winsock registry, or a failure occurred when opening or writing a catalog entry. /// /// /// /// WSA_NOT_ENOUGH_MEMORY /// /// Insufficient memory was available. This error is returned when there is insufficient memory to allocate a new catalog entry. /// /// /// /// (other) /// The routine may return any registry error code. /// /// /// /// /// /// The order in which transport service providers are initially installed governs the order in which they are enumerated through /// WSCEnumProtocols at the service provider interface, or through WSAEnumProtocols at the application interface. More importantly, /// this order also governs the order in which protocols and service providers are considered when a client requests creation of a /// socket based on its address family, type, and protocol identifier. /// /// /// Windows Sockets 2 includes an application called Sporder.exe that allows the catalog of installed protocols to be reordered /// interactively after protocols have already been installed. Windows Sockets 2 also includes an auxiliary DLL, Sporder.dll that /// exports this procedural interface for reordering protocols. This interface can be imported by linking with Sporder.lib. /// /// The following are scenarios in which the WSCWriteProviderOrder function could fail: /// /// /// The dwNumberOfEntries parameter is not equal to the number of registered service providers. /// /// /// The lpwdCatalogEntryId contains an invalid catalog identifier. /// /// /// The lpwdCatalogEntryId does not contain all valid catalog identifiers exactly one time. /// /// /// The routine is not able to access the registry for some reason (for example, inadequate user permissions). /// /// /// Another process (or thread) is currently calling the function. /// /// /// /// On success, WSCWriteProviderOrder will attempt to alert all interested applications that have registered for notification /// of the change by calling WSAProviderConfigChange. /// /// /// The WSCWriteProviderOrder function can only be called by a user logged on as a member of the Administrators group. If /// WSCWriteProviderOrder is called by a user that is not a member of the Administrators group, the function call will fail /// and WSANO_RECOVERY is returned. For computers running on Windows Vista or Windows Server 2008, this function can also fail /// because of user account control (UAC). If an application that contains this function is executed by a user logged on as a member /// of the Administrators group other than the built-in Administrator, this call will fail unless the application has been marked in /// the manifest file with a requestedExecutionLevel set to requireAdministrator. If the application on Windows Vista /// or Windows Server 2008 lacks this manifest file, a user logged on as a member of the Administrators group other than the /// built-in Administrator must then be executing the application in an enhanced shell as the built-in Administrator ( RunAs /// administrator) for this function to succeed. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/sporder/nf-sporder-wscwriteproviderorder int WSCWriteProviderOrder( IN LPDWORD // lpwdCatalogEntryId, IN DWORD dwNumberOfEntries ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("sporder.h", MSDNShortId = "459a2fc9-fa05-4ebc-8cc7-3f4915b4b800")] public static extern int WSCWriteProviderOrder([In, MarshalAs(UnmanagedType.LPArray)] uint[] lpwdCatalogEntryId, [In] uint dwNumberOfEntries); /// /// /// The WSCWriteProviderOrder32 function is used to reorder the available 32-bit transport providers. The order of the /// protocols determines the priority of a protocol when being enumerated or selected for use. /// /// /// Note This call is a strictly 32-bit version of WSCWriteProviderOrder for use on 64-bit platforms. It is provided to allow /// 64-bit processes to modify the 32-bit catalogs. /// /// /// /// A pointer to an array of CatalogEntryId elements found in the WSAPROTOCOL_INFO structure. The order of the /// CatalogEntryId elements is the new priority ordering for the protocols. /// /// The number of elements in the lpwdCatalogEntryId array. /// /// /// The function returns ERROR_SUCCESS (zero) if the routine is successful. Otherwise, it returns a specific error code. /// /// /// /// Error code /// Meaning /// /// /// WSAEINVAL /// One or more of the arguments are invalid, no action was taken. /// /// /// WSANO_RECOVERY /// /// A nonrecoverable error occurred. This error is returned under several conditions including the following: the user lacks the /// administrative privileges required to write to the Winsock registry, or a failure occurred when opening or writing a catalog entry. /// /// /// /// WSA_NOT_ENOUGH_MEMORY /// /// Insufficient memory was available. This error is returned when there is insufficient memory to allocate a new catalog entry. /// /// /// /// (other) /// The routine may return any registry error code. /// /// /// /// /// /// The WSCWriteProviderOrder32 function is a strictly 32-bit version of the WSCWriteProviderOrder function. On a 64-bit /// computer, all calls not specifically 32-bit (for example, all functions that do not end in "32") operate on the native 64-bit /// catalog. Processes that execute on a 64-bit computer must use the specific 32-bit function calls to operate on a strictly 32-bit /// catalog and preserve compatibility. The definitions and semantics of the specific 32-bit calls are the same as their native counterparts. /// /// /// The order in which transport service providers are initially installed governs the order in which they are enumerated through /// WSCEnumProtocols32 at the service provider interface, or through WSAEnumProtocols at the application interface. More /// importantly, this order also governs the order in which protocols and service providers are considered when a client requests /// creation of a socket based on its address family, type, and protocol identifier. /// /// /// Windows Sockets 2 includes an application called Sporder.exe that allows the catalog of installed protocols to be reordered /// interactively after protocols have already been installed. Windows Sockets 2 also includes an auxiliary DLL, Sporder.dll that /// exports this procedural interface for reordering protocols. This interface can be imported by linking with Sporder.lib. /// /// The following are scenarios in which the WSCWriteProviderOrder32 function could fail: /// /// /// The dwNumberOfEntries parameter is not equal to the number of registered service providers. /// /// /// The lpwdCatalogEntryId contains an invalid catalog identifier. /// /// /// The lpwdCatalogEntryId does not contain all valid catalog identifiers exactly one time. /// /// /// The routine is not able to access the registry for some reason (for example, inadequate user permissions). /// /// /// Another process (or thread) is currently calling the function. /// /// /// /// On success, WSCWriteProviderOrder32 will attempt to alert all interested applications that have registered for /// notification of the change by calling WSAProviderConfigChange. /// /// /// The WSCWriteProviderOrder32 function can only be called by a user logged on as a member of the Administrators group. If /// WSCWriteProviderOrder32 is called by a user that is not a member of the Administrators group, the function call will fail /// and WSANO_RECOVERY is returned. For computers running on Windows Vista or Windows Server 2008, this function can also fail /// because of user account control (UAC). If an application that contains this function is executed by a user logged on as a member /// of the Administrators group other than the built-in Administrator, this call will fail unless the application has been marked in /// the manifest file with a requestedExecutionLevel set to requireAdministrator. If the application on Windows Vista /// or Windows Server 2008 lacks this manifest file, a user logged on as a member of the Administrators group other than the /// built-in Administrator must then be executing the application in an enhanced shell as the built-in Administrator ( RunAs /// administrator) for this function to succeed. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/sporder/nf-sporder-wscwriteproviderorder32 int WSCWriteProviderOrder32( IN // LPDWORD lpwdCatalogEntryId, IN DWORD dwNumberOfEntries ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("sporder.h", MSDNShortId = "03ce09b4-d80e-480d-9219-d226df055f18")] public static extern int WSCWriteProviderOrder32([In, MarshalAs(UnmanagedType.LPArray)] uint[] lpwdCatalogEntryId, [In] uint dwNumberOfEntries); } }