diff --git a/PInvoke/NetApi32/CorrelationReport.md b/PInvoke/NetApi32/CorrelationReport.md index 3369ed57..c5ad2b1c 100644 --- a/PInvoke/NetApi32/CorrelationReport.md +++ b/PInvoke/NetApi32/CorrelationReport.md @@ -1,19 +1,24 @@ ## Correlation report for netapi32.dll -### Methods (14% complete) +### Methods (52% complete) Native Method | Native DLL | Header | Managed Method --- | --- | --- | --- -[DavAddConnection](https://www.google.com/search?num=5&q=DavAddConnection+site%3Amicrosoft.com) | netapi32.dll | | -[DavDeleteConnection](https://www.google.com/search?num=5&q=DavDeleteConnection+site%3Amicrosoft.com) | netapi32.dll | | -[DavFlushFile](https://www.google.com/search?num=5&q=DavFlushFile+site%3Amicrosoft.com) | netapi32.dll | | -[DavGetExtendedError](https://www.google.com/search?num=5&q=DavGetExtendedError+site%3Amicrosoft.com) | netapi32.dll | | -[DavGetHTTPFromUNCPath](https://www.google.com/search?num=5&q=DavGetHTTPFromUNCPath+site%3Amicrosoft.com) | netapi32.dll | | -[DavGetUNCFromHTTPPath](https://www.google.com/search?num=5&q=DavGetUNCFromHTTPPath+site%3Amicrosoft.com) | netapi32.dll | | +[DavAddConnection](http://msdn2.microsoft.com/en-us/library/d69cba04-503c-4d21-b762-3094c0921e28) | netapi32.dll | davclnt.h | Vanara.PInvoke.NetApi32.DavAddConnection +[DavCancelConnectionsToServer](http://msdn2.microsoft.com/en-us/library/6eb3b011-4cd3-45ec-a07e-c8743d35a176) | netapi32.dll | davclnt.h | Vanara.PInvoke.NetApi32.DavCancelConnectionsToServer +[DavDeleteConnection](http://msdn2.microsoft.com/en-us/library/736b8a16-30db-410e-8295-97730297d04b) | netapi32.dll | davclnt.h | Vanara.PInvoke.NetApi32.DavDeleteConnection +[DavFlushFile](http://msdn2.microsoft.com/en-us/library/0022a5ba-a4b2-4289-91be-db7f52e62f91) | netapi32.dll | davclnt.h | Vanara.PInvoke.NetApi32.DavFlushFile +[DavGetExtendedError](http://msdn2.microsoft.com/en-us/library/939b6163-b7ae-4ab7-9bcc-a02cbf34ca63) | netapi32.dll | davclnt.h | Vanara.PInvoke.NetApi32.DavGetExtendedError +[DavGetHTTPFromUNCPath](http://msdn2.microsoft.com/en-us/library/caa83e54-a029-45aa-9681-26b2be54fea3) | netapi32.dll | davclnt.h | Vanara.PInvoke.NetApi32.DavGetHTTPFromUNCPath +[DavGetTheLockOwnerOfTheFile](http://msdn2.microsoft.com/en-us/library/94a4607c-2770-4656-8710-987d6b951e0e) | netapi32.dll | davclnt.h | Vanara.PInvoke.NetApi32.DavGetTheLockOwnerOfTheFile +[DavGetUNCFromHTTPPath](http://msdn2.microsoft.com/en-us/library/e9613e4a-5ba1-4954-bc7a-7843249f031e) | netapi32.dll | davclnt.h | Vanara.PInvoke.NetApi32.DavGetUNCFromHTTPPath +[DavInvalidateCache](http://msdn2.microsoft.com/en-us/library/f111b19c-5472-463a-b33d-7d2188d224e8) | netapi32.dll | davclnt.h | Vanara.PInvoke.NetApi32.DavInvalidateCache +[DavRegisterAuthCallback](http://msdn2.microsoft.com/en-us/library/7b381929-174f-4b7b-aa22-dc7a2c3e3b4d) | netapi32.dll | davclnt.h | Vanara.PInvoke.NetApi32.DavRegisterAuthCallback +[DavUnregisterAuthCallback](http://msdn2.microsoft.com/en-us/library/5277d9ce-22e6-49d5-9a9c-c02993605bdf) | netapi32.dll | davclnt.h | Vanara.PInvoke.NetApi32.DavUnregisterAuthCallback [DsAddressToSiteNames](http://msdn2.microsoft.com/en-us/library/4d70dbee-be33-4d2a-a200-3696443fa853) | netapi32.dll | dsgetdc.h | Vanara.PInvoke.NetApi32.DsAddressToSiteNames [DsAddressToSiteNamesEx](http://msdn2.microsoft.com/en-us/library/60ac6195-6e43-46da-a1e6-74ec989cd0c4) | netapi32.dll | dsgetdc.h | Vanara.PInvoke.NetApi32.DsAddressToSiteNamesEx [DsDeregisterDnsHostRecords](http://msdn2.microsoft.com/en-us/library/18ab6455-dab2-42d9-b68e-a8f0ad2d8091) | netapi32.dll | dsgetdc.h | Vanara.PInvoke.NetApi32.DsDeregisterDnsHostRecords [DsEnumerateDomainTrusts](http://msdn2.microsoft.com/en-us/library/6c3b788f-ee53-4637-acdb-04316e8464fe) | netapi32.dll | dsgetdc.h | Vanara.PInvoke.NetApi32.DsEnumerateDomainTrusts [DsGetDcCloseW](http://msdn2.microsoft.com/en-us/library/d193e4cd-ad66-4d93-b912-348f17e93a6f) | netapi32.dll | dsgetdc.h | Vanara.PInvoke.NetApi32.DsGetDcClose -[DsGetDcName](http://msdn2.microsoft.com/en-us/library/ms675983) | netapi32.dll | DsGetDC.h | Vanara.PInvoke.NetApi32.DsGetDcName +[DsGetDcName](http://msdn2.microsoft.com/en-us/library/da8b2983-5e45-40b0-b552-c9b3a1d8ae94) | netapi32.dll | dsgetdc.h | Vanara.PInvoke.NetApi32.DsGetDcName [DsGetDcNext](http://msdn2.microsoft.com/en-us/library/2906772f-4391-411b-b0a9-5a20ebb6c0ee) | netapi32.dll | dsgetdc.h | Vanara.PInvoke.NetApi32.DsGetDcNext [DsGetDcOpen](http://msdn2.microsoft.com/en-us/library/2811cc30-f367-4f1a-8f0c-ed0a77dad24c) | netapi32.dll | dsgetdc.h | Vanara.PInvoke.NetApi32.DsGetDcOpen [DsGetDcSiteCoverage](http://msdn2.microsoft.com/en-us/library/e0f757d9-36b6-40f8-a1db-fb5b9862b46a) | netapi32.dll | dsgetdc.h | Vanara.PInvoke.NetApi32.DsGetDcSiteCoverage @@ -29,23 +34,17 @@ Native Method | Native DLL | Header | Managed Method [NetAccessGetInfo](https://www.google.com/search?num=5&q=NetAccessGetInfo+site%3Amicrosoft.com) | netapi32.dll | | [NetAccessGetUserPerms](https://www.google.com/search?num=5&q=NetAccessGetUserPerms+site%3Amicrosoft.com) | netapi32.dll | | [NetAccessSetInfo](https://www.google.com/search?num=5&q=NetAccessSetInfo+site%3Amicrosoft.com) | netapi32.dll | | -[NetAddAlternateComputerName](https://www.google.com/search?num=5&q=NetAddAlternateComputerName+site%3Amicrosoft.com) | netapi32.dll | | +[NetAddAlternateComputerName](http://msdn2.microsoft.com/en-us/library/710865c6-e327-439c-931d-de8674d69233) | netapi32.dll | lmjoin.h | Vanara.PInvoke.NetApi32.NetAddAlternateComputerName [NetAddServiceAccount](https://www.google.com/search?num=5&q=NetAddServiceAccount+site%3Amicrosoft.com) | netapi32.dll | | -[NetAlertRaise](https://www.google.com/search?num=5&q=NetAlertRaise+site%3Amicrosoft.com) | netapi32.dll | | -[NetAlertRaiseEx](https://www.google.com/search?num=5&q=NetAlertRaiseEx+site%3Amicrosoft.com) | netapi32.dll | | -[NetApiBufferAllocate](https://www.google.com/search?num=5&q=NetApiBufferAllocate+site%3Amicrosoft.com) | netapi32.dll | | +[NetAlertRaise](http://msdn2.microsoft.com/en-us/library/11367a72-c21d-4044-98cf-a7a30cc43a8b) | netapi32.dll | lmalert.h | Vanara.PInvoke.NetApi32.NetAlertRaise +[NetAlertRaiseEx](http://msdn2.microsoft.com/en-us/library/9762f0d6-0022-4e05-b2d8-6223d7bbb2c8) | netapi32.dll | lmalert.h | Vanara.PInvoke.NetApi32.NetAlertRaiseEx +[NetApiBufferAllocate](http://msdn2.microsoft.com/en-us/library/9ff1e3eb-9417-469f-a8c0-cdcda3cd9583) | netapi32.dll | lmapibuf.h | Vanara.PInvoke.NetApi32.NetApiBufferAllocate [NetApiBufferFree](http://msdn2.microsoft.com/en-us/library/aa370304) | netapi32.dll | lm.h | Vanara.PInvoke.NetApi32.NetApiBufferFree -[NetApiBufferReallocate](https://www.google.com/search?num=5&q=NetApiBufferReallocate+site%3Amicrosoft.com) | netapi32.dll | | -[NetApiBufferSize](https://www.google.com/search?num=5&q=NetApiBufferSize+site%3Amicrosoft.com) | netapi32.dll | | -[NetAuditClear](https://www.google.com/search?num=5&q=NetAuditClear+site%3Amicrosoft.com) | netapi32.dll | | -[NetAuditRead](https://www.google.com/search?num=5&q=NetAuditRead+site%3Amicrosoft.com) | netapi32.dll | | -[NetAuditWrite](https://www.google.com/search?num=5&q=NetAuditWrite+site%3Amicrosoft.com) | netapi32.dll | | +[NetApiBufferReallocate](http://msdn2.microsoft.com/en-us/library/61153de0-33d3-4c83-a8aa-a7179252328c) | netapi32.dll | lmapibuf.h | Vanara.PInvoke.NetApi32.NetApiBufferReallocate +[NetApiBufferSize](http://msdn2.microsoft.com/en-us/library/0c28feeb-00a3-4ad5-b85f-96326515fae2) | netapi32.dll | lmapibuf.h | Vanara.PInvoke.NetApi32.NetApiBufferSize [Netbios](https://www.google.com/search?num=5&q=Netbios+site%3Amicrosoft.com) | netapi32.dll | | -[NetConfigGet](https://www.google.com/search?num=5&q=NetConfigGet+site%3Amicrosoft.com) | netapi32.dll | | -[NetConfigGetAll](https://www.google.com/search?num=5&q=NetConfigGetAll+site%3Amicrosoft.com) | netapi32.dll | | -[NetConfigSet](https://www.google.com/search?num=5&q=NetConfigSet+site%3Amicrosoft.com) | netapi32.dll | | -[NetConnectionEnum](https://www.google.com/search?num=5&q=NetConnectionEnum+site%3Amicrosoft.com) | netapi32.dll | | -[NetCreateProvisioningPackage](https://www.google.com/search?num=5&q=NetCreateProvisioningPackage+site%3Amicrosoft.com) | netapi32.dll | | +[NetConnectionEnum](http://msdn2.microsoft.com/en-us/library/935ac6e9-78e0-42ae-a454-0a14b03ddc21) | netapi32.dll | lmshare.h | Vanara.PInvoke.NetApi32.NetConnectionEnum +[NetCreateProvisioningPackage](http://msdn2.microsoft.com/en-us/library/6E2A5578-8308-41E2-B5E9-5E34E9E76C0B) | netapi32.dll | lmjoin.h | Vanara.PInvoke.NetApi32.NetCreateProvisioningPackage [NetDfsAdd](https://www.google.com/search?num=5&q=NetDfsAdd+site%3Amicrosoft.com) | netapi32.dll | | [NetDfsAddFtRoot](https://www.google.com/search?num=5&q=NetDfsAddFtRoot+site%3Amicrosoft.com) | netapi32.dll | | [NetDfsAddRootTarget](https://www.google.com/search?num=5&q=NetDfsAddRootTarget+site%3Amicrosoft.com) | netapi32.dll | | @@ -69,21 +68,18 @@ Native Method | Native DLL | Header | Managed Method [NetDfsSetInfo](https://www.google.com/search?num=5&q=NetDfsSetInfo+site%3Amicrosoft.com) | netapi32.dll | | [NetDfsSetSecurity](https://www.google.com/search?num=5&q=NetDfsSetSecurity+site%3Amicrosoft.com) | netapi32.dll | | [NetDfsSetStdContainerSecurity](https://www.google.com/search?num=5&q=NetDfsSetStdContainerSecurity+site%3Amicrosoft.com) | netapi32.dll | | -[NetEnumerateComputerNames](https://www.google.com/search?num=5&q=NetEnumerateComputerNames+site%3Amicrosoft.com) | netapi32.dll | | +[NetEnumerateComputerNames](http://msdn2.microsoft.com/en-us/library/c657ae33-404e-4c36-a956-5fbcfa540be7) | netapi32.dll | lmjoin.h | Vanara.PInvoke.NetApi32.NetEnumerateComputerNames [NetEnumerateServiceAccounts](https://www.google.com/search?num=5&q=NetEnumerateServiceAccounts+site%3Amicrosoft.com) | netapi32.dll | | -[NetErrorLogClear](https://www.google.com/search?num=5&q=NetErrorLogClear+site%3Amicrosoft.com) | netapi32.dll | | -[NetErrorLogRead](https://www.google.com/search?num=5&q=NetErrorLogRead+site%3Amicrosoft.com) | netapi32.dll | | -[NetErrorLogWrite](https://www.google.com/search?num=5&q=NetErrorLogWrite+site%3Amicrosoft.com) | netapi32.dll | | -[NetFileClose](https://www.google.com/search?num=5&q=NetFileClose+site%3Amicrosoft.com) | netapi32.dll | | -[NetFileEnum](https://www.google.com/search?num=5&q=NetFileEnum+site%3Amicrosoft.com) | netapi32.dll | | -[NetFileGetInfo](https://www.google.com/search?num=5&q=NetFileGetInfo+site%3Amicrosoft.com) | netapi32.dll | | -[NetFreeAadJoinInformation](https://www.google.com/search?num=5&q=NetFreeAadJoinInformation+site%3Amicrosoft.com) | netapi32.dll | | -[NetGetAadJoinInformation](https://www.google.com/search?num=5&q=NetGetAadJoinInformation+site%3Amicrosoft.com) | netapi32.dll | | +[NetFileClose](http://msdn2.microsoft.com/en-us/library/36a5f464-fec3-4b4f-91c3-447ff5ff70af) | netapi32.dll | lmshare.h | Vanara.PInvoke.NetApi32.NetFileClose +[NetFileEnum](http://msdn2.microsoft.com/en-us/library/1375b337-efb0-4be1-94f7-473456a825b5) | netapi32.dll | lmshare.h | Vanara.PInvoke.NetApi32.NetFileEnum +[NetFileGetInfo](http://msdn2.microsoft.com/en-us/library/d50c05e7-7ddd-4a7d-96f6-51878e52373c) | netapi32.dll | lmshare.h | Vanara.PInvoke.NetApi32.NetFileGetInfo +[NetFreeAadJoinInformation](http://msdn2.microsoft.com/en-us/library/BDFB6179-4B8C-43E3-8D34-A2B470EA0D0B) | netapi32.dll | lmjoin.h | Vanara.PInvoke.NetApi32.NetFreeAadJoinInformation +[NetGetAadJoinInformation](http://msdn2.microsoft.com/en-us/library/C63B3AA7-FC7E-4CB9-9318-BD25560591AB) | netapi32.dll | lmjoin.h | Vanara.PInvoke.NetApi32.NetGetAadJoinInformation [NetGetAnyDCName](https://www.google.com/search?num=5&q=NetGetAnyDCName+site%3Amicrosoft.com) | netapi32.dll | | [NetGetDCName](https://www.google.com/search?num=5&q=NetGetDCName+site%3Amicrosoft.com) | netapi32.dll | | [NetGetDisplayInformationIndex](https://www.google.com/search?num=5&q=NetGetDisplayInformationIndex+site%3Amicrosoft.com) | netapi32.dll | | -[NetGetJoinableOUs](https://www.google.com/search?num=5&q=NetGetJoinableOUs+site%3Amicrosoft.com) | netapi32.dll | | -[NetGetJoinInformation](https://www.google.com/search?num=5&q=NetGetJoinInformation+site%3Amicrosoft.com) | netapi32.dll | | +[NetGetJoinableOUs](http://msdn2.microsoft.com/en-us/library/1faa912b-c56d-431c-95d5-d36790b0d467) | netapi32.dll | lmjoin.h | Vanara.PInvoke.NetApi32.NetGetJoinableOUs +[NetGetJoinInformation](http://msdn2.microsoft.com/en-us/library/c7cc1cf2-4530-4039-806b-fbee572f564d) | netapi32.dll | lmjoin.h | Vanara.PInvoke.NetApi32.NetGetJoinInformation [NetGroupAdd](https://www.google.com/search?num=5&q=NetGroupAdd+site%3Amicrosoft.com) | netapi32.dll | | [NetGroupAddUser](https://www.google.com/search?num=5&q=NetGroupAddUser+site%3Amicrosoft.com) | netapi32.dll | | [NetGroupDel](https://www.google.com/search?num=5&q=NetGroupDel+site%3Amicrosoft.com) | netapi32.dll | | @@ -94,7 +90,7 @@ Native Method | Native DLL | Header | Managed Method [NetGroupSetInfo](https://www.google.com/search?num=5&q=NetGroupSetInfo+site%3Amicrosoft.com) | netapi32.dll | | [NetGroupSetUsers](https://www.google.com/search?num=5&q=NetGroupSetUsers+site%3Amicrosoft.com) | netapi32.dll | | [NetIsServiceAccount](https://www.google.com/search?num=5&q=NetIsServiceAccount+site%3Amicrosoft.com) | netapi32.dll | | -[NetJoinDomain](https://www.google.com/search?num=5&q=NetJoinDomain+site%3Amicrosoft.com) | netapi32.dll | | +[NetJoinDomain](http://msdn2.microsoft.com/en-us/library/4efcb399-03af-4312-9f1d-6bc38f356cac) | netapi32.dll | lmjoin.h | Vanara.PInvoke.NetApi32.NetJoinDomain [NetLocalGroupAdd](https://www.google.com/search?num=5&q=NetLocalGroupAdd+site%3Amicrosoft.com) | netapi32.dll | | [NetLocalGroupAddMember](https://www.google.com/search?num=5&q=NetLocalGroupAddMember+site%3Amicrosoft.com) | netapi32.dll | | [NetLocalGroupAddMembers](https://www.google.com/search?num=5&q=NetLocalGroupAddMembers+site%3Amicrosoft.com) | netapi32.dll | | @@ -106,21 +102,16 @@ Native Method | Native DLL | Header | Managed Method [NetLocalGroupGetMembers](https://www.google.com/search?num=5&q=NetLocalGroupGetMembers+site%3Amicrosoft.com) | netapi32.dll | | [NetLocalGroupSetInfo](https://www.google.com/search?num=5&q=NetLocalGroupSetInfo+site%3Amicrosoft.com) | netapi32.dll | | [NetLocalGroupSetMembers](https://www.google.com/search?num=5&q=NetLocalGroupSetMembers+site%3Amicrosoft.com) | netapi32.dll | | -[NetMessageBufferSend](https://www.google.com/search?num=5&q=NetMessageBufferSend+site%3Amicrosoft.com) | netapi32.dll | | -[NetMessageNameAdd](https://www.google.com/search?num=5&q=NetMessageNameAdd+site%3Amicrosoft.com) | netapi32.dll | | -[NetMessageNameDel](https://www.google.com/search?num=5&q=NetMessageNameDel+site%3Amicrosoft.com) | netapi32.dll | | -[NetMessageNameEnum](https://www.google.com/search?num=5&q=NetMessageNameEnum+site%3Amicrosoft.com) | netapi32.dll | | -[NetMessageNameGetInfo](https://www.google.com/search?num=5&q=NetMessageNameGetInfo+site%3Amicrosoft.com) | netapi32.dll | | -[NetProvisionComputerAccount](https://www.google.com/search?num=5&q=NetProvisionComputerAccount+site%3Amicrosoft.com) | netapi32.dll | | +[NetProvisionComputerAccount](http://msdn2.microsoft.com/en-us/library/4c854258-b84d-4ef3-a6da-ce0a9540ffd5) | netapi32.dll | lmjoin.h | Vanara.PInvoke.NetApi32.NetProvisionComputerAccount [NetQueryDisplayInformation](https://www.google.com/search?num=5&q=NetQueryDisplayInformation+site%3Amicrosoft.com) | netapi32.dll | | [NetQueryServiceAccount](https://www.google.com/search?num=5&q=NetQueryServiceAccount+site%3Amicrosoft.com) | netapi32.dll | | -[NetRemoteComputerSupports](https://www.google.com/search?num=5&q=NetRemoteComputerSupports+site%3Amicrosoft.com) | netapi32.dll | | -[NetRemoteTOD](https://www.google.com/search?num=5&q=NetRemoteTOD+site%3Amicrosoft.com) | netapi32.dll | | -[NetRemoveAlternateComputerName](https://www.google.com/search?num=5&q=NetRemoveAlternateComputerName+site%3Amicrosoft.com) | netapi32.dll | | +[NetRemoteComputerSupports](http://msdn2.microsoft.com/en-us/library/e807489a-250e-4d4c-adb6-eff8ac30603b) | netapi32.dll | lmremutl.h | Vanara.PInvoke.NetApi32.NetRemoteComputerSupports +[NetRemoteTOD](http://msdn2.microsoft.com/en-us/library/5a935e09-f188-4ee1-b998-c67488475baa) | netapi32.dll | lmremutl.h | Vanara.PInvoke.NetApi32.NetRemoteTOD +[NetRemoveAlternateComputerName](http://msdn2.microsoft.com/en-us/library/3c7ab44e-d5fa-40da-83fe-a44bf85b2ba5) | netapi32.dll | lmjoin.h | Vanara.PInvoke.NetApi32.NetRemoveAlternateComputerName [NetRemoveServiceAccount](https://www.google.com/search?num=5&q=NetRemoveServiceAccount+site%3Amicrosoft.com) | netapi32.dll | | -[NetRenameMachineInDomain](https://www.google.com/search?num=5&q=NetRenameMachineInDomain+site%3Amicrosoft.com) | netapi32.dll | | -[NetRequestOfflineDomainJoin](https://www.google.com/search?num=5&q=NetRequestOfflineDomainJoin+site%3Amicrosoft.com) | netapi32.dll | | -[NetRequestProvisioningPackageInstall](https://www.google.com/search?num=5&q=NetRequestProvisioningPackageInstall+site%3Amicrosoft.com) | netapi32.dll | | +[NetRenameMachineInDomain](http://msdn2.microsoft.com/en-us/library/1f7ddaa1-a349-49a6-856d-a2fde2f1dc3b) | netapi32.dll | lmjoin.h | Vanara.PInvoke.NetApi32.NetRenameMachineInDomain +[NetRequestOfflineDomainJoin](http://msdn2.microsoft.com/en-us/library/f3f8fe00-d6f7-4d59-a4e7-6aef7f507e1a) | netapi32.dll | lmjoin.h | Vanara.PInvoke.NetApi32.NetRequestOfflineDomainJoin +[NetRequestProvisioningPackageInstall](http://msdn2.microsoft.com/en-us/library/107ED0F7-8DDD-4C18-8C34-3A67F771FA62) | netapi32.dll | lmjoin.h | Vanara.PInvoke.NetApi32.NetRequestProvisioningPackageInstall [NetScheduleJobAdd](https://www.google.com/search?num=5&q=NetScheduleJobAdd+site%3Amicrosoft.com) | netapi32.dll | | [NetScheduleJobDel](https://www.google.com/search?num=5&q=NetScheduleJobDel+site%3Amicrosoft.com) | netapi32.dll | | [NetScheduleJobEnum](https://www.google.com/search?num=5&q=NetScheduleJobEnum+site%3Amicrosoft.com) | netapi32.dll | | @@ -128,34 +119,30 @@ Native Method | Native DLL | Header | Managed Method [NetServerComputerNameAdd](http://msdn2.microsoft.com/en-us/library/0789fbfe-be91-4849-a31c-1e1a6ae1e70d) | netapi32.dll | lmserver.h | Vanara.PInvoke.NetApi32.NetServerComputerNameAdd [NetServerComputerNameDel](http://msdn2.microsoft.com/en-us/library/501232ad-2821-4bbd-9f16-0f49984f6101) | netapi32.dll | lmserver.h | Vanara.PInvoke.NetApi32.NetServerComputerNameDel [NetServerDiskEnum](http://msdn2.microsoft.com/en-us/library/56c981f4-7a1d-4465-bd7b-5996222c4210) | netapi32.dll | lmserver.h | Vanara.PInvoke.NetApi32.NetServerDiskEnum -[NetServerEnum](http://msdn2.microsoft.com/en-us/library/aa370623) | netapi32.dll | lm.h | Vanara.PInvoke.NetApi32.NetServerEnum -[NetServerGetInfo](http://msdn2.microsoft.com/en-us/library/aa370624) | netapi32.dll | lm.h | Vanara.PInvoke.NetApi32.NetServerGetInfo +[NetServerEnum](http://msdn2.microsoft.com/en-us/library/10012a87-805e-4817-9f09-9e5632b1fa09) | netapi32.dll | lmserver.h | Vanara.PInvoke.NetApi32.NetServerEnum +[NetServerGetInfo](http://msdn2.microsoft.com/en-us/library/aa370624) | netapi32.dll | lmserver.h | Vanara.PInvoke.NetApi32.NetServerGetInfo [NetServerSetInfo](http://msdn2.microsoft.com/en-us/library/1a04a43d-34f9-4a08-ac66-750120792af0) | netapi32.dll | lmserver.h | Vanara.PInvoke.NetApi32.NetServerSetInfo [NetServerTransportAdd](http://msdn2.microsoft.com/en-us/library/c8521aed-0762-4412-b117-c911fc77049b) | netapi32.dll | lmserver.h | Vanara.PInvoke.NetApi32.NetServerTransportAdd [NetServerTransportAddEx](http://msdn2.microsoft.com/en-us/library/d1edc75d-8313-422c-a6fb-8b51a309a252) | netapi32.dll | lmserver.h | Vanara.PInvoke.NetApi32.NetServerTransportAddEx [NetServerTransportDel](http://msdn2.microsoft.com/en-us/library/69b22f30-62b1-4dcb-bbb0-aceae8d77f61) | netapi32.dll | lmserver.h | Vanara.PInvoke.NetApi32.NetServerTransportDel [NetServerTransportEnum](http://msdn2.microsoft.com/en-us/library/db42ac44-d70d-4b89-882a-6ac83fd611fd) | netapi32.dll | lmserver.h | Vanara.PInvoke.NetApi32.NetServerTransportEnum -[NetServiceControl](https://www.google.com/search?num=5&q=NetServiceControl+site%3Amicrosoft.com) | netapi32.dll | | -[NetServiceEnum](https://www.google.com/search?num=5&q=NetServiceEnum+site%3Amicrosoft.com) | netapi32.dll | | -[NetServiceGetInfo](https://www.google.com/search?num=5&q=NetServiceGetInfo+site%3Amicrosoft.com) | netapi32.dll | | -[NetServiceInstall](https://www.google.com/search?num=5&q=NetServiceInstall+site%3Amicrosoft.com) | netapi32.dll | | -[NetSessionDel](https://www.google.com/search?num=5&q=NetSessionDel+site%3Amicrosoft.com) | netapi32.dll | | -[NetSessionEnum](https://www.google.com/search?num=5&q=NetSessionEnum+site%3Amicrosoft.com) | netapi32.dll | | -[NetSessionGetInfo](https://www.google.com/search?num=5&q=NetSessionGetInfo+site%3Amicrosoft.com) | netapi32.dll | | -[NetSetPrimaryComputerName](https://www.google.com/search?num=5&q=NetSetPrimaryComputerName+site%3Amicrosoft.com) | netapi32.dll | | -[NetShareAdd](https://www.google.com/search?num=5&q=NetShareAdd+site%3Amicrosoft.com) | netapi32.dll | | -[NetShareCheck](https://www.google.com/search?num=5&q=NetShareCheck+site%3Amicrosoft.com) | netapi32.dll | | -[NetShareDel](https://www.google.com/search?num=5&q=NetShareDel+site%3Amicrosoft.com) | netapi32.dll | | -[NetShareDelEx](https://www.google.com/search?num=5&q=NetShareDelEx+site%3Amicrosoft.com) | netapi32.dll | | -[NetShareEnum](https://www.google.com/search?num=5&q=NetShareEnum+site%3Amicrosoft.com) | netapi32.dll | | -[NetShareGetInfo](https://www.google.com/search?num=5&q=NetShareGetInfo+site%3Amicrosoft.com) | netapi32.dll | | -[NetShareSetInfo](https://www.google.com/search?num=5&q=NetShareSetInfo+site%3Amicrosoft.com) | netapi32.dll | | +[NetSessionDel](http://msdn2.microsoft.com/en-us/library/a1360f5d-9fd0-44af-b9f5-ab9bc057dfe6) | netapi32.dll | lmshare.h | Vanara.PInvoke.NetApi32.NetSessionDel +[NetSessionEnum](http://msdn2.microsoft.com/en-us/library/5923a8cc-bf7a-4ffa-b089-fd7f26ee42d2) | netapi32.dll | lmshare.h | Vanara.PInvoke.NetApi32.NetSessionEnum +[NetSessionGetInfo](http://msdn2.microsoft.com/en-us/library/d44fb8d8-2b64-4268-8603-7784e2c5f2d5) | netapi32.dll | lmshare.h | Vanara.PInvoke.NetApi32.NetSessionGetInfo +[NetSetPrimaryComputerName](http://msdn2.microsoft.com/en-us/library/524c8219-a303-45ab-95e2-91319b477568) | netapi32.dll | lmjoin.h | Vanara.PInvoke.NetApi32.NetSetPrimaryComputerName +[NetShareAdd](http://msdn2.microsoft.com/en-us/library/8b51c155-24e8-4d39-b818-eb2d1bb0ee8b) | netapi32.dll | lmshare.h | Vanara.PInvoke.NetApi32.NetShareAdd +[NetShareCheck](http://msdn2.microsoft.com/en-us/library/8453dcd2-5c58-4fe4-9426-0fd51647394d) | netapi32.dll | lmshare.h | Vanara.PInvoke.NetApi32.NetShareCheck +[NetShareDel](http://msdn2.microsoft.com/en-us/library/374b8f81-b3d6-4967-bd4a-ffd3fdc3cf7c) | netapi32.dll | lmshare.h | Vanara.PInvoke.NetApi32.NetShareDel +[NetShareDelEx](http://msdn2.microsoft.com/en-us/library/2461c533-351b-48f4-b660-cb17ac3398fa) | netapi32.dll | lmshare.h | Vanara.PInvoke.NetApi32.NetShareDelEx +[NetShareEnum](http://msdn2.microsoft.com/en-us/library/9114c54d-3905-4d40-9162-b3ea605f6fcb) | netapi32.dll | lmshare.h | Vanara.PInvoke.NetApi32.NetShareEnum +[NetShareGetInfo](http://msdn2.microsoft.com/en-us/library/672ea208-4048-4d2f-9606-ee3e2133765b) | netapi32.dll | lmshare.h | Vanara.PInvoke.NetApi32.NetShareGetInfo +[NetShareSetInfo](http://msdn2.microsoft.com/en-us/library/216b0b78-87da-4734-ad07-5ad1c9edf494) | netapi32.dll | lmshare.h | Vanara.PInvoke.NetApi32.NetShareSetInfo [NetStatisticsGet](https://www.google.com/search?num=5&q=NetStatisticsGet+site%3Amicrosoft.com) | netapi32.dll | | -[NetUnjoinDomain](https://www.google.com/search?num=5&q=NetUnjoinDomain+site%3Amicrosoft.com) | netapi32.dll | | -[NetUseAdd](https://www.google.com/search?num=5&q=NetUseAdd+site%3Amicrosoft.com) | netapi32.dll | | -[NetUseDel](https://www.google.com/search?num=5&q=NetUseDel+site%3Amicrosoft.com) | netapi32.dll | | -[NetUseEnum](https://www.google.com/search?num=5&q=NetUseEnum+site%3Amicrosoft.com) | netapi32.dll | | -[NetUseGetInfo](https://www.google.com/search?num=5&q=NetUseGetInfo+site%3Amicrosoft.com) | netapi32.dll | | +[NetUnjoinDomain](http://msdn2.microsoft.com/en-us/library/cc755c22-1fd6-4787-999e-a43258287a05) | netapi32.dll | lmjoin.h | Vanara.PInvoke.NetApi32.NetUnjoinDomain +[NetUseAdd](http://msdn2.microsoft.com/en-us/library/22550c17-003a-4f59-80f0-58fa3e286844) | netapi32.dll | lmuse.h | Vanara.PInvoke.NetApi32.NetUseAdd +[NetUseDel](http://msdn2.microsoft.com/en-us/library/200b0640-71e9-4f60-bf4c-c8df10bfe095) | netapi32.dll | lmuse.h | Vanara.PInvoke.NetApi32.NetUseDel +[NetUseEnum](http://msdn2.microsoft.com/en-us/library/fb527f85-baea-48e8-b837-967870834ec5) | netapi32.dll | lmuse.h | Vanara.PInvoke.NetApi32.NetUseEnum +[NetUseGetInfo](http://msdn2.microsoft.com/en-us/library/257875db-5ed9-4569-8dbb-5dcc7a6af95c) | netapi32.dll | lmuse.h | Vanara.PInvoke.NetApi32.NetUseGetInfo [NetUserAdd](https://www.google.com/search?num=5&q=NetUserAdd+site%3Amicrosoft.com) | netapi32.dll | | [NetUserChangePassword](https://www.google.com/search?num=5&q=NetUserChangePassword+site%3Amicrosoft.com) | netapi32.dll | | [NetUserDel](https://www.google.com/search?num=5&q=NetUserDel+site%3Amicrosoft.com) | netapi32.dll | | @@ -167,31 +154,108 @@ Native Method | Native DLL | Header | Managed Method [NetUserModalsSet](https://www.google.com/search?num=5&q=NetUserModalsSet+site%3Amicrosoft.com) | netapi32.dll | | [NetUserSetGroups](https://www.google.com/search?num=5&q=NetUserSetGroups+site%3Amicrosoft.com) | netapi32.dll | | [NetUserSetInfo](https://www.google.com/search?num=5&q=NetUserSetInfo+site%3Amicrosoft.com) | netapi32.dll | | -[NetValidateName](https://www.google.com/search?num=5&q=NetValidateName+site%3Amicrosoft.com) | netapi32.dll | | +[NetValidateName](http://msdn2.microsoft.com/en-us/library/772603df-ec17-4a83-a715-2d9a14d5c2bb) | netapi32.dll | lmjoin.h | Vanara.PInvoke.NetApi32.NetValidateName [NetValidatePasswordPolicy](https://www.google.com/search?num=5&q=NetValidatePasswordPolicy+site%3Amicrosoft.com) | netapi32.dll | | [NetValidatePasswordPolicyFree](https://www.google.com/search?num=5&q=NetValidatePasswordPolicyFree+site%3Amicrosoft.com) | netapi32.dll | | -[NetWkstaGetInfo](https://www.google.com/search?num=5&q=NetWkstaGetInfo+site%3Amicrosoft.com) | netapi32.dll | | -[NetWkstaSetInfo](https://www.google.com/search?num=5&q=NetWkstaSetInfo+site%3Amicrosoft.com) | netapi32.dll | | -[NetWkstaTransportAdd](https://www.google.com/search?num=5&q=NetWkstaTransportAdd+site%3Amicrosoft.com) | netapi32.dll | | -[NetWkstaTransportDel](https://www.google.com/search?num=5&q=NetWkstaTransportDel+site%3Amicrosoft.com) | netapi32.dll | | -[NetWkstaTransportEnum](https://www.google.com/search?num=5&q=NetWkstaTransportEnum+site%3Amicrosoft.com) | netapi32.dll | | -[NetWkstaUserEnum](https://www.google.com/search?num=5&q=NetWkstaUserEnum+site%3Amicrosoft.com) | netapi32.dll | | -[NetWkstaUserGetInfo](https://www.google.com/search?num=5&q=NetWkstaUserGetInfo+site%3Amicrosoft.com) | netapi32.dll | | -[NetWkstaUserSetInfo](https://www.google.com/search?num=5&q=NetWkstaUserSetInfo+site%3Amicrosoft.com) | netapi32.dll | | +[NetWkstaGetInfo](http://msdn2.microsoft.com/en-us/library/08777069-1afd-4482-8090-c65ef0bec1ea) | netapi32.dll | lmwksta.h | Vanara.PInvoke.NetApi32.NetWkstaGetInfo +[NetWkstaSetInfo](http://msdn2.microsoft.com/en-us/library/d746b6c9-5ef1-4174-a84f-44e4e50200cd) | netapi32.dll | lmwksta.h | Vanara.PInvoke.NetApi32.NetWkstaSetInfo +[NetWkstaTransportAdd](http://msdn2.microsoft.com/en-us/library/016060ea-eae1-421f-b708-5c2ddd2000c1) | netapi32.dll | lmwksta.h | Vanara.PInvoke.NetApi32.NetWkstaTransportAdd +[NetWkstaTransportDel](http://msdn2.microsoft.com/en-us/library/6d0ec459-8d7b-41fe-96dd-203e6a42164f) | netapi32.dll | lmwksta.h | Vanara.PInvoke.NetApi32.NetWkstaTransportDel +[NetWkstaTransportEnum](http://msdn2.microsoft.com/en-us/library/08bd22a9-00a7-4563-9353-c070ca9b2500) | netapi32.dll | lmwksta.h | Vanara.PInvoke.NetApi32.NetWkstaTransportEnum +[NetWkstaUserEnum](http://msdn2.microsoft.com/en-us/library/42eaeb70-3ce8-4eae-b20b-4729db90a7ef) | netapi32.dll | lmwksta.h | Vanara.PInvoke.NetApi32.NetWkstaUserEnum +[NetWkstaUserGetInfo](http://msdn2.microsoft.com/en-us/library/25ec7a49-fd26-4105-823b-a257a57f724e) | netapi32.dll | lmwksta.h | Vanara.PInvoke.NetApi32.NetWkstaUserGetInfo +[NetWkstaUserSetInfo](http://msdn2.microsoft.com/en-us/library/d48667a3-5ae9-4a7d-9af6-14f08835940d) | netapi32.dll | lmwksta.h | Vanara.PInvoke.NetApi32.NetWkstaUserSetInfo ### Structures Native Structure | Header | Managed Structure --- | --- | --- +[ADMIN_OTHER_INFO](http://msdn2.microsoft.com/en-us/library/43119dcf-7d04-4e3b-b1dc-20e814fbdc2f) | lmalert.h | Vanara.PInvoke.NetApi32+ADMIN_OTHER_INFO +[CONNECTION_INFO_0](http://msdn2.microsoft.com/en-us/library/aebafe24-1216-48ab-92db-df8f77d36f26) | lmshare.h | Vanara.PInvoke.NetApi32+CONNECTION_INFO_0 +[CONNECTION_INFO_1](http://msdn2.microsoft.com/en-us/library/9904c448-dcc4-47cc-a2e0-7df8d4d37f3f) | lmshare.h | Vanara.PInvoke.NetApi32+CONNECTION_INFO_1 +[DAV_CALLBACK_AUTH_BLOB](http://msdn2.microsoft.com/en-us/library/59976cb0-ed68-4db0-b8f8-cfe5e778916b) | davclnt.h | Vanara.PInvoke.NetApi32+DAV_CALLBACK_AUTH_BLOB +[DAV_CALLBACK_AUTH_UNP](http://msdn2.microsoft.com/en-us/library/47420a67-bf3f-40d9-bfc4-ac2cb2776a40) | davclnt.h | Vanara.PInvoke.NetApi32+DAV_CALLBACK_AUTH_UNP +[DAV_CALLBACK_CRED](http://msdn2.microsoft.com/en-us/library/5414d7b5-b506-4d0a-a4b8-89ab7878d674) | davclnt.h | Vanara.PInvoke.NetApi32+DAV_CALLBACK_CRED [DOMAIN_CONTROLLER_INFO](http://msdn2.microsoft.com/en-us/library/ms675912) | DsGetDC.h | Vanara.PInvoke.NetApi32+DOMAIN_CONTROLLER_INFO [DS_DOMAIN_TRUSTS](http://msdn2.microsoft.com/en-us/library/cd260fd1-dc38-4405-95ba-097a23faf668) | dsgetdc.h | Vanara.PInvoke.NetApi32+DS_DOMAIN_TRUSTS +[DSREG_USER_INFO](http://msdn2.microsoft.com/en-us/library/5E639988-0F53-40D7-BBEC-F78B3D124CC0) | lmjoin.h | Vanara.PInvoke.NetApi32+DSREG_USER_INFO [DSROLE_OPERATION_STATE_INFO](http://msdn2.microsoft.com/en-us/library/c6c8e510-190a-47ad-805c-b8d3fbee836d) | dsrole.h | Vanara.PInvoke.NetApi32+DSROLE_OPERATION_STATE_INFO [DSROLE_PRIMARY_DOMAIN_INFO_BASIC](http://msdn2.microsoft.com/en-us/library/8a7b34e8-46d6-46dc-9fef-ec37b0f65eea) | dsrole.h | Vanara.PInvoke.NetApi32+DSROLE_PRIMARY_DOMAIN_INFO_BASIC [DSROLE_UPGRADE_STATUS_INFO](http://msdn2.microsoft.com/en-us/library/c368d8d9-a91d-4013-880e-36a47d42a697) | dsrole.h | Vanara.PInvoke.NetApi32+DSROLE_UPGRADE_STATUS_INFO -[SERVER_INFO_100](http://msdn2.microsoft.com/en-us/library/aa370897) | lm.h | Vanara.PInvoke.NetApi32+SERVER_INFO_100 -[SERVER_INFO_101](http://msdn2.microsoft.com/en-us/library/aa370903) | lm.h | Vanara.PInvoke.NetApi32+SERVER_INFO_101 -[SERVER_INFO_102](http://msdn2.microsoft.com/en-us/library/aa370904) | lm.h | Vanara.PInvoke.NetApi32+SERVER_INFO_102 +[ERRLOG_OTHER_INFO](http://msdn2.microsoft.com/en-us/library/832ebe88-e1c4-4ce3-8057-922419b577f7) | lmalert.h | Vanara.PInvoke.NetApi32+ERRLOG_OTHER_INFO +[FILE_INFO_2](http://msdn2.microsoft.com/en-us/library/c80090d5-7064-4809-9185-02116f7ac2ef) | lmshare.h | Vanara.PInvoke.NetApi32+FILE_INFO_2 +[FILE_INFO_3](http://msdn2.microsoft.com/en-us/library/67f5fa89-12c7-46fb-a118-de4bfed96923) | lmshare.h | Vanara.PInvoke.NetApi32+FILE_INFO_3 +[NETSETUP_PROVISIONING_PARAMS](http://msdn2.microsoft.com/en-us/library/E965804F-145A-4D8F-BB8E-466580AC65DA) | lmjoin.h | Vanara.PInvoke.NetApi32+NETSETUP_PROVISIONING_PARAMS +[PRINT_OTHER_INFO](http://msdn2.microsoft.com/en-us/library/f2fd87bc-abde-43c0-b29d-d43cc5f038b8) | lmalert.h | Vanara.PInvoke.NetApi32+PRINT_OTHER_INFO +[SERVER_INFO_100](http://msdn2.microsoft.com/en-us/library/aa370897) | lmserver.h | Vanara.PInvoke.NetApi32+SERVER_INFO_100 +[SERVER_INFO_101](http://msdn2.microsoft.com/en-us/library/aa370903) | lmserver.h | Vanara.PInvoke.NetApi32+SERVER_INFO_101 +[SERVER_INFO_102](http://msdn2.microsoft.com/en-us/library/aa370904) | lmserver.h | Vanara.PInvoke.NetApi32+SERVER_INFO_102 [SERVER_INFO_402](http://msdn2.microsoft.com/en-us/library/51e5c27e-6a7d-45ac-9cfa-37b1f7f241f9) | lmserver.h | Vanara.PInvoke.NetApi32+SERVER_INFO_402 [SERVER_INFO_403](http://msdn2.microsoft.com/en-us/library/14309dbe-ad7b-4ae0-8acc-39e9999f411b) | lmserver.h | Vanara.PInvoke.NetApi32+SERVER_INFO_403 [SERVER_TRANSPORT_INFO_0](http://msdn2.microsoft.com/en-us/library/5b94cf7a-74d1-4ae8-87bd-22b2daf292cb) | lmserver.h | Vanara.PInvoke.NetApi32+SERVER_TRANSPORT_INFO_0 [SERVER_TRANSPORT_INFO_1](http://msdn2.microsoft.com/en-us/library/f21fed49-207a-4f64-becd-3d3c1e995eb0) | lmserver.h | Vanara.PInvoke.NetApi32+SERVER_TRANSPORT_INFO_1 [SERVER_TRANSPORT_INFO_2](http://msdn2.microsoft.com/en-us/library/b422eb71-1f93-432d-8283-81432edfe568) | lmserver.h | Vanara.PInvoke.NetApi32+SERVER_TRANSPORT_INFO_2 [SERVER_TRANSPORT_INFO_3](http://msdn2.microsoft.com/en-us/library/045d60d4-518f-4ce4-b611-e23d1588d5d3) | lmserver.h | Vanara.PInvoke.NetApi32+SERVER_TRANSPORT_INFO_3 +[SESSION_INFO_0](http://msdn2.microsoft.com/en-us/library/6b39df47-f25c-41dd-ba15-6e6806c4ec89) | lmshare.h | Vanara.PInvoke.NetApi32+SESSION_INFO_0 +[SESSION_INFO_1](http://msdn2.microsoft.com/en-us/library/bc1c985e-b8af-4134-9ae4-511d82e3909b) | lmshare.h | Vanara.PInvoke.NetApi32+SESSION_INFO_1 +[SESSION_INFO_10](http://msdn2.microsoft.com/en-us/library/a23a5647-f99d-4cb8-9d84-93653a3e7428) | lmshare.h | Vanara.PInvoke.NetApi32+SESSION_INFO_10 +[SESSION_INFO_2](http://msdn2.microsoft.com/en-us/library/c3429eba-4277-4dc7-9255-cd2ff18dc583) | lmshare.h | Vanara.PInvoke.NetApi32+SESSION_INFO_2 +[SESSION_INFO_502](http://msdn2.microsoft.com/en-us/library/a86a00ae-f60a-4b12-a9ac-4b96f9abd6a2) | lmshare.h | Vanara.PInvoke.NetApi32+SESSION_INFO_502 +[SHARE_INFO_0](http://msdn2.microsoft.com/en-us/library/47a74c71-1fcb-4c49-93b5-ea7cf3a0e567) | lmshare.h | Vanara.PInvoke.NetApi32+SHARE_INFO_0 +[SHARE_INFO_1](http://msdn2.microsoft.com/en-us/library/9bc69340-4ea5-4180-ae5c-667c0a245b66) | lmshare.h | Vanara.PInvoke.NetApi32+SHARE_INFO_1 +[SHARE_INFO_1004](http://msdn2.microsoft.com/en-us/library/41749066-d0e2-4a6b-aea5-216af9a530f4) | lmshare.h | Vanara.PInvoke.NetApi32+SHARE_INFO_1004 +[SHARE_INFO_1005](http://msdn2.microsoft.com/en-us/library/9fb3e0ae-76b5-4432-80dd-f3361738aa7c) | lmshare.h | Vanara.PInvoke.NetApi32+SHARE_INFO_1005 +[SHARE_INFO_1006](http://msdn2.microsoft.com/en-us/library/645a8670-5661-4d6c-8d9e-67c1bbb0f1d7) | lmshare.h | Vanara.PInvoke.NetApi32+SHARE_INFO_1006 +[SHARE_INFO_1501](http://msdn2.microsoft.com/en-us/library/ef5d4936-8c0b-4a3c-b2b9-34868eb01a2e) | lmshare.h | Vanara.PInvoke.NetApi32+SHARE_INFO_1501 +[SHARE_INFO_2](http://msdn2.microsoft.com/en-us/library/cd152ccd-cd60-455f-b25c-c4939c65e0ab) | lmshare.h | Vanara.PInvoke.NetApi32+SHARE_INFO_2 +[SHARE_INFO_502](http://msdn2.microsoft.com/en-us/library/306e6704-2068-42da-bcc4-c0772c719ee8) | lmshare.h | Vanara.PInvoke.NetApi32+SHARE_INFO_502 +[SHARE_INFO_503](http://msdn2.microsoft.com/en-us/library/12650bc0-f67d-464e-8386-a0fd53cdc749) | lmshare.h | Vanara.PInvoke.NetApi32+SHARE_INFO_503 +[STD_ALERT](http://msdn2.microsoft.com/en-us/library/daa4594f-e59e-4f05-8183-677bee4ea446) | lmalert.h | Vanara.PInvoke.NetApi32+STD_ALERT +[TIME_OF_DAY_INFO](http://msdn2.microsoft.com/en-us/library/bf89f071-5c04-40c2-a7b7-4e59fc9eaa02) | lmremutl.h | Vanara.PInvoke.NetApi32+TIME_OF_DAY_INFO +[USE_INFO_0](http://msdn2.microsoft.com/en-us/library/86db3f19-84c5-4e89-82cb-f01d17dcf4ec) | lmuse.h | Vanara.PInvoke.NetApi32+USE_INFO_0 +[USE_INFO_1](http://msdn2.microsoft.com/en-us/library/b9f680b8-b56a-42be-9af1-d7b18328ded4) | lmuse.h | Vanara.PInvoke.NetApi32+USE_INFO_1 +[USE_INFO_2](http://msdn2.microsoft.com/en-us/library/4cc36108-085a-47c4-9dfa-b46f7e208c8b) | lmuse.h | Vanara.PInvoke.NetApi32+USE_INFO_2 +[USE_INFO_3](http://msdn2.microsoft.com/en-us/library/3fb3ad35-f9e5-46ba-b930-fc2ccafd8ee9) | lmuse.h | Vanara.PInvoke.NetApi32+USE_INFO_3 +[USE_INFO_4](https://www.google.com/search?num=5&q=USE_INFO_4+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+USE_INFO_4 +[USE_INFO_5](https://www.google.com/search?num=5&q=USE_INFO_5+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+USE_INFO_5 +[USER_OTHER_INFO](http://msdn2.microsoft.com/en-us/library/2f6bd906-fdab-410a-8856-4482e047371f) | lmalert.h | Vanara.PInvoke.NetApi32+USER_OTHER_INFO +[WKSTA_INFO_100](http://msdn2.microsoft.com/en-us/library/c705dadd-cf55-44d9-bf36-09e078112479) | lmwksta.h | Vanara.PInvoke.NetApi32+WKSTA_INFO_100 +[WKSTA_INFO_101](http://msdn2.microsoft.com/en-us/library/2b692d40-6229-45ef-9ec6-ee464bba0696) | lmwksta.h | Vanara.PInvoke.NetApi32+WKSTA_INFO_101 +[WKSTA_INFO_1010](https://www.google.com/search?num=5&q=WKSTA_INFO_1010+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1010 +[WKSTA_INFO_1011](https://www.google.com/search?num=5&q=WKSTA_INFO_1011+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1011 +[WKSTA_INFO_1012](https://www.google.com/search?num=5&q=WKSTA_INFO_1012+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1012 +[WKSTA_INFO_1013](https://www.google.com/search?num=5&q=WKSTA_INFO_1013+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1013 +[WKSTA_INFO_1018](https://www.google.com/search?num=5&q=WKSTA_INFO_1018+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1018 +[WKSTA_INFO_102](http://msdn2.microsoft.com/en-us/library/01607fb5-c433-439c-aaaa-3736697f7c07) | lmwksta.h | Vanara.PInvoke.NetApi32+WKSTA_INFO_102 +[WKSTA_INFO_1023](https://www.google.com/search?num=5&q=WKSTA_INFO_1023+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1023 +[WKSTA_INFO_1027](https://www.google.com/search?num=5&q=WKSTA_INFO_1027+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1027 +[WKSTA_INFO_1028](https://www.google.com/search?num=5&q=WKSTA_INFO_1028+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1028 +[WKSTA_INFO_1032](https://www.google.com/search?num=5&q=WKSTA_INFO_1032+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1032 +[WKSTA_INFO_1033](https://www.google.com/search?num=5&q=WKSTA_INFO_1033+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1033 +[WKSTA_INFO_1041](https://www.google.com/search?num=5&q=WKSTA_INFO_1041+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1041 +[WKSTA_INFO_1042](https://www.google.com/search?num=5&q=WKSTA_INFO_1042+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1042 +[WKSTA_INFO_1043](https://www.google.com/search?num=5&q=WKSTA_INFO_1043+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1043 +[WKSTA_INFO_1044](https://www.google.com/search?num=5&q=WKSTA_INFO_1044+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1044 +[WKSTA_INFO_1045](https://www.google.com/search?num=5&q=WKSTA_INFO_1045+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1045 +[WKSTA_INFO_1046](https://www.google.com/search?num=5&q=WKSTA_INFO_1046+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1046 +[WKSTA_INFO_1047](https://www.google.com/search?num=5&q=WKSTA_INFO_1047+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1047 +[WKSTA_INFO_1048](https://www.google.com/search?num=5&q=WKSTA_INFO_1048+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1048 +[WKSTA_INFO_1049](https://www.google.com/search?num=5&q=WKSTA_INFO_1049+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1049 +[WKSTA_INFO_1050](https://www.google.com/search?num=5&q=WKSTA_INFO_1050+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1050 +[WKSTA_INFO_1051](https://www.google.com/search?num=5&q=WKSTA_INFO_1051+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1051 +[WKSTA_INFO_1052](https://www.google.com/search?num=5&q=WKSTA_INFO_1052+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1052 +[WKSTA_INFO_1053](https://www.google.com/search?num=5&q=WKSTA_INFO_1053+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1053 +[WKSTA_INFO_1054](https://www.google.com/search?num=5&q=WKSTA_INFO_1054+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1054 +[WKSTA_INFO_1055](https://www.google.com/search?num=5&q=WKSTA_INFO_1055+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1055 +[WKSTA_INFO_1056](https://www.google.com/search?num=5&q=WKSTA_INFO_1056+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1056 +[WKSTA_INFO_1057](https://www.google.com/search?num=5&q=WKSTA_INFO_1057+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1057 +[WKSTA_INFO_1058](https://www.google.com/search?num=5&q=WKSTA_INFO_1058+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1058 +[WKSTA_INFO_1059](https://www.google.com/search?num=5&q=WKSTA_INFO_1059+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1059 +[WKSTA_INFO_1060](https://www.google.com/search?num=5&q=WKSTA_INFO_1060+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1060 +[WKSTA_INFO_1061](https://www.google.com/search?num=5&q=WKSTA_INFO_1061+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1061 +[WKSTA_INFO_1062](https://www.google.com/search?num=5&q=WKSTA_INFO_1062+site%3Amicrosoft.com) | | Vanara.PInvoke.NetApi32+WKSTA_INFO_1062 +[WKSTA_INFO_302](https://www.google.com/search?num=5&q=WKSTA_INFO_302+site%3Amicrosoft.com) | lmwksta.h | Vanara.PInvoke.NetApi32+WKSTA_INFO_302 +[WKSTA_INFO_402](https://www.google.com/search?num=5&q=WKSTA_INFO_402+site%3Amicrosoft.com) | lmwksta.h | Vanara.PInvoke.NetApi32+WKSTA_INFO_402 +[WKSTA_INFO_502](http://msdn2.microsoft.com/en-us/library/716e700a-e464-47ec-a2df-74c03597ac6d) | lmwksta.h | Vanara.PInvoke.NetApi32+WKSTA_INFO_502 +[WKSTA_TRANSPORT_INFO_0](http://msdn2.microsoft.com/en-us/library/e7afe2a3-f729-4fd5-afc3-d3ffbd09e884) | lmwksta.h | Vanara.PInvoke.NetApi32+WKSTA_TRANSPORT_INFO_0 +[WKSTA_USER_INFO_0](http://msdn2.microsoft.com/en-us/library/8bd8d8c7-4558-46cb-ab46-a2197d53e9f7) | lmwksta.h | Vanara.PInvoke.NetApi32+WKSTA_USER_INFO_0 +[WKSTA_USER_INFO_1](http://msdn2.microsoft.com/en-us/library/a30747de-6cb0-41dc-95a7-be3d471056d5) | lmwksta.h | Vanara.PInvoke.NetApi32+WKSTA_USER_INFO_1 +[WKSTA_USER_INFO_1101](http://msdn2.microsoft.com/en-us/library/88772ba2-046b-4b03-ae02-d851075e4363) | lmwksta.h | Vanara.PInvoke.NetApi32+WKSTA_USER_INFO_1101 diff --git a/PInvoke/NetApi32/DavClnt.cs b/PInvoke/NetApi32/DavClnt.cs index 965bc414..260d4ddf 100644 --- a/PInvoke/NetApi32/DavClnt.cs +++ b/PInvoke/NetApi32/DavClnt.cs @@ -136,6 +136,7 @@ namespace Vanara.PInvoke /// Authentication scheme. [PInvokeData("davclnt.h", MSDNShortId = "6ac191ac-e63f-431f-893b-92c69320db58")] + [Flags] public enum DAV_AUTHN_SCHEME { /// Basic authentication is to be used. diff --git a/PInvoke/NetApi32/DsGetDC.cs b/PInvoke/NetApi32/DsGetDC.cs index 3f3b45d3..b0c09fb1 100644 --- a/PInvoke/NetApi32/DsGetDC.cs +++ b/PInvoke/NetApi32/DsGetDC.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.InteropServices; +using System.Linq; using Vanara.InteropServices; using static Vanara.PInvoke.AdvApi32; using static Vanara.PInvoke.Ws2_32; @@ -316,34 +317,24 @@ namespace Vanara.PInvoke DS_GFTI_UPDATE_TDO = 1 } - /// - /// The DsAddressToSiteNames function obtains the site names corresponding to the specified addresses. - /// + /// The DsAddressToSiteNames function obtains the site names corresponding to the specified addresses. /// - /// /// Pointer to a null-terminated string that specifies the name of the remote server to process this function. This parameter must be /// the name of a domain controller. A non-domain controller can call this function by calling DsGetDcName to find the domain controller. - /// - /// - /// - /// Contains the number of elements in the SocketAddresses array. /// + /// Contains the number of elements in the SocketAddresses array. /// - /// /// Contains an array of SOCKET_ADDRESS structures that contain the addresses to convert. Each address in this array must be of the /// type AF_INET. EntryCount contains the number of elements in this array. - /// /// /// - /// /// Receives an array of null-terminated string pointers that contain the site names for the addresses. Each element in this array /// corresponds to the same element in the SocketAddresses array. An element is NULL if the corresponding address does not map /// to any known site or if the address entry is not of the proper form. The caller must free this array when it is no longer /// required by calling NetApiBufferFree. - /// /// /// - /// Returns NO_ERROR if successful or a Win32 or RPC error otherwise. The following list lists possible error codes. + /// Returns NO_ERROR if successful or a Win32 or RPC error otherwise. The following list lists possible error codes. /// // https://docs.microsoft.com/en-us/windows/desktop/api/dsgetdc/nf-dsgetdc-dsaddresstositenamesa DSGETDCAPI DWORD // DsAddressToSiteNamesA( IN LPCSTR ComputerName, IN DWORD EntryCount, IN PSOCKET_ADDRESS SocketAddresses, OUT LPSTR **SiteNames ); @@ -351,47 +342,32 @@ namespace Vanara.PInvoke [PInvokeData("dsgetdc.h", MSDNShortId = "4d70dbee-be33-4d2a-a200-3696443fa853")] public static extern Win32Error DsAddressToSiteNames(string ComputerName, uint EntryCount, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] SOCKET_ADDRESS[] SocketAddresses, out SafeNetApiBuffer SiteNames); - /// - /// The DsAddressToSiteNamesEx function obtains the site and subnet names corresponding to the addresses specified. - /// + /// The DsAddressToSiteNamesEx function obtains the site and subnet names corresponding to the addresses specified. /// - /// /// Pointer to a null-terminated string that specifies the name of the remote server to process this function. This parameter must be /// the name of a domain controller. A non-domain controller can call this function by calling DsGetDcName to find the domain controller. - /// - /// - /// - /// Contains the number of elements in the SocketAddresses array. /// + /// Contains the number of elements in the SocketAddresses array. /// - /// /// Contains an array of SOCKET_ADDRESS structures that contain the addresses to convert. Each address in this array must be of the /// type AF_INET. EntryCount contains the number of elements in this array. - /// /// /// - /// /// Receives an array of null-terminated string pointers that contain the site names for the addresses. Each element in this array /// corresponds to the same element in the SocketAddresses array. An element is NULL if the corresponding address does not map /// to any known site or if the address entry is not of the proper form. The caller must free this array when it is no longer /// required by calling NetApiBufferFree. - /// /// /// - /// /// Receives an array of null-terminated string pointers that contain the subnet names used to perform the address to site name /// mappings. Each element in this array corresponds to the same element in the SocketAddresses array. An element is NULL if /// the corresponding address to site name mapping was not determined or if no subnet was used to perform the corresponding address /// to site mapping. The latter will be the case when there is exactly one site in the enterprise with no subnet objects mapped to /// it. The caller must free this array when it is no longer required by calling NetApiBufferFree. - /// /// - /// - /// Returns NO_ERROR if successful or a Win32 or RPC error otherwise. The following are possible error codes. - /// - // https://docs.microsoft.com/en-us/windows/desktop/api/dsgetdc/nf-dsgetdc-dsaddresstositenamesexa DSGETDCAPI DWORD - // DsAddressToSiteNamesExA( IN LPCSTR ComputerName, IN DWORD EntryCount, IN PSOCKET_ADDRESS SocketAddresses, OUT LPSTR **SiteNames, - // OUT LPSTR **SubnetNames ); + /// Returns NO_ERROR if successful or a Win32 or RPC error otherwise. The following are possible error codes. + // https://docs.microsoft.com/en-us/windows/desktop/api/dsgetdc/nf-dsgetdc-dsaddresstositenamesexw + // DSGETDCAPI DWORD DsAddressToSiteNamesExW( IN LPCWSTR ComputerName, IN DWORD EntryCount, IN PSOCKET_ADDRESS SocketAddresses, OUT LPWSTR **SiteNames, OUT LPWSTR **SubnetNames ); [DllImport(Lib.NetApi32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("dsgetdc.h", MSDNShortId = "60ac6195-6e43-46da-a1e6-74ec989cd0c4")] public static extern Win32Error DsAddressToSiteNamesEx(string ComputerName, uint EntryCount, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] SOCKET_ADDRESS[] SocketAddresses, out SafeNetApiBuffer SiteNames, out SafeNetApiBuffer SubnetNames); @@ -492,11 +468,8 @@ namespace Vanara.PInvoke [PInvokeData("dsgetdc.h", MSDNShortId = "18ab6455-dab2-42d9-b68e-a8f0ad2d8091")] public static extern Win32Error DsDeregisterDnsHostRecords([Optional] string ServerName, string DnsDomainName, IntPtr DomainGuid, IntPtr DsaGuid, string DnsHostName); - /// - /// The DsEnumerateDomainTrusts function obtains domain trust data for a specified domain. - /// - /// - /// + /// The DsEnumerateDomainTrusts function obtains domain trust data for a specified domain. + /// /// Pointer to a null-terminated string that specifies the name of a computer in the domain to obtain the trust information for. If /// this parameter is NULL, the name of the local computer is used. The caller must be an authenticated user in this domain. /// @@ -505,10 +478,8 @@ namespace Vanara.PInvoke /// controller, this function obtains the trust data from cached data if the cached data is not expired. If the cached data is /// expired, this function obtains the trust data from a domain controller in the domain that this computer is a member of and /// updates the cache. The cached data automatically expires after five minutes. - /// - /// - /// - /// + /// + /// /// Contains a set of flags that determines which domain trusts to enumerate. This can be zero or a combination of one or more of the /// following values. /// @@ -523,28 +494,19 @@ namespace Vanara.PInvoke /// DS_DOMAIN_PRIMARY /// Enumerate domains that are the primary domain of the domain which has ServerName as a member. /// DS_DOMAIN_TREE_ROOT - /// Enumerate domains that are at the root of the forest which has ServerName as a member. - /// - /// - /// - /// Pointer to a PDS_DOMAIN_TRUSTS value that receives an array of DS_DOMAIN_TRUSTS structures. Each structure in this array - /// contains trust data about a domain. The caller must free this memory when it is no longer required by calling NetApiBufferFree. - /// - /// - /// - /// Pointer to a ULONG value that receives the number of elements returned in the Domains array. - /// + /// Enumerate domains that are at the root of the forest which has ServerName as a member. + /// Pointer to a PDS_DOMAIN_TRUSTS value that receives an array of DS_DOMAIN_TRUSTS structures. Each structure in this array + /// contains trust data about a domain. The caller must free this memory when it is no longer required by calling NetApiBufferFree. + /// Pointer to a ULONG value that receives the number of elements returned in the Domains array. /// - /// /// Returns ERROR_SUCCESS if successful or a Win32 error code otherwise. Possible error codes include those listed in the /// following list. - /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/dsgetdc/nf-dsgetdc-dsenumeratedomaintrustsa DSGETDCAPI DWORD // DsEnumerateDomainTrustsA( LPSTR ServerName, ULONG Flags, PDS_DOMAIN_TRUSTSA *Domains, PULONG DomainCount ); [DllImport(Lib.NetApi32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("dsgetdc.h", MSDNShortId = "6c3b788f-ee53-4637-acdb-04316e8464fe")] - public static extern Win32Error DsEnumerateDomainTrusts([Optional] string ServerName, DomainTrustFlag Flags, out SafeNetApiBuffer Domains, out uint DomainCount); + public static extern Win32Error DsEnumerateDomainTrusts([Optional] string ServerName, [Optional] DomainTrustFlag Flags, out SafeNetApiBuffer Domains, out uint DomainCount); /// /// The DsGetDcClose function closes a domain controller enumeration operation. @@ -562,7 +524,351 @@ namespace Vanara.PInvoke // GetDcContextHandle ); [DllImport(Lib.NetApi32, SetLastError = false, EntryPoint = "DsGetDcCloseW")] [PInvokeData("dsgetdc.h", MSDNShortId = "d193e4cd-ad66-4d93-b912-348f17e93a6f")] - public static extern void DsGetDcClose(SafeDCEnumHandle GetDcContextHandle); + public static extern void DsGetDcClose(HANDLE GetDcContextHandle); + + /// + /// The DsGetDcName function returns the name of a domain controller in a specified domain. This function accepts additional + /// domain controller selection criteria to indicate preference for a domain controller with particular characteristics. + /// + /// + /// Pointer to a null-terminated string that specifies the name of the server to process this function. Typically, this parameter is + /// NULL, which indicates that the local computer is used. + /// + /// + /// + /// Pointer to a null-terminated string that specifies the name of the domain or application partition to query. This name can either + /// be a DNS style name, for example, fabrikam.com, or a flat-style name, for example, Fabrikam. If a DNS style name is specified, + /// the name may be specified with or without a trailing period. + /// + /// + /// If the Flags parameter contains the DS_GC_SERVER_REQUIRED flag, DomainName must be the name of the forest. In this case, + /// DsGetDcName fails if DomainName specifies a name that is not the forest root. + /// + /// + /// If the Flags parameter contains the DS_GC_SERVER_REQUIRED flag and DomainName is NULL, DsGetDcName attempts + /// to find a global catalog in the forest of the computer identified by ComputerName, which is the local computer if ComputerName is NULL. + /// + /// + /// If DomainName is NULL and the Flags parameter does not contain the DS_GC_SERVER_REQUIRED flag, ComputerName is set + /// to the default domain name of the primary domain of the computer identified by ComputerName. + /// + /// + /// + /// Pointer to a GUID structure that specifies the GUID of the domain queried. If DomainGuid is not NULL and the domain + /// specified by DomainName or ComputerName cannot be found, DsGetDcName attempts to locate a domain controller in the domain + /// having the GUID specified by DomainGuid. + /// + /// + /// Pointer to a null-terminated string that specifies the name of the site where the returned domain controller should physically + /// exist. If this parameter is NULL, DsGetDcName attempts to return a domain controller in the site closest to the + /// site of the computer specified by ComputerName. This parameter should be NULL, by default. + /// + /// + /// + /// Contains a set of flags that provide additional data used to process the request. This parameter can be a combination of the + /// following values. + /// + /// DS_AVOID_SELF + /// + /// When called from a domain controller, specifies that the returned domain controller name should not be the current computer. If + /// the current computer is not a domain controller, this flag is ignored. This flag can be used to obtain the name of another domain + /// controller in the domain. + /// + /// DS_BACKGROUND_ONLY + /// + /// If the DS_FORCE_REDISCOVERY flag is not specified, this function uses cached domain controller data. If the cached data is + /// more than 15 minutes old, the cache is refreshed by pinging the domain controller. If this flag is specified, this refresh is + /// avoided even if the cached data is expired. This flag should be used if the DsGetDcName function is called periodically. + /// + /// DS_DIRECTORY_SERVICE_PREFERRED + /// + /// DsGetDcName attempts to find a domain controller that supports directory service functions. If a domain controller that + /// supports directory services is not available, DsGetDcName returns the name of a non-directory service domain controller. + /// However, DsGetDcName only returns a non-directory service domain controller after the attempt to find a directory service + /// domain controller times out. + /// + /// DS_DIRECTORY_SERVICE_REQUIRED + /// Requires that the returned domain controller support directory services. + /// DS_DIRECTORY_SERVICE_6_REQUIRED + /// Requires that the returned domain controller be running Windows Server 2008 or later. + /// DS_DIRECTORY_SERVICE_8_REQUIRED + /// Requires that the returned domain controller be running Windows Server 2012 or later. + /// DS_FORCE_REDISCOVERY + /// + /// Forces cached domain controller data to be ignored. When the DS_FORCE_REDISCOVERY flag is not specified, + /// DsGetDcName may return cached domain controller data. If this flag is specified, DsGetDcName will not use cached + /// information (if any exists) but will instead perform a fresh domain controller discovery. + /// + /// + /// This flag should not be used under normal conditions, as using the cached domain controller information has better performance + /// characteristics and helps to ensure that the same domain controller is used consistently by all applications. This flag should be + /// used only after the application determines that the domain controller returned by DsGetDcName (when called without this + /// flag) is not accessible. In that case, the application should repeat the DsGetDcName call with this flag to ensure that + /// the unuseful cached information (if any) is ignored and a reachable domain controller is discovered. + /// + /// DS_GC_SERVER_REQUIRED + /// + /// Requires that the returned domain controller be a global catalog server for the forest of domains with this domain as the root. + /// If this flag is set and the DomainName parameter is not NULL, DomainName must specify a forest name. This flag cannot be + /// combined with the DS_PDC_REQUIRED or DS_KDC_REQUIRED flags. + /// + /// DS_GOOD_TIMESERV_PREFERRED + /// + /// DsGetDcName attempts to find a domain controller that is a reliable time server. The Windows Time Service can be + /// configured to declare one or more domain controllers as a reliable time server. For more information, see the Windows Time + /// Service documentation. This flag is intended to be used only by the Windows Time Service. + /// + /// DS_IP_REQUIRED + /// + /// This parameter indicates that the domain controller must have an IP address. In that case, DsGetDcName will place the + /// Internet protocol address of the domain controller in the DomainControllerAddress member of DomainControllerInfo. + /// + /// DS_IS_DNS_NAME + /// Specifies that the DomainName parameter is a DNS name. This flag cannot be combined with the DS_IS_FLAT_NAME flag. + /// + /// Specify either DS_IS_DNS_NAME or DS_IS_FLAT_NAME. If neither flag is specified, DsGetDcName may take longer + /// to find a domain controller because it may have to search for both the DNS-style and flat name. + /// + /// DS_IS_FLAT_NAME + /// Specifies that the DomainName parameter is a flat name. This flag cannot be combined with the DS_IS_DNS_NAME flag. + /// DS_KDC_REQUIRED + /// + /// Requires that the returned domain controller be currently running the Kerberos Key Distribution Center service. This flag cannot + /// be combined with the DS_PDC_REQUIRED or DS_GC_SERVER_REQUIRED flags. + /// + /// DS_ONLY_LDAP_NEEDED + /// + /// Specifies that the server returned is an LDAP server. The server returned is not necessarily a domain controller. No other + /// services are implied to be present at the server. The server returned does not necessarily have a writable config + /// container nor a writable schema container. The server returned may not necessarily be used to create or modify security + /// principles. This flag may be used with the DS_GC_SERVER_REQUIRED flag to return an LDAP server that also hosts a global + /// catalog server. The returned global catalog server is not necessarily a domain controller. No other services are implied to be + /// present at the server. If this flag is specified, the DS_PDC_REQUIRED, DS_TIMESERV_REQUIRED, + /// DS_GOOD_TIMESERV_PREFERRED, DS_DIRECTORY_SERVICES_PREFERED, DS_DIRECTORY_SERVICES_REQUIRED, and + /// DS_KDC_REQUIRED flags are ignored. + /// + /// DS_PDC_REQUIRED + /// + /// Requires that the returned domain controller be the primary domain controller for the domain. This flag cannot be combined with + /// the DS_KDC_REQUIRED or DS_GC_SERVER_REQUIRED flags. + /// + /// DS_RETURN_DNS_NAME + /// + /// Specifies that the names returned in the DomainControllerName and DomainName members of DomainControllerInfo should + /// be DNS names. If a DNS name is not available, an error is returned. This flag cannot be specified with the + /// DS_RETURN_FLAT_NAME flag. This flag implies the DS_IP_REQUIRED flag. + /// + /// DS_RETURN_FLAT_NAME + /// + /// Specifies that the names returned in the DomainControllerName and DomainName members of DomainControllerInfo should + /// be flat names. If a flat name is not available, an error is returned. This flag cannot be specified with the + /// DS_RETURN_DNS_NAME flag. + /// + /// DS_TIMESERV_REQUIRED + /// Requires that the returned domain controller be currently running the Windows Time Service. + /// DS_TRY_NEXTCLOSEST_SITE + /// + /// When this flag is specified, DsGetDcName attempts to find a domain controller in the same site as the caller. If no such + /// domain controller is found, it will find a domain controller that can provide topology information and call DsBindToISTG to + /// obtain a bind handle, then call DsQuerySitesByCost over UDP to determine the "next closest site," and finally cache the name of + /// the site found. If no domain controller is found in that site, then DsGetDcName falls back on the default method of + /// locating a domain controller. + /// + /// + /// If this flag is used in conjunction with a non-NULL value in the input parameter SiteName, then ERROR_INVALID_FLAGS is thrown. + /// + /// + /// Also, the kind of search employed with DS_TRY_NEXT_CLOSEST_SITE is site-specific, so this flag is ignored if it is used in + /// conjunction with DS_PDC_REQUIRED. Finally, DS_TRY_NEXTCLOSEST_SITE is ignored when used in conjunction with + /// DS_RETURN_FLAT_NAME because that uses NetBIOS to resolve the name, but the domain of the domain controller found won't + /// necessarily match the domain to which the client is joined. + /// + /// + /// Note This flag is Group Policy enabled. If you enable the "Next Closest Site" policy setting, Next Closest Site DC + /// Location will be turned on for the machine across all available but un-configured network adapters. If you disable the policy + /// setting, Next Closest Site DC Location will not be used by default for the machine across all available but un-configured network + /// adapters. However, if a DC Locator call is made using the DS_TRY_NEXTCLOSEST_SITE flag explicitly, DsGetDcName + /// honors the Next Closest Site behavior. If you do not configure this policy setting, Next Closest Site DC Location will be not be + /// used by default for the machine across all available but un-configured network adapters. If the DS_TRY_NEXTCLOSEST_SITE + /// flag is used explicitly, the Next Closest Site behavior will be used. + /// + /// DS_WRITABLE_REQUIRED + /// Requires that the returned domain controller be writable; that is, host a writable copy of the directory service. + /// DS_WEB_SERVICE_REQUIRED + /// Requires that the returned domain controller be currently running the Active Directory web service. + /// + /// + /// Pointer to a PDOMAIN_CONTROLLER_INFO value that receives a pointer to a DOMAIN_CONTROLLER_INFO structure that contains + /// data about the domain controller selected. This structure is allocated by DsGetDcName. The caller must free the structure + /// using the NetApiBufferFree function when it is no longer required. + /// + /// + /// If the function returns domain controller data, the return value is ERROR_SUCCESS. + /// If the function fails, the return value can be one of the following error codes. + /// + /// + /// + /// The DsGetDcName function is sent to the Netlogon service on the remote computer specified by ComputerName. If ComputerName + /// is NULL, the function is processed on the local computer. + /// + /// + /// DsGetDcName does not verify that the domain controller name returned is the name of an actual domain controller or global + /// catalog. If mutual authentication is required, the caller must perform the authentication. + /// + /// + /// DsGetDcName does not require any particular access to the specified domain. By default, this function does not ensure that + /// the returned domain controller is currently available. Instead, the caller should attempt to use the returned domain controller. + /// If the domain controller is not available, the caller should call the DsGetDcName function again, specifying the + /// DS_FORCE_REDISCOVERY flag. + /// + /// Response Time + /// When using DsGetDcName be aware of the following timing details: + /// + /// + /// + /// DsGetDcName makes network calls and can take from a few seconds up to one minute, depending on network traffic, topology, + /// DC load, and so on. + /// + /// + /// + /// It is NOT recommended to call DsGetDcName from a UI or other timing critical thread. + /// + /// + /// + /// The DC Locator does use optimized logic to provide the DC information as quickly as possible. It also uses cached information at + /// the site to contact the closest DC. + /// + /// + /// + /// Notes on Domain Controller Stickiness + /// + /// In Active Directory Domain Services, the domain controller locator function is designed so that once a client finds a preferred + /// domain controller, the client will not look for another unless that domain controller stops responding or the client is + /// restarted. This is referred to as "Domain Controller Stickiness." Because workstations typically operate for months without a + /// problem or restart, one unintended consequence of this behavior is that if a particular domain controller goes down for + /// maintenance, all of the clients that were connected to it shift their connections to another domain controller. But when the + /// domain controller comes back up, no clients ever reconnect to it because the clients do not restart very often. This can cause + /// load-balancing problems. + /// + /// + /// Previously, the most common solution to this problem was to deploy a script on each client machine that periodically called + /// DsGetDcName using the flag. This was a somewhat cumbersome solution, so Windows Server 2008 and Windows Vista introduced a + /// new mechanism that caused issues with domain controller stickiness. + /// + /// + /// Whenever DsGetDcName retrieves a domain controller name from its cache, it checks to see if this cached entry is expired, + /// and if so, discards that domain controller name and tries to rediscover a domain controller name. The life span of a cached entry + /// is controlled by the value in the following registry keys + /// + /// HKEY_LOCAL_MACHINE<b>SYSTEM<b>CurrentControlSet<b>Services<b>Netlogon<b>Parameters<b>ForceRediscoveryInterval + /// and + /// HKEY_LOCAL_MACHINE<b>Software<b>Policies<b>Microsoft<b>Netlogon<b>Parameters<b>ForceRediscoveryInterval + /// + /// The values in these registry keys are of type REG_DWORD. They specify the length in seconds before DsGetDcName + /// should try to rediscover the domain controller name. The default value is 43200 seconds (12 hours). If the value of the + /// ForceRediscoveryInterval registry entry is set to 0, the client always performs rediscovery. If the value is set to + /// 4294967295, the cache never expires, and the cached domain controller continues to be used. We recommend that you do not set the + /// ForceRediscoveryInterval registry entry to a value that is less than 3600 seconds (60 minutes). + /// + /// + /// Note The registry settings of ForceRediscoveryInterval are group policy enabled. If you disable the policy setting, + /// Force Rediscovery will used by default for the machine at every 12 hour interval. If you do not configure this policy setting, + /// Force Rediscovery will used by default for the machine at every 12 hour interval, unless the local machine setting in the + /// registry is a different value. + /// + /// + /// Note that if the DS_BACKGROUND_ONLY flag is specified, DsGetDcName will never try to rediscover the domain + /// controller name, since the point of that flag is to force DsGetDcName to use the cached domain controller name even if it + /// is expired. + /// + /// ETW Tracing in DsGetDcName + /// To turn on ETW Tracing for DsGetDcName, create the following registry key: + /// HKEY_LOCAL_MACHINE<b>System<b>CurrentControlSet<b>Services<b>DCLocator<b>Tracing + /// The key will have a structure as follows: + /// + /// ProcessName must be the full name including extension of the process that you want to get trace information for. PID is only + /// required when multiple processes with the same name exist. If it is defined, then only the process with that PID will be enabled + /// for tracing. It is not possible to trace only 2 out of 3 (or more) processes with the same name. You can enable one instance or + /// all instances (when multiple instances with the same process name exist and PID is not specified, all instances will be enabled + /// for tracing). + /// + /// + /// For example, this would trace all instances of App1.exe and App2.exe, but only the instance of App3.exe that has a PID of 999: + /// + /// Run the following command to start the tracing session: + /// tracelog.exe -start <sessionname> -guid #cfaa5446-c6c4-4f5c-866f-31c9b55b962d -f <filename> -flag <traceFlags> + /// + /// sessionname is the name given for the trace session. The guid for the DCLocator tracing provider is + /// "cfaa5446-c6c4-4f5c-866f-31c9b55b962d". filename is the name of the log file to which the events are written. traceFlags is one + /// or more of the following flags which signify which areas to trace: + /// + /// + /// + /// Flag + /// Hex Value + /// Description + /// + /// + /// DCLOCATOR_MISC + /// 0x00000002 + /// Miscellaneous debugging + /// + /// + /// DCLOCATOR_MAILSLOT + /// 0x00000010 + /// Mailslot messages + /// + /// + /// DCLOCATOR_SITE + /// 0x00000020 + /// Sites + /// + /// + /// DCLOCATOR_CRITICAL + /// 0x00000100 + /// Important errors + /// + /// + /// DCLOCATOR_SESSION_SETUP + /// 0x00000200 + /// Trusted Domain Maintenance + /// + /// + /// DCLOCATOR_DNS + /// 0x00004000 + /// Name Registration + /// + /// + /// DCLOCATOR_DNS_MORE + /// 0x00020000 + /// Verbose Name Registration + /// + /// + /// DCLOCATOR_MAILBOX_TEXT + /// 0x02000000 + /// Verbose Mailbox Messages + /// + /// + /// DCLOCATOR_SITE_MORE + /// 0x08000000 + /// Verbose sites + /// + /// + /// Run the following command to stop the trace session: + /// tracelog.exe -stop <sessionname> + /// sessionname is the same name as the name you used when starting the session. + /// + /// Note The registry key for the process being traced must be present in the registry at the time the trace session is + /// started. When the session starts, the process will verify whether or not it should be generating trace messages (based on the + /// presence or absence of a registry key for that process name and optional PID). The process checks the registry only at the start + /// of the session. Any changes in the registry occurring after that will not have any effect on tracing. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/dsgetdc/nf-dsgetdc-dsgetdcnamea + // DSGETDCAPI DWORD DsGetDcNameA( IN LPCSTR ComputerName, IN LPCSTR DomainName, IN GUID *DomainGuid, IN LPCSTR SiteName, IN ULONG Flags, OUT PDOMAIN_CONTROLLER_INFOA *DomainControllerInfo ); + [DllImport(Lib.NetApi32, SetLastError = false, CharSet = CharSet.Auto)] + [PInvokeData("dsgetdc.h", MSDNShortId = "da8b2983-5e45-40b0-b552-c9b3a1d8ae94")] + public static extern Win32Error DsGetDcName([Optional] string ComputerName, [Optional] string DomainName, in Guid DomainGuid, [Optional] string SiteName, DsGetDcNameFlags Flags, out SafeNetApiBuffer DomainControllerInfo); /// /// The DsGetDcName function returns the name of a domain controller in a specified domain. This function accepts additional domain @@ -614,59 +920,7 @@ namespace Vanara.PInvoke /// [DllImport(Lib.NetApi32, CharSet = CharSet.Auto)] [PInvokeData("DsGetDC.h", MSDNShortId = "ms675983")] - public static extern Win32Error DsGetDcName(string ComputerName, string DomainName, in Guid DomainGuid, string SiteName, DsGetDcNameFlags Flags, out SafeNetApiBuffer DomainControllerInfo); - - /// - /// The DsGetDcName function returns the name of a domain controller in a specified domain. This function accepts additional domain - /// controller selection criteria to indicate preference for a domain controller with particular characteristics. - /// - /// - /// Pointer to a null-terminated string that specifies the name of the server to process this function. Typically, this parameter is - /// NULL, which indicates that the local computer is used. - /// - /// - /// Pointer to a null-terminated string that specifies the name of the domain or application partition to query. This name can either - /// be a DNS style name, for example, fabrikam.com, or a flat-style name, for example, Fabrikam. If a DNS style name is specified, - /// the name may be specified with or without a trailing period. - /// - /// If the Flags parameter contains the DS_GC_SERVER_REQUIRED flag, DomainName must be the name of the forest. In this case, - /// DsGetDcName fails if DomainName specifies a name that is not the forest root. - /// - /// - /// If the Flags parameter contains the DS_GC_SERVER_REQUIRED flag and DomainName is NULL, DsGetDcName attempts to find a global - /// catalog in the forest of the computer identified by ComputerName, which is the local computer if ComputerName is NULL. - /// - /// - /// If DomainName is NULL and the Flags parameter does not contain the DS_GC_SERVER_REQUIRED flag, ComputerName is set to the default - /// domain name of the primary domain of the computer identified by ComputerName. - /// - /// - /// - /// Pointer to a GUID structure that specifies the GUID of the domain queried. If DomainGuid is not NULL and the domain specified by - /// DomainName or ComputerName cannot be found, DsGetDcName attempts to locate a domain controller in the domain having the GUID - /// specified by DomainGuid. - /// - /// - /// Pointer to a null-terminated string that specifies the name of the site where the returned domain controller should physically - /// exist. If this parameter is NULL, DsGetDcName attempts to return a domain controller in the site closest to the site of the - /// computer specified by ComputerName. This parameter should be NULL, by default. - /// - /// - /// Contains a set of flags that provide additional data used to process the request. This parameter can be a combination of the - /// following values. - /// - /// - /// Pointer to a PDOMAIN_CONTROLLER_INFO value that receives a pointer to a DOMAIN_CONTROLLER_INFO structure that contains data about - /// the domain controller selected. This structure is allocated by DsGetDcName. The caller must free the structure using the - /// NetApiBufferFree function when it is no longer required. - /// - /// - /// If the function returns domain controller data, the return value is ERROR_SUCCESS. - /// If the function fails, the return value can be one of the following error codes. - /// - [DllImport(Lib.NetApi32, CharSet = CharSet.Auto)] - [PInvokeData("DsGetDC.h", MSDNShortId = "ms675983")] - public static extern Win32Error DsGetDcName(string ComputerName, string DomainName, IntPtr DomainGuid, string SiteName, DsGetDcNameFlags Flags, out SafeNetApiBuffer DomainControllerInfo); + public static extern Win32Error DsGetDcName([Optional] string ComputerName, [Optional] string DomainName, [Optional] IntPtr DomainGuid, [Optional] string SiteName, DsGetDcNameFlags Flags, out SafeNetApiBuffer DomainControllerInfo); /// /// The DsGetDcNext function retrieves the next domain controller in a domain controller enumeration operation. @@ -1005,8 +1259,7 @@ namespace Vanara.PInvoke /// /// /// - /// Pointer to a variable that receives a pointer to a null-terminated string specifying the site location of this computer. This - /// string is allocated by the system and must be freed using the NetApiBufferFree function. + /// Pointer to a variable that receives a pointer to a null-terminated string specifying the site location of this computer. /// /// /// @@ -1023,7 +1276,7 @@ namespace Vanara.PInvoke // ComputerName, OUT LPSTR *SiteName ); [DllImport(Lib.NetApi32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("dsgetdc.h", MSDNShortId = "2dfffd9a-af4f-4a93-8b3c-966e4f7c455f")] - public static extern Win32Error DsGetSiteName([Optional] string ComputerName, out SafeNetApiBuffer SiteName); + public static extern Win32Error DsGetSiteName([Optional] string ComputerName, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(NetApiBufferUnicodeStringMarshaler))] out string SiteName); /// /// @@ -1290,7 +1543,7 @@ namespace Vanara.PInvoke private SafeDCEnumHandle() : base() { } /// - protected override bool InternalReleaseHandle() { DsGetDcClose(this); return true; } + protected override bool InternalReleaseHandle() { DsGetDcClose(handle); return true; } } } } \ No newline at end of file diff --git a/PInvoke/NetApi32/DsRole.cs b/PInvoke/NetApi32/DsRole.cs index 8b398912..839753c8 100644 --- a/PInvoke/NetApi32/DsRole.cs +++ b/PInvoke/NetApi32/DsRole.cs @@ -104,7 +104,7 @@ namespace Vanara.PInvoke { /// The DsRoleGetPrimaryDomainInformation function retrieves data from a DSROLE_PRIMARY_DOMAIN_INFO_BASIC structure. [CorrespondingType(typeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC), CorrepsondingAction.Get)] - DsRolePrimaryDomainInfoBasic, + DsRolePrimaryDomainInfoBasic = 1, /// The DsRoleGetPrimaryDomainInformation function retrieves from a DSROLE_UPGRADE_STATUS_INFO structure. [CorrespondingType(typeof(DSROLE_UPGRADE_STATUS_INFO), CorrepsondingAction.Get)] @@ -147,25 +147,19 @@ namespace Vanara.PInvoke // https://docs.microsoft.com/en-us/windows/desktop/api/dsrole/nf-dsrole-dsrolefreememory void DsRoleFreeMemory( IN PVOID Buffer ); [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("dsrole.h", MSDNShortId = "5560dfec-2134-4e02-9c87-26d246cd5841")] - public static extern void DsRoleFreeMemory(SafeDcRoleBuffer Buffer); + public static extern void DsRoleFreeMemory(IntPtr Buffer); /// - /// /// The DsRoleGetPrimaryDomainInformation function retrieves state data for the computer. This data includes the state of the /// directory service installation and domain data. - /// /// /// - /// /// Pointer to null-terminated Unicode string that contains the name of the computer on which to call the function. If this parameter /// is NULL, the local computer is used. - /// /// /// - /// /// Contains one of the DSROLE_PRIMARY_DOMAIN_INFO_LEVEL values that specify the type of data to retrieve. This parameter also /// determines the format of the data supplied in Buffer. - /// /// /// /// @@ -182,7 +176,7 @@ namespace Vanara.PInvoke // DsRoleGetPrimaryDomainInformation( IN LPCWSTR lpServer, IN DSROLE_PRIMARY_DOMAIN_INFO_LEVEL InfoLevel, OUT PBYTE *Buffer ); [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true)] [PInvokeData("dsrole.h", MSDNShortId = "d54876e3-a622-4b44-a597-db0f710f7758")] - public static extern uint DsRoleGetPrimaryDomainInformation([MarshalAs(UnmanagedType.LPWStr)] string lpServer, DSROLE_PRIMARY_DOMAIN_INFO_LEVEL InfoLevel, out SafeDcRoleBuffer Buffer); + public static extern Win32Error DsRoleGetPrimaryDomainInformation([In, MarshalAs(UnmanagedType.LPWStr), Optional] string lpServer, DSROLE_PRIMARY_DOMAIN_INFO_LEVEL InfoLevel, out SafeDcRoleBuffer Buffer); /// /// @@ -314,7 +308,7 @@ namespace Vanara.PInvoke public T ToStructure() where T : struct => IsInvalid ? default : (T)Marshal.PtrToStructure(handle, typeof(T)); /// - protected override bool InternalReleaseHandle() { DsRoleFreeMemory(this); return true; } + protected override bool InternalReleaseHandle() { DsRoleFreeMemory(handle); return true; } } } } \ No newline at end of file diff --git a/PInvoke/NetApi32/Lm.Ext.cs b/PInvoke/NetApi32/Lm.Ext.cs index 42c4f343..f507ae44 100644 --- a/PInvoke/NetApi32/Lm.Ext.cs +++ b/PInvoke/NetApi32/Lm.Ext.cs @@ -1,14 +1,683 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.InteropServices; using Vanara.Extensions; +using Vanara.InteropServices; +using static Vanara.PInvoke.Ws2_32; namespace Vanara.PInvoke { public static partial class NetApi32 { - /// Inherit from this interface for any implementation of the SERVER_INFO_XXXX structures to use the helper functions. - public interface INetServerInfo { } + /// The DsAddressToSiteNamesEx function obtains the site and subnet names corresponding to the addresses specified. + /// + /// String that specifies the name of the remote server to process this function. This parameter must be the name of a domain + /// controller. A non-domain controller can call this function by calling DsGetDcName to find the domain controller. + /// + /// + /// Contains an array of SOCKET_ADDRESS structures that contain the addresses to convert. Each address in this array must be of the + /// type AF_INET. + /// + /// + /// Returns a list that contains the supplied SOCKET_ADDRESS structure with its corresponding site name and subnet name. An + /// value is if the corresponding address does not map to any known site or subnet or if the address entry is + /// not of the proper form. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/dsgetdc/nf-dsgetdc-dsaddresstositenamesexa DSGETDCAPI DWORD + // DsAddressToSiteNamesExA( IN LPCSTR ComputerName, IN DWORD EntryCount, IN PSOCKET_ADDRESS SocketAddresses, OUT LPSTR **SiteNames, + // OUT LPSTR **SubnetNames ); + [PInvokeData("dsgetdc.h", MSDNShortId = "60ac6195-6e43-46da-a1e6-74ec989cd0c4")] + public static IEnumerable<(SOCKET_ADDRESS address, string site, string subnet)> DsAddressToSiteNamesEx(string ComputerName, SOCKET_ADDRESS[] SocketAddresses) + { + DsAddressToSiteNamesEx(ComputerName, (uint)(SocketAddresses?.Length ?? 0), SocketAddresses, out var sites, out var subnets).ThrowIfFailed(); + return from addr in SocketAddresses + from site in sites.ToStringEnum(SocketAddresses.Length) + from sub in subnets.ToStringEnum(SocketAddresses.Length) + select (addr, site, sub); + } + + /// The DsEnumerateDomainTrusts function obtains domain trust data for a specified domain. + /// + /// + /// A string that specifies the name of a computer in the domain to obtain the trust information for. If this parameter is + /// , the name of the local computer is used. The caller must be an authenticated user in this domain. + /// + /// + /// If this computer is a domain controller, this function returns the trust data immediately. If this computer is not a domain + /// controller, this function obtains the trust data from cached data if the cached data is not expired. If the cached data is + /// expired, this function obtains the trust data from a domain controller in the domain that this computer is a member of and + /// updates the cache. The cached data automatically expires after five minutes. + /// + /// + /// + /// + /// Contains a set of flags that determines which domain trusts to enumerate. This can be a combination of one or more of the + /// following values. + /// + /// DS_DOMAIN_DIRECT_INBOUND + /// Enumerate domains that directly trust the domain which has ServerName as a member. + /// DS_DOMAIN_DIRECT_OUTBOUND + /// Enumerate domains directly trusted by the domain which has ServerName as a member. + /// DS_DOMAIN_IN_FOREST + /// Enumerate domains that are a member of the same forest which has ServerName as a member. + /// DS_DOMAIN_NATIVE_MODE + /// Enumerate domains where the primary domain is running in Windows 2000 native mode. + /// DS_DOMAIN_PRIMARY + /// Enumerate domains that are the primary domain of the domain which has ServerName as a member. + /// DS_DOMAIN_TREE_ROOT + /// Enumerate domains that are at the root of the forest which has ServerName as a member. + /// + /// An enumeration of DS_DOMAIN_TRUSTS structures. Each structure in this array contains trust data about a domain. + // https://docs.microsoft.com/en-us/windows/desktop/api/dsgetdc/nf-dsgetdc-dsenumeratedomaintrustsa DSGETDCAPI DWORD + // DsEnumerateDomainTrustsA( LPSTR ServerName, ULONG Flags, PDS_DOMAIN_TRUSTSA *Domains, PULONG DomainCount ); + [PInvokeData("dsgetdc.h", MSDNShortId = "6c3b788f-ee53-4637-acdb-04316e8464fe")] + public static IEnumerable DsEnumerateDomainTrusts(DomainTrustFlag Flags, string ServerName = null) + { + DsEnumerateDomainTrusts(ServerName, Flags, out var buf, out var cnt).ThrowIfFailed(); + return buf.ToIEnum((int)cnt); + } + + /// + /// The DsGetDcName function returns the name of a domain controller in a specified domain. This function accepts additional + /// domain controller selection criteria to indicate preference for a domain controller with particular characteristics. + /// + /// + /// + /// Contains a set of flags that provide additional data used to process the request. This parameter can be a combination of the + /// following values. + /// + /// DS_AVOID_SELF + /// + /// When called from a domain controller, specifies that the returned domain controller name should not be the current computer. If + /// the current computer is not a domain controller, this flag is ignored. This flag can be used to obtain the name of another domain + /// controller in the domain. + /// + /// DS_BACKGROUND_ONLY + /// + /// If the DS_FORCE_REDISCOVERY flag is not specified, this function uses cached domain controller data. If the cached data is + /// more than 15 minutes old, the cache is refreshed by pinging the domain controller. If this flag is specified, this refresh is + /// avoided even if the cached data is expired. This flag should be used if the DsGetDcName function is called periodically. + /// + /// DS_DIRECTORY_SERVICE_PREFERRED + /// + /// DsGetDcName attempts to find a domain controller that supports directory service functions. If a domain controller that + /// supports directory services is not available, DsGetDcName returns the name of a non-directory service domain controller. + /// However, DsGetDcName only returns a non-directory service domain controller after the attempt to find a directory service + /// domain controller times out. + /// + /// DS_DIRECTORY_SERVICE_REQUIRED + /// Requires that the returned domain controller support directory services. + /// DS_DIRECTORY_SERVICE_6_REQUIRED + /// Requires that the returned domain controller be running Windows Server 2008 or later. + /// DS_DIRECTORY_SERVICE_8_REQUIRED + /// Requires that the returned domain controller be running Windows Server 2012 or later. + /// DS_FORCE_REDISCOVERY + /// + /// Forces cached domain controller data to be ignored. When the DS_FORCE_REDISCOVERY flag is not specified, + /// DsGetDcName may return cached domain controller data. If this flag is specified, DsGetDcName will not use cached + /// information (if any exists) but will instead perform a fresh domain controller discovery. + /// + /// + /// This flag should not be used under normal conditions, as using the cached domain controller information has better performance + /// characteristics and helps to ensure that the same domain controller is used consistently by all applications. This flag should be + /// used only after the application determines that the domain controller returned by DsGetDcName (when called without this + /// flag) is not accessible. In that case, the application should repeat the DsGetDcName call with this flag to ensure that + /// the unuseful cached information (if any) is ignored and a reachable domain controller is discovered. + /// + /// DS_GC_SERVER_REQUIRED + /// + /// Requires that the returned domain controller be a global catalog server for the forest of domains with this domain as the root. + /// If this flag is set and the DomainName parameter is not , DomainName must specify a forest name. This flag cannot be + /// combined with the DS_PDC_REQUIRED or DS_KDC_REQUIRED flags. + /// + /// DS_GOOD_TIMESERV_PREFERRED + /// + /// DsGetDcName attempts to find a domain controller that is a reliable time server. The Windows Time Service can be + /// configured to declare one or more domain controllers as a reliable time server. For more information, see the Windows Time + /// Service documentation. This flag is intended to be used only by the Windows Time Service. + /// + /// DS_IP_REQUIRED + /// + /// This parameter indicates that the domain controller must have an IP address. In that case, DsGetDcName will place the + /// Internet protocol address of the domain controller in the DomainControllerAddress member of DomainControllerInfo. + /// + /// DS_IS_DNS_NAME + /// Specifies that the DomainName parameter is a DNS name. This flag cannot be combined with the DS_IS_FLAT_NAME flag. + /// + /// Specify either DS_IS_DNS_NAME or DS_IS_FLAT_NAME. If neither flag is specified, DsGetDcName may take longer + /// to find a domain controller because it may have to search for both the DNS-style and flat name. + /// + /// DS_IS_FLAT_NAME + /// Specifies that the DomainName parameter is a flat name. This flag cannot be combined with the DS_IS_DNS_NAME flag. + /// DS_KDC_REQUIRED + /// + /// Requires that the returned domain controller be currently running the Kerberos Key Distribution Center service. This flag cannot + /// be combined with the DS_PDC_REQUIRED or DS_GC_SERVER_REQUIRED flags. + /// + /// DS_ONLY_LDAP_NEEDED + /// + /// Specifies that the server returned is an LDAP server. The server returned is not necessarily a domain controller. No other + /// services are implied to be present at the server. The server returned does not necessarily have a writable config + /// container nor a writable schema container. The server returned may not necessarily be used to create or modify security + /// principles. This flag may be used with the DS_GC_SERVER_REQUIRED flag to return an LDAP server that also hosts a global + /// catalog server. The returned global catalog server is not necessarily a domain controller. No other services are implied to be + /// present at the server. If this flag is specified, the DS_PDC_REQUIRED, DS_TIMESERV_REQUIRED, + /// DS_GOOD_TIMESERV_PREFERRED, DS_DIRECTORY_SERVICES_PREFERED, DS_DIRECTORY_SERVICES_REQUIRED, and + /// DS_KDC_REQUIRED flags are ignored. + /// + /// DS_PDC_REQUIRED + /// + /// Requires that the returned domain controller be the primary domain controller for the domain. This flag cannot be combined with + /// the DS_KDC_REQUIRED or DS_GC_SERVER_REQUIRED flags. + /// + /// DS_RETURN_DNS_NAME + /// + /// Specifies that the names returned in the DomainControllerName and DomainName members of DomainControllerInfo should + /// be DNS names. If a DNS name is not available, an error is returned. This flag cannot be specified with the + /// DS_RETURN_FLAT_NAME flag. This flag implies the DS_IP_REQUIRED flag. + /// + /// DS_RETURN_FLAT_NAME + /// + /// Specifies that the names returned in the DomainControllerName and DomainName members of DomainControllerInfo should + /// be flat names. If a flat name is not available, an error is returned. This flag cannot be specified with the + /// DS_RETURN_DNS_NAME flag. + /// + /// DS_TIMESERV_REQUIRED + /// Requires that the returned domain controller be currently running the Windows Time Service. + /// DS_TRY_NEXTCLOSEST_SITE + /// + /// When this flag is specified, DsGetDcName attempts to find a domain controller in the same site as the caller. If no such + /// domain controller is found, it will find a domain controller that can provide topology information and call DsBindToISTG to + /// obtain a bind handle, then call DsQuerySitesByCost over UDP to determine the "next closest site," and finally cache the name of + /// the site found. If no domain controller is found in that site, then DsGetDcName falls back on the default method of + /// locating a domain controller. + /// + /// + /// If this flag is used in conjunction with a non-NULL value in the input parameter SiteName, then ERROR_INVALID_FLAGS is thrown. + /// + /// + /// Also, the kind of search employed with DS_TRY_NEXT_CLOSEST_SITE is site-specific, so this flag is ignored if it is used in + /// conjunction with DS_PDC_REQUIRED. Finally, DS_TRY_NEXTCLOSEST_SITE is ignored when used in conjunction with + /// DS_RETURN_FLAT_NAME because that uses NetBIOS to resolve the name, but the domain of the domain controller found won't + /// necessarily match the domain to which the client is joined. + /// + /// + /// Note This flag is Group Policy enabled. If you enable the "Next Closest Site" policy setting, Next Closest Site DC + /// Location will be turned on for the machine across all available but un-configured network adapters. If you disable the policy + /// setting, Next Closest Site DC Location will not be used by default for the machine across all available but un-configured network + /// adapters. However, if a DC Locator call is made using the DS_TRY_NEXTCLOSEST_SITE flag explicitly, DsGetDcName + /// honors the Next Closest Site behavior. If you do not configure this policy setting, Next Closest Site DC Location will be not be + /// used by default for the machine across all available but un-configured network adapters. If the DS_TRY_NEXTCLOSEST_SITE + /// flag is used explicitly, the Next Closest Site behavior will be used. + /// + /// DS_WRITABLE_REQUIRED + /// Requires that the returned domain controller be writable; that is, host a writable copy of the directory service. + /// DS_WEB_SERVICE_REQUIRED + /// Requires that the returned domain controller be currently running the Active Directory web service. + /// + /// + /// A string that specifies the name of the server to process this function. Typically, this parameter is + /// , which indicates that the local computer is used. + /// + /// + /// + /// A string that specifies the name of the domain or application partition to query. This name can either + /// be a DNS style name, for example, fabrikam.com, or a flat-style name, for example, Fabrikam. If a DNS style name is specified, + /// the name may be specified with or without a trailing period. + /// + /// + /// If the Flags parameter contains the DS_GC_SERVER_REQUIRED flag, DomainName must be the name of the forest. In this case, + /// DsGetDcName fails if DomainName specifies a name that is not the forest root. + /// + /// + /// If the Flags parameter contains the DS_GC_SERVER_REQUIRED flag and DomainName is , DsGetDcName attempts + /// to find a global catalog in the forest of the computer identified by ComputerName, which is the local computer if ComputerName is . + /// + /// + /// If DomainName is and the Flags parameter does not contain the DS_GC_SERVER_REQUIRED flag, ComputerName is set + /// to the default domain name of the primary domain of the computer identified by ComputerName. + /// + /// + /// + /// An optional Guid value that specifies the GUID of the domain queried. If DomainGuid is not and the domain + /// specified by DomainName or ComputerName cannot be found, DsGetDcName attempts to locate a domain controller in the domain + /// having the GUID specified by DomainGuid. + /// + /// + /// A string that specifies the name of the site where the returned domain controller should physically + /// exist. If this parameter is , DsGetDcName attempts to return a domain controller in the site closest to the + /// site of the computer specified by ComputerName. This parameter should be , by default. + /// + /// A DOMAIN_CONTROLLER_INFO structure that contains data about the domain controller selected. + /// + /// + /// The DsGetDcName function is sent to the Netlogon service on the remote computer specified by ComputerName. If ComputerName + /// is , the function is processed on the local computer. + /// + /// + /// DsGetDcName does not verify that the domain controller name returned is the name of an actual domain controller or global + /// catalog. If mutual authentication is required, the caller must perform the authentication. + /// + /// + /// DsGetDcName does not require any particular access to the specified domain. By default, this function does not ensure that + /// the returned domain controller is currently available. Instead, the caller should attempt to use the returned domain controller. + /// If the domain controller is not available, the caller should call the DsGetDcName function again, specifying the + /// DS_FORCE_REDISCOVERY flag. + /// + /// Response Time + /// When using DsGetDcName be aware of the following timing details: + /// + /// + /// + /// DsGetDcName makes network calls and can take from a few seconds up to one minute, depending on network traffic, topology, + /// DC load, and so on. + /// + /// + /// + /// It is NOT recommended to call DsGetDcName from a UI or other timing critical thread. + /// + /// + /// + /// The DC Locator does use optimized logic to provide the DC information as quickly as possible. It also uses cached information at + /// the site to contact the closest DC. + /// + /// + /// + /// Notes on Domain Controller Stickiness + /// + /// In Active Directory Domain Services, the domain controller locator function is designed so that once a client finds a preferred + /// domain controller, the client will not look for another unless that domain controller stops responding or the client is + /// restarted. This is referred to as "Domain Controller Stickiness." Because workstations typically operate for months without a + /// problem or restart, one unintended consequence of this behavior is that if a particular domain controller goes down for + /// maintenance, all of the clients that were connected to it shift their connections to another domain controller. But when the + /// domain controller comes back up, no clients ever reconnect to it because the clients do not restart very often. This can cause + /// load-balancing problems. + /// + /// + /// Previously, the most common solution to this problem was to deploy a script on each client machine that periodically called + /// DsGetDcName using the flag. This was a somewhat cumbersome solution, so Windows Server 2008 and Windows Vista introduced a + /// new mechanism that caused issues with domain controller stickiness. + /// + /// + /// Whenever DsGetDcName retrieves a domain controller name from its cache, it checks to see if this cached entry is expired, + /// and if so, discards that domain controller name and tries to rediscover a domain controller name. The life span of a cached entry + /// is controlled by the value in the following registry keys + /// + /// HKEY_LOCAL_MACHINE<b>SYSTEM<b>CurrentControlSet<b>Services<b>Netlogon<b>Parameters<b>ForceRediscoveryInterval + /// and + /// HKEY_LOCAL_MACHINE<b>Software<b>Policies<b>Microsoft<b>Netlogon<b>Parameters<b>ForceRediscoveryInterval + /// + /// The values in these registry keys are of type REG_DWORD. They specify the length in seconds before DsGetDcName + /// should try to rediscover the domain controller name. The default value is 43200 seconds (12 hours). If the value of the + /// ForceRediscoveryInterval registry entry is set to 0, the client always performs rediscovery. If the value is set to + /// 4294967295, the cache never expires, and the cached domain controller continues to be used. We recommend that you do not set the + /// ForceRediscoveryInterval registry entry to a value that is less than 3600 seconds (60 minutes). + /// + /// + /// Note The registry settings of ForceRediscoveryInterval are group policy enabled. If you disable the policy setting, + /// Force Rediscovery will used by default for the machine at every 12 hour interval. If you do not configure this policy setting, + /// Force Rediscovery will used by default for the machine at every 12 hour interval, unless the local machine setting in the + /// registry is a different value. + /// + /// + /// Note that if the DS_BACKGROUND_ONLY flag is specified, DsGetDcName will never try to rediscover the domain + /// controller name, since the point of that flag is to force DsGetDcName to use the cached domain controller name even if it + /// is expired. + /// + /// ETW Tracing in DsGetDcName + /// To turn on ETW Tracing for DsGetDcName, create the following registry key: + /// HKEY_LOCAL_MACHINE<b>System<b>CurrentControlSet<b>Services<b>DCLocator<b>Tracing + /// The key will have a structure as follows: + /// + /// ProcessName must be the full name including extension of the process that you want to get trace information for. PID is only + /// required when multiple processes with the same name exist. If it is defined, then only the process with that PID will be enabled + /// for tracing. It is not possible to trace only 2 out of 3 (or more) processes with the same name. You can enable one instance or + /// all instances (when multiple instances with the same process name exist and PID is not specified, all instances will be enabled + /// for tracing). + /// + /// + /// For example, this would trace all instances of App1.exe and App2.exe, but only the instance of App3.exe that has a PID of 999: + /// + /// Run the following command to start the tracing session: + /// tracelog.exe -start <sessionname> -guid #cfaa5446-c6c4-4f5c-866f-31c9b55b962d -f <filename> -flag <traceFlags> + /// + /// sessionname is the name given for the trace session. The guid for the DCLocator tracing provider is + /// "cfaa5446-c6c4-4f5c-866f-31c9b55b962d". filename is the name of the log file to which the events are written. traceFlags is one + /// or more of the following flags which signify which areas to trace: + /// + /// + /// + /// Flag + /// Hex Value + /// Description + /// + /// + /// DCLOCATOR_MISC + /// 0x00000002 + /// Miscellaneous debugging + /// + /// + /// DCLOCATOR_MAILSLOT + /// 0x00000010 + /// Mailslot messages + /// + /// + /// DCLOCATOR_SITE + /// 0x00000020 + /// Sites + /// + /// + /// DCLOCATOR_CRITICAL + /// 0x00000100 + /// Important errors + /// + /// + /// DCLOCATOR_SESSION_SETUP + /// 0x00000200 + /// Trusted Domain Maintenance + /// + /// + /// DCLOCATOR_DNS + /// 0x00004000 + /// Name Registration + /// + /// + /// DCLOCATOR_DNS_MORE + /// 0x00020000 + /// Verbose Name Registration + /// + /// + /// DCLOCATOR_MAILBOX_TEXT + /// 0x02000000 + /// Verbose Mailbox Messages + /// + /// + /// DCLOCATOR_SITE_MORE + /// 0x08000000 + /// Verbose sites + /// + /// + /// Run the following command to stop the trace session: + /// tracelog.exe -stop <sessionname> + /// sessionname is the same name as the name you used when starting the session. + /// + /// Note The registry key for the process being traced must be present in the registry at the time the trace session is + /// started. When the session starts, the process will verify whether or not it should be generating trace messages (based on the + /// presence or absence of a registry key for that process name and optional PID). The process checks the registry only at the start + /// of the session. Any changes in the registry occurring after that will not have any effect on tracing. + /// + /// + [PInvokeData("dsgetdc.h", MSDNShortId = "da8b2983-5e45-40b0-b552-c9b3a1d8ae94")] + public static DOMAIN_CONTROLLER_INFO DsGetDcName(DsGetDcNameFlags Flags, [Optional] string ComputerName, [Optional] string DomainName, [Optional] Guid? DomainGuid, [Optional] string SiteName) + { + SafeNetApiBuffer buf; + if (DomainGuid.HasValue) + DsGetDcName(ComputerName, DomainName, DomainGuid.Value, SiteName, Flags, out buf).ThrowIfFailed(); + else + DsGetDcName(ComputerName, DomainName, IntPtr.Zero, SiteName, Flags, out buf).ThrowIfFailed(); + return buf.ToStructure(); + } + + /// The DsGetDcOpen function opens a new domain controller enumeration operation. + /// + /// A string that contains the domain naming system (DNS) name of the domain to enumerate the domain + /// controllers for. This parameter cannot be . + /// + /// + /// + /// Contains a set of flags that modify the behavior of the function. This can be zero or a combination of one or more of the + /// following values. + /// + /// DS_ONLY_DO_SITE_NAME + /// Only site-specific domain controllers are enumerated. + /// DS_NOTIFY_AFTER_SITE_RECORDS + /// + /// The DsGetDcNext function will return the ERROR_FILEMARK_DETECTED value after all of the site-specific domain controllers + /// are retrieved. DsGetDcNext will then enumerate the second group, which contains all domain controllers in the domain, + /// including the site-specific domain controllers contained in the first group. + /// + /// + /// + /// A string that contains the name of site the client is in. This parameter is optional and may be . + /// + /// + /// An optional GUID value that contains the identifier of the domain specified by DnsName. This identifier is used to handle + /// the case of a renamed domain. If this value is specified and the domain specified in DnsName is renamed, this function attempts + /// to enumerate domain controllers in the domain that contains the specified identifier. This parameter is optional and may be . + /// + /// + /// A string that contains the name of the forest that contains the DnsName domain. This value is used in + /// conjunction with DomainGuidto enumerate the domain controllers if the domain has been renamed. This parameter is optional and may + /// be . + /// + /// + /// + /// Contains a set of flags that identify the type of domain controllers to enumerate. This can be zero or a combination of one or + /// more of the following values. + /// + /// DS_FORCE_REDISCOVERY + /// + /// Forces cached domain controller data to be ignored. When this flag is not specified, DsGetDcOpen obtains the domain + /// controller enumeration from cached domain controller data. + /// + /// DS_GC_SERVER_REQUIRED + /// + /// Requires that the enumerated domain controllers be global catalog servers for the forest of domains with this domain as the root. + /// This flag cannot be combined with the DS_PDC_REQUIRED flag. + /// + /// DS_KDC_REQUIRED + /// + /// Requires that the enumerated domain controllers currently be running the Kerberos Key Distribution Center service. This flag + /// cannot be combined with the DS_PDC_REQUIRED or DS_GC_SERVER_REQUIRED flags. + /// + /// DS_ONLY_LDAP_NEEDED + /// + /// Specifies that the enumerated servers are LDAP servers. The servers are not necessarily domain controllers. No other services are + /// implied to be present at each enumerated server. The servers do not necessarily have a writable config container nor a + /// writable schema container. The servers may not necessarily be used to create or modify security principles. This flag may + /// be used with the DS_GC_SERVER_REQUIRED flag to enumerate LDAP servers that also host a global catalog server. In that + /// case, the enumerated global catalog servers are not necessarily domain controllers and other services are implied to be present + /// at each server. If this flag is specified, the DS_PDC_REQUIRED, DS_TIMESERV_REQUIRED, + /// DS_GOOD_TIMESERV_PREFERRED, DS_DIRECTORY_SERVICES_PREFERED, DS_DIRECTORY_SERVICES_REQUIRED, and + /// DS_KDC_REQUIRED flags are ignored. + /// + /// DS_PDC_REQUIRED + /// + /// Requires that the enumerated domain controllers be the primary domain controllers for the domain. This flag cannot be combined + /// with the DS_GC_SERVER_REQUIRED flag. + /// + /// + /// An enumeration of domain controllers paired with the socket address data for the domain controller. + // https://docs.microsoft.com/en-us/windows/desktop/api/dsgetdc/nf-dsgetdc-dsgetdcopena + // DSGETDCAPI DWORD DsGetDcOpenA( IN LPCSTR DnsName, IN ULONG OptionFlags, IN LPCSTR SiteName, IN GUID *DomainGuid, IN LPCSTR DnsForestName, IN ULONG DcFlags, OUT PHANDLE RetGetDcContext ); + [PInvokeData("dsgetdc.h", MSDNShortId = "2811cc30-f367-4f1a-8f0c-ed0a77dad24c")] + public static IEnumerable<(string dnsHostName, SOCKET_ADDRESS[] sockets)> DsGetDcEnum(string DnsName, [Optional] DsGetDcOpenOptions OptionFlags, [Optional] DsGetDcNameFlags DcFlags, [Optional] string SiteName, [Optional] Guid? DomainGuid, [Optional] string DnsForestName) + { + SafeDCEnumHandle h; + if (DomainGuid.HasValue) + DsGetDcOpen(DnsName, OptionFlags, SiteName, DomainGuid.Value, DnsForestName, DcFlags, out h).ThrowIfFailed(); + else + DsGetDcOpen(DnsName, OptionFlags, SiteName, IntPtr.Zero, DnsForestName, DcFlags, out h).ThrowIfFailed(); + using (h) + { + while (true) + { + var err = DsGetDcNext(h, out var addrCnt, out var addr, out var host); + if (err.Succeeded) + yield return (host.ToString(), addr.ToArray((int)addrCnt)); + else if (err == Win32Error.ERROR_NO_MORE_ITEMS) + break; + else if (err == Win32Error.ERROR_FILEMARK_DETECTED) + continue; + else + err.ThrowIfFailed(); + } + } + } + + /// The DsGetDcSiteCoverage function returns the site names of all sites covered by a domain controller. + /// A string value that specifies the name of the remote domain controller. + /// An array of strings containing the site names. + // https://docs.microsoft.com/en-us/windows/desktop/api/dsgetdc/nf-dsgetdc-dsgetdcsitecoveragea + [PInvokeData("dsgetdc.h", MSDNShortId = "e0f757d9-36b6-40f8-a1db-fb5b9862b46a")] + public static IEnumerable DsGetDcSiteCoverage(string ServerName = null) + { + DsGetDcSiteCoverage(ServerName, out var c, out var b).ThrowIfFailed(); + return b.ToStringEnum((int)c); + } + + /// The DsGetForestTrustInformationW function obtains forest trust data for a specified domain. + /// + /// Contains the name of the domain controller that DsGetForestTrustInformation is connected to remotely. The caller must be + /// an authenticated user on this server. If this parameter is , the local server is used. + /// + /// + /// + /// Contains the NETBIOS or DNS name of the trusted domain that the forest trust data is to be retrieved for. This domain must have + /// the TRUST_ATTRIBUTE_FOREST_TRANSITIVE trust attribute. For more information, see TRUSTED_DOMAIN_INFORMATION_EX. + /// + /// If this parameter is , the forest trust data for the domain hosted by ServerName is retrieved. + /// + /// + /// Contains a set of flags that modify the behavior of this function. This can be zero or the following value. + /// DS_GFTI_UPDATE_TDO + /// + /// If this flag is set, DsGetForestTrustInformationW will update the forest trust data of the trusted domain identified by + /// the TrustedDomainNameparameter. In this case, the TrustedDomainName parameter cannot be . The caller must have access + /// to modify the trust data or ERROR_ACCESS_DENIED is returned. + /// + /// This flag is only valid if ServerName specifies the primary domain controller of the domain. + /// + /// + /// The forest trust data that describes the namespaces claimed by the domain specified by TrustedDomainName. The Time member + /// of all returned records will be zero. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/dsgetdc/nf-dsgetdc-dsgetforesttrustinformationw + [PInvokeData("dsgetdc.h", MSDNShortId = "c94fdc5b-920b-4807-9cbf-3172ec1c7386")] + public static AdvApi32.LsaForestTrustInformation DsGetForestTrustInformation([Optional] string ServerName, [Optional] string TrustedDomainName, DsGetForestTrustInformationFlags Flags = 0) + { + DsGetForestTrustInformationW(ServerName, TrustedDomainName, Flags, out var b).ThrowIfFailed(); + return AdvApi32.LsaForestTrustInformation.FromBuffer(b.DangerousGetHandle()); + } + + /// + /// The DsMergeForestTrustInformationW function merges the changes from a new forest trust data structure with an old forest trust data structure. + /// + /// A string that specifies the trusted domain to update. + /// A LsaForestTrustInformation instance that contains the new forest trust data to be merged. The Flags and Time members of the entries are ignored. + /// A LsaForestTrustInformation instance that contains the old forest trust data to be merged. This parameter may be if no records exist. + /// A LsaForestTrustInformation instance with the merged forest trust data. + /// Returns NO_ERROR if successful or a Windows error code otherwise. + // https://docs.microsoft.com/en-us/windows/desktop/api/dsgetdc/nf-dsgetdc-dsmergeforesttrustinformationw + [PInvokeData("dsgetdc.h", MSDNShortId = "f42e16d0-62b2-49c4-b182-d1e744afe58c")] + public static AdvApi32.LsaForestTrustInformation DsMergeForestTrustInformation(string DomainName, [In] AdvApi32.LsaForestTrustInformation NewForestTrustInfo, [In, Optional] AdvApi32.LsaForestTrustInformation OldForestTrustInfo) + { + SafeNetApiBuffer buf; + if (OldForestTrustInfo is null) + DsMergeForestTrustInformationW(DomainName, NewForestTrustInfo.DangerousGetLSA_FOREST_TRUST_INFORMATION(), IntPtr.Zero, out buf).ThrowIfFailed(); + else + DsMergeForestTrustInformationW(DomainName, NewForestTrustInfo.DangerousGetLSA_FOREST_TRUST_INFORMATION(), OldForestTrustInfo.DangerousGetLSA_FOREST_TRUST_INFORMATION(), out buf).ThrowIfFailed(); + return AdvApi32.LsaForestTrustInformation.FromBuffer(buf.DangerousGetHandle()); + } + + /// + /// The DsRoleGetPrimaryDomainInformation function retrieves state data for the computer. This data includes the state of the + /// directory service installation and domain data. + /// + /// + /// Pointer to null-terminated Unicode string that contains the name of the computer on which to call the function. If this parameter + /// is , the local computer is used. + /// + /// + /// Contains one of the DSROLE_PRIMARY_DOMAIN_INFO_LEVEL values that specify the type of data to retrieve. This parameter also + /// determines the format of the data supplied in Buffer. + /// + /// + /// + /// Pointer to the address of a buffer that receives the requested data. The format of this data depends on the value of the + /// InfoLevel parameter. + /// + /// The caller must free this memory when it is no longer required by calling DsRoleFreeMemory. + /// + /// + /// If the function is successful, the return value is ERROR_SUCCESS. + /// If the function fails, the return value can be one of the following values. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/dsrole/nf-dsrole-dsrolegetprimarydomaininformation DWORD + // DsRoleGetPrimaryDomainInformation( IN LPCWSTR lpServer, IN DSROLE_PRIMARY_DOMAIN_INFO_LEVEL InfoLevel, OUT PBYTE *Buffer ); + [PInvokeData("dsrole.h", MSDNShortId = "d54876e3-a622-4b44-a597-db0f710f7758")] + public static T DsRoleGetPrimaryDomainInformation([Optional] string lpServer, DSROLE_PRIMARY_DOMAIN_INFO_LEVEL InfoLevel) where T : struct + { + if (!CorrespondingTypeAttribute.CanGet(InfoLevel, typeof(T))) throw new ArgumentException("Type mismatch", nameof(InfoLevel)); + DsRoleGetPrimaryDomainInformation(lpServer, InfoLevel, out var buf).ThrowIfFailed(); + return buf.ToStructure(); + } + + /// + /// The NetServerDiskEnum function retrieves a list of disk drives on a server. The function returns an array of + /// three-character strings (a drive letter, a colon, and a terminating null character). + /// + /// A pointer to a string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this + /// parameter is , the local computer is used. + /// An array of strings (a drive letter followed by a colon). + /// + /// If the function succeeds, the return value is NERR_Success. + /// If the function fails, the return value can be one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_ACCESS_DENIED + /// The user does not have access to the requested information. + /// + /// + /// ERROR_INVALID_LEVEL + /// The value specified for the level parameter is invalid. + /// + /// + /// ERROR_MORE_DATA + /// More entries are available. Specify a large enough buffer to receive all entries. + /// + /// + /// ERROR_NOT_ENOUGH_MEMORY + /// Insufficient memory is available. + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The request is not supported. This error is returned if a remote server was specified in servername parameter, the remote server + /// only supports remote RPC calls using the legacy Remote Access Protocol mechanism, and this request is not supported. + /// + /// + /// + /// + /// + /// + /// Only members of the Administrators or Server Operators local group can successfully execute the NetServerDiskEnum function + /// on a remote computer. + /// + /// + /// If you are programming for Active Directory, you may be able to call certain Active Directory Service Interface (ADSI) methods to + /// achieve the same results you can achieve by calling the network management server functions. For more information, see the + /// IADsComputer interface reference. + /// + /// + [PInvokeData("lmserver.h", MSDNShortId = "56c981f4-7a1d-4465-bd7b-5996222c4210")] + public static IEnumerable NetServerDiskEnum([Optional] string servername) + { + var h = 0U; + NetServerDiskEnum(servername, 0, out var buf, MAX_PREFERRED_LENGTH, out var cnt, out var _, ref h).ThrowIfFailed(); + var ptr = buf.DangerousGetHandle(); + var chSz = StringHelper.GetCharSize(); + for (var i = 0; i < cnt; i++) + { + yield return StringHelper.GetString(ptr); + ptr = ptr.Offset(3 * chSz); + } + } /// The NetServerEnum function lists all servers of the specified type that are visible in a domain. /// The type of the structure to have filled in for each server. This must be SERVER_INFO_100 or SERVER_INFO_101. @@ -29,9 +698,8 @@ namespace Vanara.PInvoke if (level != 100 && level != 101) throw new ArgumentOutOfRangeException(nameof(level), @"Only SERVER_INFO_100 or SERVER_INFO_101 are supported as valid structures."); var resumeHandle = IntPtr.Zero; - var ret = NetServerEnum(null, level, out var bufptr, MAX_PREFERRED_LENGTH, out var entriesRead, out var totalEntries, netServerEnumFilter, domain, resumeHandle); - ret.ThrowIfFailed(); - return bufptr.DangerousGetHandle().ToIEnum(entriesRead); + NetServerEnum(null, (uint)level, out var bufptr, MAX_PREFERRED_LENGTH, out var entriesRead, out var totalEntries, netServerEnumFilter, domain, resumeHandle).ThrowIfFailed(); + return bufptr.ToIEnum((int)entriesRead); } /// The NetServerGetInfo function retrieves current configuration information for the specified server. @@ -47,26 +715,1639 @@ namespace Vanara.PInvoke /// SERVER_INFO_101 produces 101). /// /// The requested type with returned information about the server. - public static T NetServerGetInfo(string serverName, int level = 0) where T : struct, INetServerInfo + public static T NetServerGetInfo([Optional] string serverName, int level = 0) where T : struct, INetServerInfo { if (level == 0) level = GetLevelFromStructure(); if (level != 100 && level != 101 && level != 102) throw new ArgumentOutOfRangeException(nameof(level), @"Only SERVER_INFO_100, SERVER_INFO_101, or SERVER_INFO_102 are supported as valid structures."); - var ret = NetServerGetInfo(serverName, level, out var ptr); - ret.ThrowIfFailed(); + NetServerGetInfo(serverName, level, out var ptr).ThrowIfFailed(); return ptr.DangerousGetHandle().ToStructure(); } + /// + /// The NetServerTransportEnum function supplies information about transport protocols that are managed by the server. + /// + /// A string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this + /// parameter is , the local computer is used. + /// Specifies the information level of the data. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// 0 + /// + /// Return information about the transport protocol, including name, address, and location on the network. The bufptr parameter + /// points to an array of SERVER_TRANSPORT_INFO_0 structures. + /// + /// + /// + /// 1 + /// + /// Return information about the transport protocol, including name, address, network location, and domain. The bufptr parameter + /// points to an array of SERVER_TRANSPORT_INFO_1 structures. + /// + /// + /// + /// Pointer to the buffer that receives the data. The format of this data depends on the value of the level parameter. This buffer is + /// allocated by the system and must be freed using the NetApiBufferFree function. Note that you must free the buffer even if the + /// function fails with ERROR_MORE_DATA. + /// Specifies the preferred maximum length of returned data, in bytes. If you specify MAX_PREFERRED_LENGTH, the function allocates + /// the amount of memory required for the data. If you specify another value in this parameter, it can restrict the number of bytes + /// that the function returns. If the buffer size is insufficient to hold all entries, the function returns ERROR_MORE_DATA. For more + /// information, see Network Management Function Buffers and Network Management Function Buffer Lengths. + /// Pointer to a value that receives the count of elements actually enumerated. + /// Pointer to a value that receives the total number of entries that could have been enumerated from the current resume position. + /// Note that applications should consider this value only as a hint. + /// The resume handle. + /// + /// If the function succeeds, the return value is NERR_Success. + /// If the function fails, the return value can be one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_INVALID_LEVEL + /// The value specified for the level parameter is invalid. + /// + /// + /// ERROR_MORE_DATA + /// More entries are available. Specify a large enough buffer to receive all entries. + /// + /// + /// ERROR_NOT_ENOUGH_MEMORY + /// Insufficient memory is available. + /// + /// + /// NERR_BufTooSmall + /// The supplied buffer is too small. + /// + /// + /// + /// + /// + /// Only Authenticated Users can successfully call this function. Windows XP/2000: No special group membership is required to + /// successfully execute this function. + /// + /// Examples + /// + /// The following code sample demonstrates how to retrieve information about transport protocols that are managed by the server, + /// using a call to the NetServerTransportEnum function. The sample calls NetServerTransportEnum, specifying + /// information level 0 ( SERVER_TRANSPORT_INFO_0). The sample prints the name of each transport protocol and the total number + /// enumerated. Finally, the code sample frees the memory allocated for the information buffer. + /// + /// + [PInvokeData("lmserver.h", MSDNShortId = "db42ac44-d70d-4b89-882a-6ac83fd611fd")] + public static IEnumerable NetServerTransportEnum([Optional] string servername, int level = -1) where T : struct + { + if (level == -1) level = GetLevelFromStructure(); + var h = 0U; + NetServerTransportEnum(servername, level, out var buf, MAX_PREFERRED_LENGTH, out var cnt, out var _, ref h).ThrowIfFailed(); + return buf.ToIEnum((int)cnt); + } + + /// The NetEnumerateComputerNames function enumerates names for the specified computer. + /// + /// A pointer to a constant string that specifies the name of the computer on which to execute this function. If this parameter is + /// , the local computer is used. + /// + /// + /// + /// The type of the name queried. This member can be one of the following values defined in the NET_COMPUTER_NAME_TYPE + /// enumeration defined in the Lmjoin.h header file. + /// + /// + /// + /// Value + /// Meaning + /// + /// + /// NetPrimaryComputerName + /// The primary computer name. + /// + /// + /// NetAlternateComputerNames + /// Alternate computer names. + /// + /// + /// NetAllComputerNames + /// All computer names. + /// + /// + /// NetComputerNameTypeMax + /// Indicates the end of the range that specifies the possible values for the type of name to be queried. + /// + /// + /// + /// + /// If the function call is successful, this parameter will return the computer names that match the computer type name specified in + /// the NameType parameter. + /// + /// + /// The NetEnumerateComputerNames function is supported on Windows Vista and later. + /// The NetEnumerateComputerNames function is used to request the names a computer currently has configured. + /// + /// The NetEnumerateComputerNames function requires that the caller is a member of the Administrators local group on the + /// target computer. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmjoin/nf-lmjoin-netenumeratecomputernames NET_API_STATUS NET_API_FUNCTION + // NetEnumerateComputerNames( LPCWSTR Server, NET_COMPUTER_NAME_TYPE NameType, ULONG Reserved, PDWORD EntryCount, LPWSTR + // **ComputerNames ); + [PInvokeData("lmjoin.h", MSDNShortId = "c657ae33-404e-4c36-a956-5fbcfa540be7")] + public static IEnumerable NetEnumerateComputerNames([Optional] string Server, NET_COMPUTER_NAME_TYPE NameType = NET_COMPUTER_NAME_TYPE.NetAllComputerNames) + { + NetEnumerateComputerNames(Server, NameType, 0, out var c, out var buf).ThrowIfFailed(); + return buf.ToStringEnum((int)c); + } + + /// + /// The NetGetJoinableOUs function retrieves a list of organizational units (OUs) in which a computer account can be created. + /// + /// A string that specifies the name of the domain for which to retrieve the list of OUs that can be joined. + /// A string that specifies the DNS or NetBIOS name of the computer on which to call the function. If this + /// parameter is , the local computer is used. + /// A string that specifies the account name to use when connecting to the domain controller. The string must + /// specify either a domain NetBIOS name and user account (for example, "REDMOND\user") or the user principal name (UPN) of the user + /// in the form of an Internet-style login name (for example, "someone@example.com"). If this parameter is , the caller's + /// context is used. + /// If the lpAccount parameter specifies an account name, this parameter must point to the password to use when connecting to the + /// domain controller. Otherwise, this parameter must be . + /// The list of joinable OUs. + /// + /// No special group membership is required to successfully execute the NetGetJoinableOUs function. + /// For more information about organizational units, see Managing Users in the Active Directory documentation. + /// + [PInvokeData("lmjoin.h", MSDNShortId = "1faa912b-c56d-431c-95d5-d36790b0d467")] + public static IEnumerable NetGetJoinableOUs(string lpDomain, [Optional] string lpServer, [Optional] string lpAccount, [Optional] string lpPassword) + { + NetGetJoinableOUs(lpServer, lpDomain, lpAccount, lpPassword, out var cnt, out var buf).ThrowIfFailed(); + return buf.ToStringEnum((int)cnt); + } + + /// + /// Lists all connections made to a shared resource on the server or all connections established from a particular computer. If there + /// is more than one user using this connection, then it is possible to get more than one structure for the same connection, but with + /// a different user name. + /// + /// + /// A string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this + /// parameter is , the local computer is used. + /// + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE is defined. + /// + /// A string that specifies a share name or computer name for the connections of interest. If it is a share name, then all + /// the connections made to that share name are listed. If it is a computer name (for example, it starts with two backslash + /// characters), then NetConnectionEnum lists all connections made from that computer to the server specified. + /// + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE is defined. + /// Specifies the information level of the data. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// 0 + /// Return connection identifiers. The bufptr parameter is a pointer to an array of CONNECTION_INFO_0 structures. + /// + /// + /// 1 + /// + /// Return connection identifiers and connection information. The bufptr parameter is a pointer to an array of CONNECTION_INFO_1 structures. + /// + /// + /// + /// + /// Pointer to the address of the buffer that receives the information. The format of this data depends on the value of the level parameter. + /// + /// + /// This buffer is allocated by the system and must be freed using the NetApiBufferFree function. Note that you must free the buffer + /// even if the function fails with ERROR_MORE_DATA. + /// + /// Specifies the preferred maximum length of returned data, in bytes. If you specify MAX_PREFERRED_LENGTH, the function + /// allocates the amount of memory required for the data. If you specify another value in this parameter, it can restrict the number + /// of bytes that the function returns. If the buffer size is insufficient to hold all entries, the function returns + /// ERROR_MORE_DATA. For more information, see Network Management Function Buffers and Network Management Function Buffer Lengths. + /// Pointer to a value that receives the count of elements actually enumerated. + /// Pointer to a value that receives the total number of entries that could have been enumerated from the current resume position. + /// Note that applications should consider this value only as a hint. + /// Pointer to a value that contains a resume handle which is used to continue an existing connection search. The handle should be + /// zero on the first call and left unchanged for subsequent calls. If this parameter is , then no resume handle is stored. + /// + /// If the function succeeds, the return value is NERR_Success. + /// If the function fails, the return value is a system error code. For a list of error codes, see System Error Codes. + /// + /// + /// + /// Administrator, Server or Print Operator, or Power User group membership is required to successfully execute the + /// NetConnectionEnum function. + /// + /// Examples + /// + /// The following code sample demonstrates how to list the connections made to a shared resource with a call to the + /// NetConnectionEnum function. The sample calls NetConnectionEnum, specifying information level 1 (CONNECTION_INFO_1). + /// If there are entries to return, it prints the values of the coni1_username and coni1_netname members. If there are + /// no entries to return, the sample prints an appropriate message. Finally, the code sample frees the memory allocated for the + /// information buffer. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmshare/nf-lmshare-netconnectionenum NET_API_STATUS NET_API_FUNCTION + // NetConnectionEnum( LMSTR servername, LMSTR qualifier, DWORD level, LPBYTE *bufptr, DWORD prefmaxlen, LPDWORD entriesread, LPDWORD + // totalentries, LPDWORD resume_handle ); + [PInvokeData("lmshare.h", MSDNShortId = "935ac6e9-78e0-42ae-a454-0a14b03ddc21")] + public static IEnumerable NetConnectionEnum([Optional] string servername, string qualifier, uint level = uint.MaxValue) where T : struct + { + if (level == uint.MaxValue) level = (uint)GetLevelFromStructure(); + var h = 0U; + NetConnectionEnum(servername, qualifier, level, out var buf, MAX_PREFERRED_LENGTH, out var cnt, out var _, ref h).ThrowIfFailed(); + return buf.ToIEnum((int)cnt); + } + + /// Returns information about some or all open files on a server, depending on the parameters specified. + /// The expected return type of the enumerated element. + /// + /// A string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this + /// parameter is , the local computer is used. + /// + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE is defined. + /// + /// A string that specifies a qualifier for the returned information. If this parameter is , all open resources + /// are enumerated. If this parameter is not , the function enumerates only resources that have the value of the basepath + /// parameter as a prefix. (A prefix is the portion of a path that comes before a backslash.) + /// + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE is defined. + /// + /// A string that specifies the name of the user or the name of the connection. If the string begins with two backslashes + /// ("\"), then it indicates the name of the connection, for example, "\127.0.0.1" or "\ClientName". The part of the connection name + /// after the backslashes is the same as the client name in the session information structure returned by the NetSessionEnum + /// function. If the string does not begin with two backslashes, then it indicates the name of the user. If this parameter is not + /// , its value serves as a qualifier for the enumeration. The files returned are limited to those that have user names or + /// connection names that match the qualifier. If this parameter is , no user-name qualifier is used. + /// + /// + /// Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This parameter is a pointer to a string that + /// specifies the name of the user. If this parameter is not , its value serves as a qualifier for the enumeration. The + /// files returned are limited to those that have user names matching the qualifier. If this parameter is , no user-name + /// qualifier is used. + /// + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE is defined. + /// Specifies the information level of the data. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// 2 + /// Return the file identification number. The return value is an array of FILE_INFO_2 structures. + /// + /// + /// 3 + /// Return information about the file. The return value is an array of FILE_INFO_3 structures. + /// + /// + /// An enumeration of files. The format of this data depends on the value of the level parameter. + /// + /// Only members of the Administrators or Server Operators local group can successfully execute the NetFileEnum function. + /// You can call the NetFileGetInfo function to retrieve information about a particular opening of a server resource. + /// + /// If you are programming for Active Directory, you may be able to call certain Active Directory Service Interface (ADSI) methods to + /// achieve the same functionality you can achieve by calling NetFileEnum. For more information, see IADsResource and IADsFileServiceOperations. + /// + /// + [PInvokeData("lmshare.h", MSDNShortId = "1375b337-efb0-4be1-94f7-473456a825b5")] + public static IEnumerable NetFileEnum([Optional] string servername, [Optional] string basepath, [Optional] string username, uint level = uint.MaxValue) where T : struct + { + if (level == uint.MaxValue) level = (uint)GetLevelFromStructure(); + var h = IntPtr.Zero; + NetFileEnum(servername, basepath, username, level, out var buf, MAX_PREFERRED_LENGTH, out var cnt, out var _, ref h).ThrowIfFailed(); + return buf.ToIEnum((int)cnt); + } + + /// Retrieves information about a particular opening of a server resource. + /// The expected return type associated with the . + /// A string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this + /// parameter is , the local computer is used. + /// Specifies the file identifier of the open resource for which to return information. The value of this parameter must have been + /// returned in a previous enumeration call. For more information, see the following Remarks section. + /// Specifies the information level of the data. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// 2 + /// Return the file identification number. The bufptr parameter is a pointer to a FILE_INFO_2 structure. + /// + /// + /// 3 + /// + /// Return the file identification number and other information about the file. The bufptr parameter is a pointer to a FILE_INFO_3 structure. + /// + /// + /// + /// The format of this structure depends on the value of the parameter. + /// + /// + /// Only members of the Administrators or Server Operators local group can successfully execute the NetFileGetInfo function. + /// + /// You can call the NetFileEnum function to retrieve information about multiple files open on a server. + /// + /// If you are programming for Active Directory, you may be able to call certain Active Directory Service Interface (ADSI) methods to + /// achieve the same functionality you can achieve by calling NetFileGetInfo. For more information, see IADsResource and IADsFileServiceOperations. + /// + /// + [PInvokeData("lmshare.h", MSDNShortId = "d50c05e7-7ddd-4a7d-96f6-51878e52373c")] + public static T NetFileGetInfo([Optional] string servername, uint fileid, uint level = uint.MaxValue) where T : struct + { + if (level == uint.MaxValue) level = (uint)GetLevelFromStructure(); + NetFileGetInfo(servername, fileid, level, out var buf).ThrowIfFailed(); + return buf.ToStructure(); + } + + /// Provides information about sessions established on a server. + /// The expected element return type associated with the . + /// + /// A string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this parameter is + /// , the local computer is used. + /// + /// + /// A string that specifies the name of the computer session for which information is to be returned. If this parameter is + /// , NetSessionEnum returns information for all computer sessions on the server. + /// + /// + /// A string that specifies the name of the user for which information is to be returned. If this parameter is + /// , NetSessionEnum returns information for all users. + /// + /// + /// + /// Specifies the information level of the data. This parameter can be one of the following values. If + /// omitted or , this value will be extracted from the last digits of the name of . + /// + /// + /// + /// Value + /// Meaning + /// + /// + /// 0 + /// Return the name of the computer that established the session. The return value is an array of SESSION_INFO_0 structures. + /// + /// + /// 1 + /// + /// Return the name of the computer, name of the user, and open files, pipes, and devices on the computer. The bufptr parameter + /// points to an array of SESSION_INFO_1 structures. + /// + /// + /// + /// 2 + /// + /// In addition to the information indicated for level 1, return the type of client and how the user established the session. The + /// return value is an array of SESSION_INFO_2 structures. + /// + /// + /// + /// 10 + /// + /// Return the name of the computer, name of the user, and active and idle times for the session. The return value is an array of + /// SESSION_INFO_10 structures. + /// + /// + /// + /// 502 + /// + /// Return the name of the computer; name of the user; open files, pipes, and devices on the computer; and the name of the transport + /// the client is using. The return value is an array of SESSION_INFO_502 structures. + /// + /// + /// + /// + /// This resulting list of sessions. The format of this data depends on the value of the parameter. + /// + /// + /// Only members of the Administrators or Server Operators local group can successfully execute the NetSessionEnum function at + /// level 1 or level 2. No special group membership is required for level 0 or level 10 calls. + /// + /// + /// If you are programming for Active Directory, you may be able to call certain Active Directory Service Interface (ADSI) methods to + /// achieve the same functionality you can achieve by calling the network management session functions. For more information, see + /// IADsSession and IADsFileServiceOperations. + /// + /// Examples + /// + /// The following code sample demonstrates how to retrieve information about current sessions using a call to the + /// NetSessionEnum function. The sample calls NetSessionEnum, specifying information level 10 ( SESSION_INFO_10). The + /// sample loops through the entries and prints the retrieved information. Finally, the code prints the total number of sessions + /// enumerated and frees the memory allocated for the information buffer. + /// + /// + [PInvokeData("lmshare.h", MSDNShortId = "5923a8cc-bf7a-4ffa-b089-fd7f26ee42d2")] + public static IEnumerable NetSessionEnum([Optional] string servername, [Optional] string UncClientName, [Optional] string username, uint level = uint.MaxValue) where T : struct + { + if (level == uint.MaxValue) level = (uint)GetLevelFromStructure(); + var h = 0U; + NetSessionEnum(servername, UncClientName, username, level, out var buf, MAX_PREFERRED_LENGTH, out var cnt, out var _, ref h).ThrowIfFailed(); + return buf.ToIEnum((int)cnt); + } + + /// Retrieves information about a session established between a particular server and workstation. + /// The expected return type associated with the . + /// A string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this + /// parameter is , the local computer is used. + /// A string that specifies the name of the computer session for which information is to be returned. This parameter is + /// required and cannot be . For more information, see NetSessionEnum. + /// A string that specifies the name of the user whose session information is to be returned. This parameter is required + /// and cannot be . + /// Specifies the information level of the data. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// 0 + /// Return the name of the computer that established the session. The return value is a SESSION_INFO_0 structure. + /// + /// + /// 1 + /// + /// Return the name of the computer, name of the user, and open files, pipes, and devices on the computer. The return value is a SESSION_INFO_1 structure. + /// + /// + /// + /// 2 + /// + /// In addition to the information indicated for level 1, return the type of client and how the user established the session. The return value is a SESSION_INFO_2 structure. + /// + /// + /// + /// 10 + /// + /// Return the name of the computer; name of the user; and active and idle times for the session. The return value is a + /// SESSION_INFO_10 structure. + /// + /// + /// + /// The data. The format of this data depends on the value of the level parameter. + /// + /// + /// Only members of the Administrators or Server Operators local group can successfully execute the NetSessionGetInfo function + /// at level 1 or level 2. No special group membership is required for level 0 or level 10 calls. + /// + /// + /// If you are programming for Active Directory, you may be able to call certain Active Directory Service Interface (ADSI) methods to + /// achieve the same functionality you can achieve by calling the network management session functions. For more information, see + /// IADsSession and IADsFileServiceOperations. + /// + /// + /// If you call this function at information level 1 or 2 on a member server or workstation, all authenticated users can view the information. + /// + /// Examples + /// + /// The following code sample demonstrates how to retrieve information about a session using a call to the NetSessionGetInfo + /// function. The sample calls NetSessionGetInfo, specifying information level 10 ( SESSION_INFO_10). If the call succeeds, + /// the code prints information about the session. Finally, the sample frees the memory allocated for the information buffer. + /// + /// + [PInvokeData("lmshare.h", MSDNShortId = "d44fb8d8-2b64-4268-8603-7784e2c5f2d5")] + public static T NetSessionGetInfo([Optional] string servername, string UncClientName, string username, uint level = uint.MaxValue) where T : struct + { + if (level == uint.MaxValue) level = (uint)GetLevelFromStructure(); + NetSessionGetInfo(servername, UncClientName, username, level, out var buf).ThrowIfFailed(); + return buf.ToStructure(); + } + + /// Shares a server resource. + /// The data structure used to describe the share. + /// A string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this + /// parameter is , the local computer is used. + /// Value that specifies the data. The format of this data depends on the value of the level parameter. + /// Specifies the information level of the data. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// 2 + /// + /// Specifies information about the shared resource, including the name of the resource, type and permissions, and number of + /// connections. The buf parameter points to a SHARE_INFO_2 structure. + /// + /// + /// + /// 502 + /// + /// Specifies information about the shared resource, including the name of the resource, type and permissions, number of connections, + /// and other pertinent information. The buf parameter points to a SHARE_INFO_502 structure. + /// + /// + /// + /// 503 + /// + /// Specifies information about the shared resource, including the name of the resource, type and permissions, number of connections, + /// and other pertinent information. The buf parameter points to a SHARE_INFO_503 structure. + /// + /// + /// + /// + /// + /// This function applies only to Server Message Block (SMB) shares. For other types of shares, such as Distributed File System (DFS) + /// or WebDAV shares, use Windows Networking (WNet) functions, which support all types of shares. + /// + /// + /// Only members of the Administrators, System Operators, or Power Users local group can add file shares with a call to the + /// NetShareAdd function. The Print Operator can add printer shares. + /// + /// + /// If you are programming for Active Directory, you may be able to call certain Active Directory Service Interface (ADSI) methods to + /// achieve the same functionality you can achieve by calling the network management share functions. For more information, see IADsFileShare. + /// + /// + /// If 503 is specified for the level parameter, the remote server specified in the shi503_servername member of the + /// SHARE_INFO_503 structure must have been bound to a transport protocol using the NetServerTransportAddEx function. In the call to + /// NetServerTransportAddEx, either 2 or 3 must have been specified for the level parameter, and the SVTI2_SCOPED_NAME + /// flag must have been specified in the SERVER_TRANSPORT_INFO_2 structure for the transport protocol. + /// + /// + [PInvokeData("lmshare.h", MSDNShortId = "8b51c155-24e8-4d39-b818-eb2d1bb0ee8b")] + public static void NetShareAdd([Optional] string servername, in T buf, uint level = uint.MaxValue) where T : struct + { + if (level == uint.MaxValue) level = (uint)GetLevelFromStructure(); + var mem = SafeHGlobalHandle.CreateFromStructure(buf); + var err = NetShareAdd(servername, level, (IntPtr)mem, out var perr); + if (err.Succeeded) return; + if (err != Win32Error.ERROR_INVALID_PARAMETER) err.ThrowIfFailed(); + throw err.GetException($"Invalid parameter. Index: {perr}"); + } + + /// + /// Retrieves information about each shared resource on a server. + /// + /// You can also use the WNetEnumResource function to retrieve resource information. However, WNetEnumResource does not + /// enumerate hidden shares or users connected to a share. + /// + /// + /// The expected element return type associated with the . + /// + /// A string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this parameter is + /// , the local computer is used. + /// + /// + /// Specifies the information level of the data. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// 0 + /// Return share names. The return value is an array of SHARE_INFO_0 structures. + /// + /// + /// 1 + /// + /// Return information about shared resources, including the name and type of the resource, and a comment associated with the + /// resource. The return value is an array of SHARE_INFO_1 structures. + /// + /// + /// + /// 2 + /// + /// Return information about shared resources, including name of the resource, type and permissions, password, and number of + /// connections. The return value is an array of SHARE_INFO_2 structures. + /// + /// + /// + /// 502 + /// + /// Return information about shared resources, including name of the resource, type and permissions, number of connections, and other + /// pertinent information. The return value is an array of SHARE_INFO_502 structures. Shares from different scopes are not returned. + /// For more information about scoping, see the Remarks section of the documentation for the NetServerTransportAddEx function. + /// + /// + /// + /// 503 + /// + /// Return information about shared resources, including the name of the resource, type and permissions, number of connections, and + /// other pertinent information. The return value is an array of SHARE_INFO_503 structures. Shares from all scopes are returned. If + /// the shi503_servername member of this structure is "*", there is no configured server name and the NetShareEnum function + /// enumerates shares for all the unscoped names. Windows Server 2003 and Windows XP: This information level is not supported. + /// + /// + /// + /// + /// The data. The format of this data depends on the value of the parameter. + /// + /// + /// This function applies only to Server Message Block (SMB) shares. For other types of shares, such as Distributed File System (DFS) + /// or WebDAV shares, use Windows Networking (WNet) functions, which support all types of shares. + /// + /// + /// For interactive users (users who are logged on locally to the machine), no special group membership is required to execute the + /// NetShareEnum function. For non-interactive users, Administrator, Power User, Print Operator, or Server Operator group + /// membership is required to successfully execute the NetShareEnum function at levels 2, 502, and 503. No special group + /// membership is required for level 0 or level 1 calls. + /// + /// + /// Windows Server 2003 and Windows XP: For all users, Administrator, Power User, Print Operator, or Server Operator group + /// membership is required to successfully execute the NetShareEnum function at levels 2 and 502. + /// + /// + /// To retrieve a value that indicates whether a share is the root volume in a DFS tree structure, you must call the NetShareGetInfo + /// function and specify information level 1005. + /// + /// + /// If you are programming for Active Directory, you may be able to call certain Active Directory Service Interface (ADSI) methods to + /// achieve the same functionality you can achieve by calling the network management share functions. For more information, see IADsFileShare. + /// + /// + [PInvokeData("lmshare.h", MSDNShortId = "9114c54d-3905-4d40-9162-b3ea605f6fcb")] + public static IEnumerable NetShareEnum([Optional] string servername, uint level = uint.MaxValue) where T : struct + { + if (level == uint.MaxValue) level = (uint)GetLevelFromStructure(); + var h = 0U; + NetShareEnum(servername, level, out var buf, MAX_PREFERRED_LENGTH, out var cnt, out var _, ref h).ThrowIfFailed(); + return buf.ToIEnum((int)cnt); + } + + /// Retrieves information about a particular shared resource on a server. + /// + /// + /// A string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this parameter is + /// , the local computer is used. + /// + /// A string that specifies the name of the share for which to return information. + /// + /// Specifies the information level of the data. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// 0 + /// Return the share name. The return value is a SHARE_INFO_0 structure. + /// + /// + /// 1 + /// + /// Return information about the shared resource, including the name and type of the resource, and a comment associated with the + /// resource. The return value is a SHARE_INFO_1 structure. + /// + /// + /// + /// 2 + /// + /// Return information about the shared resource, including name of the resource, type and permissions, password, and number of + /// connections. The return value is a SHARE_INFO_2 structure. + /// + /// + /// + /// 501 + /// + /// Return the name and type of the resource, and a comment associated with the resource. The return value is a SHARE_INFO_501 structure. + /// + /// + /// + /// 502 + /// + /// Return information about the shared resource, including name of the resource, type and permissions, number of connections, and + /// other pertinent information. The return value is a SHARE_INFO_502 structure. + /// + /// + /// + /// 503 + /// + /// Specifies information about the shared resource, including the name of the resource, type and permissions, number of connections, + /// and other pertinent information. The return value is a SHARE_INFO_503 structure. If the shi503_servername member of this + /// structure is "*", there is no configured server name. Windows Server 2003 and Windows XP: This information level is not supported. + /// + /// + /// + /// 1005 + /// + /// Return a value that indicates whether the share is the root volume in a Dfs tree structure. The return value is a SHARE_INFO_1005 structure. + /// + /// + /// + /// + /// The data. The format of this data depends on the value of the parameter. + /// + /// + /// This function applies only to Server Message Block (SMB) shares. For other types of shares, such as Distributed File System (DFS) + /// or WebDAV shares, use Windows Networking (WNet) functions, which support all types of shares. + /// + /// + /// For interactive users (users who are logged on locally to the machine), no special group membership is required to execute the + /// NetShareGetInfo function. For non-interactive users, Administrator, Power User, Print Operator, or Server Operator group + /// membership is required to successfully execute the NetShareEnum function at levels 2, 502, and 503. No special group membership + /// is required for level 0 or level 1 calls. + /// + /// + /// Windows Server 2003 and Windows XP: For all users, Administrator, Power User, Print Operator, or Server Operator group + /// membership is required to successfully execute the NetShareGetInfo function at levels 2 and 502. + /// + /// + /// If you are programming for Active Directory, you may be able to call certain Active Directory Service Interface (ADSI) methods to + /// achieve the same functionality you can achieve by calling the network management share functions. For more information, see IADsFileShare. + /// + /// + /// If 503 is specified for the level parameter, the remote server specified in the shi503_servername member of the + /// SHARE_INFO_503 structure must have been bound to a transport protocol using the NetServerTransportAddEx function. In the call to + /// NetServerTransportAddEx, either 2 or 3 must have been specified for the level parameter, and the SVTI2_SCOPED_NAME + /// flag must have been specified in the SERVER_TRANSPORT_INFO_2 structure for the transport protocol. + /// + /// + [PInvokeData("lmshare.h", MSDNShortId = "672ea208-4048-4d2f-9606-ee3e2133765b")] + public static T NetShareGetInfo([Optional] string servername, string netname, uint level = uint.MaxValue) where T : struct + { + if (level == uint.MaxValue) level = (uint)GetLevelFromStructure(); + NetShareGetInfo(servername, netname, level, out var buf).ThrowIfFailed(); + return buf.ToStructure(); + } + + /// Sets the parameters of a shared resource. + /// The type of the data being set. + /// + /// Pointer to a string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this + /// parameter is NULL, the local computer is used. + /// + /// Pointer to a string that specifies the name of the share to set information on. + /// The buf. + /// + /// Specifies the information level of the data. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// 1 + /// + /// Specifies information about the shared resource, including the name and type of the resource, and a comment associated with the + /// resource. The buf parameter points to a SHARE_INFO_1 structure. + /// + /// + /// + /// 2 + /// + /// Specifies information about the shared resource, including the name of the resource, type and permissions, password, and number + /// of connections. The buf parameter points to a SHARE_INFO_2 structure. + /// + /// + /// + /// 502 + /// + /// Specifies information about the shared resource, including the name and type of the resource, required permissions, number of + /// connections, and other pertinent information. The buf parameter points to a SHARE_INFO_502 structure. + /// + /// + /// + /// 503 + /// + /// Specifies the name of the shared resource. The buf parameter points to a SHARE_INFO_503 structure. All members of this structure + /// except shi503_servername are ignored by the NetShareSetInfo function. Windows Server 2003 and Windows XP: This information level + /// is not supported. + /// + /// + /// + /// 1004 + /// Specifies a comment associated with the shared resource. The buf parameter points to a SHARE_INFO_1004 structure. + /// + /// + /// 1005 + /// Specifies a set of flags describing the shared resource. The buf parameter points to a SHARE_INFO_1005 structure. + /// + /// + /// 1006 + /// + /// Specifies the maximum number of concurrent connections that the shared resource can accommodate. The buf parameter points to a + /// SHARE_INFO_1006 structure. + /// + /// + /// + /// 1501 + /// Specifies the SECURITY_DESCRIPTOR associated with the specified share. The buf parameter points to a SHARE_INFO_1501 structure. + /// + /// + /// + /// + /// + /// This function applies only to Server Message Block (SMB) shares. For other types of shares, such as Distributed File System (DFS) + /// or WebDAV shares, use Windows Networking (WNet) functions, which support all types of shares. + /// + /// + /// Only members of the Administrators or Power Users local group, or those with Print or Server Operator group membership, can + /// successfully execute the NetShareSetInfo function. The Print Operator can set information only about Printer shares. + /// + /// + /// If the NetShareSetInfo function returns ERROR_INVALID_PARAMETER, you can use the parm_err parameter to indicate the + /// first member of the share information structure that is not valid. (A share information structure begins with SHARE_INFO_ + /// and its format is specified by the level parameter.) The following table lists the values that can be returned in the parm_err + /// parameter and the corresponding structure member that is in error. (The prefix shi* indicates that the member can begin + /// with multiple prefixes, for example, shi2 or shi502_.) + /// + /// + /// + /// Value + /// Member + /// + /// + /// SHARE_NETNAME_PARMNUM + /// shi*_netname + /// + /// + /// SHARE_TYPE_PARMNUM + /// shi*_type + /// + /// + /// SHARE_REMARK_PARMNUM + /// shi*_remark + /// + /// + /// SHARE_PERMISSIONS_PARMNUM + /// shi*_permissions + /// + /// + /// SHARE_MAX_USES_PARMNUM + /// shi*_max_uses + /// + /// + /// SHARE_CURRENT_USES_PARMNUM + /// shi*_current_uses + /// + /// + /// SHARE_PATH_PARMNUM + /// shi*_path + /// + /// + /// SHARE_PASSWD_PARMNUM + /// shi*_passwd + /// + /// + /// SHARE_FILE_SD_PARMNUM + /// shi*_security_descriptor + /// + /// + /// + /// If you are programming for Active Directory, you may be able to call certain Active Directory Service Interface (ADSI) methods to + /// achieve the same functionality you can achieve by calling the network management share functions. For more information, see IADsFileShare. + /// + /// + /// If 503 is specified for the level parameter, the remote server specified in the shi503_servername member of the + /// SHARE_INFO_503 structure must have been bound to a transport protocol using the NetServerTransportAddEx function. In the call to + /// NetServerTransportAddEx, either 2 or 3 must have been specified for the level parameter, and the SVTI2_SCOPED_NAME + /// flag must have been specified in the SERVER_TRANSPORT_INFO_2 structure for the transport protocol. + /// + /// + [PInvokeData("lmshare.h", MSDNShortId = "216b0b78-87da-4734-ad07-5ad1c9edf494")] + public static void NetShareSetInfo([Optional] string servername, string netname, in T buf, uint level = uint.MaxValue) where T : struct + { + var mem = SafeHGlobalHandle.CreateFromStructure(buf); + var err = NetShareSetInfo(servername, netname, level, (IntPtr)mem, out var perr); + if (err.Succeeded) return; + if (err != Win32Error.ERROR_INVALID_PARAMETER) err.ThrowIfFailed(); + throw err.GetException($"Invalid parameter. Index: {perr}"); + } + + /// + /// The NetUseAdd function establishes a connection between the local computer and a remote server. You can specify a local + /// drive letter or a printer device to connect. If you do not specify a local drive letter or printer device, the function + /// authenticates the client with the server for future connections. + /// + /// + /// + /// The UNC name of the computer on which to execute this function. If this parameter is NULL, then the local computer is + /// used. If the UncServerName parameter specified is a remote computer, then the remote computer must support remote RPC calls using + /// the legacy Remote Access Protocol mechanism. + /// + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// The data. The format of this data depends on the value of the Level parameter. + /// A value that specifies the information level of the data. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// 1 + /// + /// Specifies information about the connection between a local device and a shared resource. Information includes the connection + /// status and type. The Buf parameter is a pointer to a USE_INFO_1 structure. + /// + /// + /// + /// 2 + /// + /// Specifies information about the connection between a local device and a shared resource. Information includes the connection + /// status and type, and a user name and domain name. The Buf parameter is a pointer to a USE_INFO_2 structure. + /// + /// + /// + /// + /// You can also use the WNetAddConnection2 and WNetAddConnection3 functions to redirect a local device to a network resource. + /// + /// No special group membership is required to call the NetUseAdd function. This function cannot be executed on a remote + /// server except in cases of downlevel compatibility. + /// + /// + /// This function applies only to the Server Message Block (LAN Manager Workstation) client. The NetUseAdd function does not + /// support Distributed File System (DFS) shares. To add a share using a different network provider (WebDAV or a DFS share, for + /// example), use the WNetAddConnection2 or WNetAddConnection3 function. + /// + /// + /// If the NetUseAdd function returns ERROR_INVALID_PARAMETER, you can use the ParmError parameter to indicate the first + /// member of the information structure that is invalid. (The information structure begins with USE_INFO_ and its format is specified + /// by the Level parameter.) The following table lists the values that can be returned in the ParmError parameter and the + /// corresponding structure member that is in error. (The prefix ui*_ indicates that the member can begin with multiple prefixes, for + /// example, ui1_ or ui2_.) + /// + /// + /// + /// Constant + /// Value + /// Member + /// + /// + /// USE_LOCAL_PARMNUM + /// 1 + /// ui*_local + /// + /// + /// USE_REMOTE_PARMNUM + /// 2 + /// ui*_remote + /// + /// + /// USE_PASSWORD_PARMNUM + /// 3 + /// ui*_password + /// + /// + /// USE_ASGTYPE_PARMNUM + /// 4 + /// ui*_asg_type + /// + /// + /// USE_USERNAME_PARMNUM + /// 5 + /// ui*_username + /// + /// + /// USE_DOMAINNAME_PARMNUM + /// 6 + /// ui*_domainname + /// + /// + /// + [PInvokeData("lmuse.h", MSDNShortId = "22550c17-003a-4f59-80f0-58fa3e286844")] + public static void NetUseAdd([Optional] string servername, in T buf, uint LevelFlags = uint.MaxValue) where T : struct + { + if (LevelFlags == uint.MaxValue) LevelFlags = (uint)GetLevelFromStructure(); + var mem = SafeHGlobalHandle.CreateFromStructure(buf); + var err = NetUseAdd(servername, LevelFlags, (IntPtr)mem, out var perr); + if (err.Succeeded) return; + if (err != Win32Error.ERROR_INVALID_PARAMETER) err.ThrowIfFailed(); + throw err.GetException($"Invalid parameter. Index: {perr}"); + } + + /// + /// The NetUseEnum function lists all current connections between the local computer and resources on remote servers. + /// You can also use the WNetOpenEnum and the WNetEnumResource functions to enumerate network resources or connections. + /// + /// The expected element return type associated with the . + /// + /// The UNC name of the computer on which to execute this function. If this is parameter is NULL, then the local computer is + /// used. If the UncServerName parameter specified is a remote computer, then the remote computer must support remote RPC calls using + /// the legacy Remote Access Protocol mechanism. + /// + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// The information level of the data requested. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// 0 + /// + /// Specifies a local device name and the share name of a remote resource. The BufPtr parameter points to an array of USE_INFO_0 structures. + /// + /// + /// + /// 1 + /// + /// Specifies information about the connection between a local device and a shared resource, including connection status and type. + /// The BufPtr parameter points to an array of USE_INFO_1 structures. + /// + /// + /// + /// 2 + /// + /// Specifies information about the connection between a local device and a shared resource. Information includes the connection + /// status, connection type, user name, and domain name. The BufPtr parameter points to an array of USE_INFO_2 structures. + /// + /// + /// + /// The information structures. The format of this data depends on the value of the Level parameter. + /// + /// + /// No special group membership is required to call the NetUseEnum function. This function cannot be executed on a remote + /// server except in cases of downlevel compatibility using the legacy Remote Access Protocol. + /// + /// To retrieve information about one network connection, you can call the NetUseGetInfo function. + /// + /// This function applies only to the Server Message Block (LAN Manager Workstation) client. The NetUseEnum function does not + /// support Distributed File System (DFS) shares. To enumerate shares using a different network provider (WebDAV or a DFS share, for + /// example), use the WNetOpenEnum, WNetEnumResource, and WNetCloseEnum functions. + /// + /// + [PInvokeData("lmuse.h", MSDNShortId = "fb527f85-baea-48e8-b837-967870834ec5")] + public static IEnumerable NetUseEnum([Optional] string UncServerName, uint LevelFlags = uint.MaxValue) where T : struct + { + if (LevelFlags == uint.MaxValue) LevelFlags = (uint)GetLevelFromStructure(); + var h = 0U; + NetUseEnum(UncServerName, LevelFlags, out var buf, MAX_PREFERRED_LENGTH, out var cnt, out var _, ref h).ThrowIfFailed(); + return buf.ToIEnum((int)cnt); + } + + /// + /// The NetUseGetInfo function retrieves information about a connection to a shared resource. + /// You can also use the WNetGetConnection function to retrieve the name of a network resource associated with a local device. + /// + /// + /// + /// The UNC name of computer on which to execute this function. If this is parameter is NULL, then the local computer is used. + /// If the UncServerName parameter specified is a remote computer, then the remote computer must support remote RPC calls using the + /// legacy Remote Access Protocol mechanism. + /// + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + /// + /// A pointer to a string that specifies the name of the connection for which to return information. + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + /// + /// The information level of the data requested. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// 0 + /// + /// Specifies a local device name and the share name of a remote resource. The BufPtr parameter is a pointer to a USE_INFO_0 structure. + /// + /// + /// + /// 1 + /// + /// Specifies information about the connection between a local device and a shared resource, including connection status and type. + /// The BufPtr parameter is a pointer to a USE_INFO_1 structure. + /// + /// + /// + /// 2 + /// + /// Specifies information about the connection between a local device and a shared resource. Information includes the connection + /// status, connection type, user name, and domain name. The BufPtr parameter is a pointer to a USE_INFO_2 structure. + /// + /// + /// + /// + /// + /// A pointer to the buffer that receives the data. The format of this data depends on the value of the Level parameter. This buffer + /// is allocated by the system and must be freed using the NetApiBufferFree function. For more information, see Network Management + /// Function Buffers and Network Management Function Buffer Lengths. + /// + /// + /// If the function succeeds, the return value is NERR_Success. + /// If the function fails, the return value is a system error code. For a list of error codes, see System Error Codes. + /// + /// + /// + /// No special group membership is required to call the NetUseGetInfo function. This function cannot be executed on a remote + /// server except in cases of downlevel compatibility. + /// + /// + /// To list all current connections between the local computer and resources on remote servers, you can call the NetUseEnum function. + /// + /// + /// This function applies only to the Server Message Block (LAN Manager Workstation) client. The NetUseGetInfo function does + /// not support Distributed File System (DFS) shares. To retrieve information for a share using a different network provider (WebDAV + /// or a DFS share, for example), use the WNetGetConnection function. + /// + /// + [PInvokeData("lmuse.h", MSDNShortId = "257875db-5ed9-4569-8dbb-5dcc7a6af95c")] + public static T NetUseGetInfo([Optional] string UncServerName, string UseName, uint LevelFlags = uint.MaxValue) where T : struct + { + if (LevelFlags == uint.MaxValue) LevelFlags = (uint)GetLevelFromStructure(); + NetUseGetInfo(UncServerName, UseName, LevelFlags, out var buf).ThrowIfFailed(); + return buf.ToStructure(); + } + + /// The NetWkstaGetInfo function returns information about the configuration of a workstation. + /// The type of structure to get. + /// Pointer to a string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this + /// parameter is NULL, the local computer is used. + /// Specifies the information level of the data. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// 100 + /// + /// Return information about the workstation environment, including platform-specific information, the name of the domain and the + /// local computer, and information concerning the operating system. The bufptr parameter points to a WKSTA_INFO_100 structure. + /// + /// + /// + /// 101 + /// + /// In addition to level 100 information, return the path to the LANMAN directory. The bufptr parameter points to a WKSTA_INFO_101 structure. + /// + /// + /// + /// 102 + /// + /// In addition to level 101 information, return the number of users who are logged on to the local computer. The bufptr parameter + /// points to a WKSTA_INFO_102 structure. + /// + /// + /// + /// The data. The format of this data depends on the value of the level parameter. + /// + /// + /// Windows Server 2003 and Windows XP: If you call this function on a domain controller that is running Active Directory, + /// access is allowed or denied based on the ACL for the securable object. To enable anonymous access, the user Anonymous must be a + /// member of the "Pre-Windows 2000 compatible access" group. This is because anonymous tokens do not include the Everyone group SID + /// by default. If you call this function on a member server or workstation, all authenticated users can view the information. + /// Anonymous access is also permitted if the EveryoneIncludesAnonymous policy setting allows anonymous access. Anonymous access is + /// always permitted for level 100. If you call this function at level 101, authenticated users can view the information. Members of + /// the Administrators, and the Server, System and Print Operator local groups can view information at levels 102 and 502. For more + /// information about restricting anonymous access, see Security Requirements for the Network Management Functions. For more + /// information on ACLs, ACEs, and access tokens, see Access Control Model. + /// + /// + /// Windows 2000: If you call this function on a domain controller that is running Active Directory, access is allowed or + /// denied based on the access control list (ACL) for the securable object. The default ACL permits all authenticated users and + /// members of the " Pre-Windows 2000 compatible access" group to view the information. By default, the "Pre-Windows 2000 compatible + /// access" group includes Everyone as a member. This enables anonymous access to the information if the system allows anonymous + /// access. If you call this function on a member server or workstation, all authenticated users can view the information. Anonymous + /// access is also permitted if the RestrictAnonymous policy setting allows anonymous access. + /// + /// + /// To compile an application that uses this function, define the _WIN32_WINNT macro as 0x0400 or later. For more information,see + /// Using the Windows Headers. + /// + /// + [PInvokeData("lmwksta.h", MSDNShortId = "08777069-1afd-4482-8090-c65ef0bec1ea")] + public static T NetWkstaGetInfo(string servername, uint level = uint.MaxValue) where T : struct + { + if (level == uint.MaxValue) level = (uint)GetLevelFromStructure(); + NetWkstaGetInfo(servername, level, out var buf).ThrowIfFailed(); + return buf.ToStructure(); + } + + /// + /// The NetWkstaSetInfo function configures a workstation with information that remains in effect after the system has been reinitialized. + /// + /// The type of the data to set. + /// A pointer to a string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this + /// parameter is NULL, the local computer is used. + /// The data. The format of this data depends on the value of the level parameter. + /// The information level of the data. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// 100 + /// + /// Windows NT: Specifies information about a workstation environment, including platform-specific information, the names of the + /// domain and the local computer, and information concerning the operating system. The buffer parameter points to a WKSTA_INFO_100 + /// structure. The wk100_computername and wk100_langroup fields of this structure cannot be set by calling this function. To set + /// these values, call SetComputerName/SetComputerNameEx or NetJoinDomain, respectively. + /// + /// + /// + /// 101 + /// + /// Windows NT: In addition to level 100 information, specifies the path to the LANMAN directory. The buffer parameter points to a + /// WKSTA_INFO_101 structure. The wk101_computername and wk101_langroup fields of this structure cannot be set by calling this + /// function. To set these values, call SetComputerName/SetComputerNameEx or NetJoinDomain, respectively. + /// + /// + /// + /// 102 + /// + /// Windows NT: In addition to level 101 information, specifies the number of users who are logged on to the local computer. The + /// buffer parameter points to a WKSTA_INFO_102 structure. The wk102_computername and wk102_langroup fields of this structure cannot + /// be set by calling this function. To set these values, call SetComputerName/SetComputerNameEx or NetJoinDomain, respectively. + /// + /// + /// + /// 502 + /// + /// Windows NT: The buffer parameter points to a WKSTA_INFO_502 structure that contains information about the workstation environment. + /// + /// + /// + /// Do not set levels 1010-1013, 1018, 1023, 1027, 1028, 1032, 1033, 1035, or 1041-1062. + /// + /// Only members of the Administrators group can successfully execute the NetWkstaSetInfo function on a remote server. + /// + /// The NetWkstaSetInfo function calls the workstation service on the local system or a remote system. Only a limited number + /// of members of the WKSTA_INFO_502 structure can actually be changed using the NetWkstaSetInfo function. No errors are + /// returned if a member is set that is ignored by the workstation service. The workstation service is primarily configured using + /// settings in the registry. + /// + /// + /// The NetWkstaUserSetInfo function can be used instead of the NetWkstaSetInfo function to set configuration information on + /// the local system. The NetWkstaUserSetInfo function calls the Local Security Authority (LSA). + /// + /// + /// If the NetWkstaSetInfo function returns ERROR_INVALID_PARAMETER, you can use the parm_err parameter to indicate the first + /// member of the workstation information structure that is invalid. (A workstation information structure begins with WKSTA_INFO_ and + /// its format is specified by the level parameter.) The following table lists the values that can be returned in the parm_err + /// parameter and the corresponding structure member that is in error. (The prefix wki*_ indicates that the member can begin with + /// multiple prefixes, for example, wki100_ or wki402_.) + /// + /// + /// + /// Value + /// Member + /// + /// + /// WKSTA_PLATFORM_ID_PARMNUM + /// wki*_platform_id + /// + /// + /// WKSTA_COMPUTERNAME_PARMNUM + /// wki*_computername + /// + /// + /// WKSTA_LANGROUP_PARMNUM + /// wki*_langroup + /// + /// + /// WKSTA_VER_MAJOR_PARMNUM + /// wki*_ver_major + /// + /// + /// WKSTA_VER_MINOR_PARMNUM + /// wki*_ver_minor + /// + /// + /// WKSTA_LOGGED_ON_USERS_PARMNUM + /// wki*_logged_on_users + /// + /// + /// WKSTA_LANROOT_PARMNUM + /// wki*_lanroot + /// + /// + /// WKSTA_LOGON_DOMAIN_PARMNUM + /// wki*_logon_domain + /// + /// + /// WKSTA_LOGON_SERVER_PARMNUM + /// wki*_logon_server + /// + /// + /// WKSTA_CHARWAIT_PARMNUM + /// wki*_char_wait + /// + /// + /// WKSTA_CHARTIME_PARMNUM + /// wki*_collection_time + /// + /// + /// WKSTA_CHARCOUNT_PARMNUM + /// wki*_maximum_collection_count + /// + /// + /// WKSTA_KEEPCONN_PARMNUM + /// wki*_keep_conn + /// + /// + /// WKSTA_KEEPSEARCH_PARMNUM + /// wki*_keep_search + /// + /// + /// WKSTA_MAXCMDS_PARMNUM + /// wki*_max_cmds + /// + /// + /// WKSTA_NUMWORKBUF_PARMNUM + /// wki*_num_work_buf + /// + /// + /// WKSTA_MAXWRKCACHE_PARMNUM + /// wki*_max_wrk_cache + /// + /// + /// WKSTA_SESSTIMEOUT_PARMNUM + /// wki*_sess_timeout + /// + /// + /// WKSTA_SIZERROR_PARMNUM + /// wki*_siz_error + /// + /// + /// WKSTA_NUMALERTS_PARMNUM + /// wki*_num_alerts + /// + /// + /// WKSTA_NUMSERVICES_PARMNUM + /// wki*_num_services + /// + /// + /// WKSTA_ERRLOGSZ_PARMNUM + /// wki*_errlog_sz + /// + /// + /// WKSTA_PRINTBUFTIME_PARMNUM + /// wki*_print_buf_time + /// + /// + /// WKSTA_NUMCHARBUF_PARMNU + /// wki*_num_char_buf + /// + /// + /// WKSTA_SIZCHARBUF_PARMNUM + /// wki*_siz_char_buf + /// + /// + /// WKSTA_WRKHEURISTICS_PARMNUM + /// wki*_wrk_heuristics + /// + /// + /// WKSTA_MAILSLOTS_PARMNUM + /// wki*_mailslots + /// + /// + /// WKSTA_MAXTHREADS_PARMNUM + /// wki*_max_threads + /// + /// + /// WKSTA_SIZWORKBUF_PARMNUM + /// wki*_siz_work_buf + /// + /// + /// WKSTA_NUMDGRAMBUF_PARMNUM + /// wki*_num_dgram_buf + /// + /// + /// + /// The workstation service parameter settings are stored in the registry, not in the LanMan.ini file used prveiously by LAN Manager. + /// The NetWkstaSetInfo function does not change the values in the LanMan.ini file. When the workstation service is stopped + /// and restarted, workstation parameters are reset to the default values specified in the registry (unless they are overwritten by + /// command-line parameters). Values set by previous calls to NetWkstaSetInfo can be overwritten when workstation parameters + /// are reset. + /// + /// Examples + /// + /// The following code sample demonstrates how to set the session time-out value associated with a workstation using a call to the + /// NetServerSetInfo function. (The session time-out is the number of seconds the server waits before disconnecting an + /// inactive session.) The code specifies information level 502 (WKSTA_INFO_502). + /// + /// + [PInvokeData("lmwksta.h", MSDNShortId = "d746b6c9-5ef1-4174-a84f-44e4e50200cd")] + public static void NetWkstaSetInfo(string servername, in T buffer, uint level = uint.MaxValue) where T : struct + { + var mem = SafeHGlobalHandle.CreateFromStructure(buffer); + var err = NetWkstaSetInfo(servername, level, (IntPtr)mem, out var perr); + if (err.Succeeded) return; + if (err != Win32Error.ERROR_INVALID_PARAMETER) err.ThrowIfFailed(); + throw err.GetException($"Invalid parameter. Index: {perr}"); + } + + /// + /// The NetWkstaUserEnum function lists information about all users currently logged on to the workstation. This list includes + /// interactive, service and batch logons. + /// + /// + /// Pointer to a string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this + /// parameter is NULL, the local computer is used. + /// Specifies the information level of the data. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// 0 + /// + /// Return the names of users currently logged on to the workstation. The bufptr parameter points to an array of WKSTA_USER_INFO_0 structures. + /// + /// + /// + /// 1 + /// + /// Return the names of the current users and the domains accessed by the workstation. The bufptr parameter points to an array of + /// WKSTA_USER_INFO_1 structures. + /// + /// + /// + /// The data enumeration. The format of this data depends on the value of the level parameter. + /// + /// + /// Note that since the NetWkstaUserEnum function lists entries for service and batch logons, as well as for interactive + /// logons, the function can return entries for users who have logged off a workstation. This can occur, for example, when a user + /// calls a service that impersonates the user. In this instance, NetWkstaUserEnum returns an entry for the user until the + /// service stops impersonating the user. + /// + /// + /// Windows Server 2003 and Windows XP: If you call this function on a domain controller that is running Active Directory, + /// access is allowed or denied based on the ACL for the securable object. To enable anonymous access, the user Anonymous must be a + /// member of the "Pre-Windows 2000 compatible access" group. This is because anonymous tokens do not include the Everyone group SID + /// by default. If you call this function on a member server or workstation, all authenticated users can view the information. + /// Anonymous access is also permitted if the RestrictAnonymous policy setting permits anonymous access. If the RestrictAnonymous + /// policy setting does not permit anonymous access, only an administrator can successfully execute the function. Members of the + /// Administrators, and the Server, System and Print Operator local groups can also view information. For more information about + /// restricting anonymous access, see Security Requirements for the Network Management Functions. For more information on ACLs, ACEs, + /// and access tokens, see Access Control Model. + /// + /// + /// Windows 2000: If you call this function on a domain controller that is running Active Directory, access is allowed or + /// denied based on the access control list (ACL) for the securable object. The default ACL permits all authenticated users and + /// members of the " Pre-Windows 2000 compatible access" group to view the information. By default, the "Pre-Windows 2000 compatible + /// access" group includes Everyone as a member. This enables anonymous access to the information if the system allows anonymous + /// access. If you call this function on a member server or workstation, all authenticated users can view the information. Anonymous + /// access is also permitted if the RestrictAnonymous policy setting allows anonymous access. + /// + /// + /// To compile an application that uses this function, define the _WIN32_WINNT macro as 0x0400 or later. For more information,see + /// Using the Windows Headers. + /// + /// + [PInvokeData("lmwksta.h", MSDNShortId = "42eaeb70-3ce8-4eae-b20b-4729db90a7ef")] + public static IEnumerable NetWkstaUserEnum([Optional] string servername, uint level = uint.MaxValue) where T : struct + { + if (level == uint.MaxValue) level = (uint)GetLevelFromStructure(); + var h = 0U; + NetWkstaUserEnum(servername, level, out var buf, MAX_PREFERRED_LENGTH, out var cnt, out var _, ref h).ThrowIfFailed(); + return buf.ToIEnum((int)cnt); + } + + /// + /// The NetWkstaUserGetInfo function returns information about the currently logged-on user. This function must be called in + /// the context of the logged-on user. + /// + /// + /// Specifies the information level of the data. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// 0 + /// + /// Return the name of the user currently logged on to the workstation. The bufptr parameter points to a WKSTA_USER_INFO_0 structure. + /// + /// + /// + /// 1 + /// + /// Return information about the workstation, including the name of the current user and the domains accessed by the workstation. The + /// bufptr parameter points to a WKSTA_USER_INFO_1 structure. + /// + /// + /// + /// 1101 + /// Return domains browsed by the workstation. The bufptr parameter points to a WKSTA_USER_INFO_1101 structure. + /// + /// + /// The data. The format of this data depends on the value of the bufptr parameter. + /// + /// The NetWkstaUserGetInfo function only works locally. + /// Examples + /// + /// The following code sample demonstrates how to retrieve information about the currently logged-on user using a call to the + /// NetWkstaUserGetInfo function. The sample calls NetWkstaUserGetInfo, specifying information level 1 ( + /// WKSTA_USER_INFO_1). If the call succeeds, the sample prints information about the logged-on user. Finally, the sample frees the + /// memory allocated for the information buffer. + /// + /// + [PInvokeData("lmwksta.h", MSDNShortId = "25ec7a49-fd26-4105-823b-a257a57f724e")] + public static T NetWkstaUserGetInfo(uint level = uint.MaxValue) where T : struct + { + if (level == uint.MaxValue) level = (uint)GetLevelFromStructure(); + NetWkstaUserGetInfo(null, level, out var buf).ThrowIfFailed(); + return buf.ToStructure(); + } + + /// + /// The NetWkstaUserSetInfo function sets the user-specific information about the configuration elements for a workstation. + /// + /// This parameter must be set to zero. + /// + /// Specifies the information level of the data. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// 1 + /// + /// Specifies information about the workstation, including the name of the current user and the domains accessed by the workstation. + /// The buf parameter points to a WKSTA_USER_INFO_1 structure. + /// + /// + /// + /// 1101 + /// Specifies domains browsed by the workstation. The buf parameter points to a WKSTA_USER_INFO_1101 structure. + /// + /// + /// + /// + /// Pointer to the buffer that specifies the data. The format of this data depends on the value of the level parameter. For more + /// information, see Network Management Function Buffers. + /// + /// + /// Pointer to a value that receives the index of the first parameter that causes the ERROR_INVALID_PARAMETER error. If this + /// parameter is NULL, the index is not returned on error. + /// + /// + /// If the function succeeds, the return value is NERR_Success. + /// If the function fails, the return value can be one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_INVALID_LEVEL + /// The level parameter is invalid. + /// + /// + /// ERROR_INVALID_PARAMETER + /// One of the function parameters is invalid. + /// + /// + /// + /// + /// The NetWkstaUserSetInfo function only works locally. Administrator group membership is required. + /// + /// Domain names in the wkui1101_oth_domains member of the WKSTA_USER_INFO_1101 structure are separated by spaces. An empty + /// list is valid. A NULL pointer means to leave the member unmodified. The wkui1101_oth_domains member cannot be set + /// with MS-DOS. When setting this element, NetWkstaUserSetInfo rejects the request if the name list was invalid or if a name + /// could not be added to one or more of the network adapters managed by the system. + /// + /// + /// If the NetWkstaUserSetInfo function returns ERROR_INVALID_PARAMETER, you can use the parm_err parameter to indicate the + /// member of the workstation user information structure that is invalid. (A workstation user information structure begins with + /// WKSTA_USER_INFO_ and its format is specified by the level parameter.) The following table lists the value that can be returned in + /// the parm_err parameter and the corresponding structure member that is in error. (The prefix wkui*_ indicates that the member can + /// begin with multiple prefixes, for example, wkui0_ or wkui1_.) + /// + /// + /// + /// Value + /// Member + /// + /// + /// WKSTA_OTH_DOMAINS_PARMNUM + /// wkui*_oth_domains + /// + /// + /// Examples + /// + /// The following code sample demonstrates how to set user-specific information for a workstation using a call to the + /// NetWkstaUserSetInfo function, specifying information level 1101 ( WKSTA_USER_INFO_1101). + /// + /// + [PInvokeData("lmwksta.h", MSDNShortId = "d48667a3-5ae9-4a7d-9af6-14f08835940d")] + public static void NetWkstaUserSetInfo(in T buf, uint level = uint.MaxValue) where T : struct + { + var mem = SafeHGlobalHandle.CreateFromStructure(buf); + var err = NetWkstaSetInfo(null, level, (IntPtr)mem, out var perr); + if (err.Succeeded) return; + if (err != Win32Error.ERROR_INVALID_PARAMETER) err.ThrowIfFailed(); + throw err.GetException($"Invalid parameter. Index: {perr}"); + } + private static int GetLevelFromStructure() { - int.TryParse(System.Text.RegularExpressions.Regex.Replace(typeof(T).Name, @"[^\d]", ""), out var i); + var m = System.Text.RegularExpressions.Regex.Match(typeof(T).Name, @"(\d+)$"); + var i = 0; + if (m.Success) + int.TryParse(m.Value, out i); return i; } - - private static IEnumerable GetNetworkComputerInfo(NetServerEnumFilter netServerEnumFilter = NetServerEnumFilter.SV_TYPE_WORKSTATION | NetServerEnumFilter.SV_TYPE_SERVER, string domain = null) => - NetServerEnum(netServerEnumFilter, domain, 101); - - private static IEnumerable GetNetworkComputerNames(NetServerEnumFilter netServerEnumFilter = NetServerEnumFilter.SV_TYPE_WORKSTATION | NetServerEnumFilter.SV_TYPE_SERVER, string domain = null) => - NetServerEnum(netServerEnumFilter, domain, 100).Select(si => si.sv100_name); } } \ No newline at end of file diff --git a/PInvoke/NetApi32/LmAccess.cs b/PInvoke/NetApi32/LmAccess.cs new file mode 100644 index 00000000..d71be843 --- /dev/null +++ b/PInvoke/NetApi32/LmAccess.cs @@ -0,0 +1,124 @@ +using System; +using System.Runtime.InteropServices; +using System.Text; +using Vanara.Extensions; + +namespace Vanara.PInvoke +{ + public static partial class NetApi32 + { + /* + GROUP_INFO_0 structure + GROUP_INFO_1 structure + GROUP_INFO_1002 structure + GROUP_INFO_1005 structure + GROUP_INFO_2 structure + GROUP_INFO_3 structure + GROUP_USERS_INFO_0 structure + GROUP_USERS_INFO_1 structure + LOCALGROUP_INFO_0 structure + LOCALGROUP_INFO_1 structure + LOCALGROUP_INFO_1002 structure + LOCALGROUP_MEMBERS_INFO_0 structure + LOCALGROUP_MEMBERS_INFO_1 structure + LOCALGROUP_MEMBERS_INFO_2 structure + LOCALGROUP_MEMBERS_INFO_3 structure + LOCALGROUP_USERS_INFO_0 structure + NET_DISPLAY_GROUP structure + NET_DISPLAY_MACHINE structure + NET_DISPLAY_USER structure + NET_VALIDATE_AUTHENTICATION_INPUT_ARG structure + NET_VALIDATE_OUTPUT_ARG structure + NET_VALIDATE_PASSWORD_CHANGE_INPUT_ARG structure + NET_VALIDATE_PASSWORD_HASH structure + NET_VALIDATE_PASSWORD_RESET_INPUT_ARG structure + NET_VALIDATE_PERSISTED_FIELDS structure + USER_INFO_0 structure + USER_INFO_1 structure + USER_INFO_10 structure + USER_INFO_1003 structure + USER_INFO_1005 structure + USER_INFO_1006 structure + USER_INFO_1007 structure + USER_INFO_1008 structure + USER_INFO_1009 structure + USER_INFO_1010 structure + USER_INFO_1011 structure + USER_INFO_1012 structure + USER_INFO_1013 structure + USER_INFO_1014 structure + USER_INFO_1017 structure + USER_INFO_1018 structure + USER_INFO_1020 structure + USER_INFO_1023 structure + USER_INFO_1024 structure + USER_INFO_1025 structure + USER_INFO_1051 structure + USER_INFO_1052 structure + USER_INFO_1053 structure + USER_INFO_11 structure + USER_INFO_2 structure + USER_INFO_20 structure + USER_INFO_21 structure + USER_INFO_22 structure + USER_INFO_23 structure + USER_INFO_24 structure + USER_INFO_3 structure + USER_INFO_4 structure + USER_MODALS_INFO_0 structure + USER_MODALS_INFO_1 structure + USER_MODALS_INFO_1001 structure + USER_MODALS_INFO_1002 structure + USER_MODALS_INFO_1003 structure + USER_MODALS_INFO_1004 structure + USER_MODALS_INFO_1005 structure + USER_MODALS_INFO_1006 structure + USER_MODALS_INFO_1007 structure + USER_MODALS_INFO_2 structure + USER_MODALS_INFO_3 structure + NetAccessAdd function + NetAccessDel function + NetAccessEnum function + NetAccessGetInfo function + NetAccessGetUserPerms function + NetAccessSetInfo function + NetGetAnyDCName function + NetGetDCName function + NetGetDisplayInformationIndex function + NetGroupAdd function + NetGroupAddUser function + NetGroupDel function + NetGroupDelUser function + NetGroupEnum function + NetGroupGetInfo function + NetGroupGetUsers function + NetGroupSetInfo function + NetGroupSetUsers function + NetLocalGroupAdd function + NetLocalGroupAddMember function + NetLocalGroupAddMembers function + NetLocalGroupDel function + NetLocalGroupDelMember function + NetLocalGroupDelMembers function + NetLocalGroupEnum function + NetLocalGroupGetInfo function + NetLocalGroupGetMembers function + NetLocalGroupSetInfo function + NetLocalGroupSetMembers function + NetQueryDisplayInformation function + NetUserAdd function + NetUserChangePassword function + NetUserDel function + NetUserEnum function + NetUserGetGroups function + NetUserGetInfo function + NetUserGetLocalGroups function + NetUserModalsGet function + NetUserModalsSet function + NetUserSetGroups function + NetUserSetInfo function + NetValidatePasswordPolicy function + NetValidatePasswordPolicyFree function + */ + } +} \ No newline at end of file diff --git a/PInvoke/NetApi32/LmAlert.cs b/PInvoke/NetApi32/LmAlert.cs new file mode 100644 index 00000000..c843895b --- /dev/null +++ b/PInvoke/NetApi32/LmAlert.cs @@ -0,0 +1,628 @@ +using System; +using System.Runtime.InteropServices; +using Vanara.Extensions; + +namespace Vanara.PInvoke +{ + public static partial class NetApi32 + { + /// An administrator's intervention is required. + public const string ALERT_ADMIN_EVENT = "ADMIN"; + + /// An entry was added to the error log. + public const string ALERT_ERRORLOG_EVENT = "ERRORLOG"; + + /// A user or application received a broadcast message. + public const string ALERT_MESSAGE_EVENT = "MESSAGE"; + + /// A print job completed or a print error occurred. + public const string ALERT_PRINT_EVENT = "PRINTING"; + + /// An application or resource was used. + public const string ALERT_USER_EVENT = "USER"; + + /// Name of mailslot to send alert notifications + public const string ALERTER_MAILSLOT = "\\\\.\\MAILSLOT\\Alerter"; + + /// A bitmask describing the status of the print job. + [PInvokeData("lmalert.h", MSDNShortId = "f2fd87bc-abde-43c0-b29d-d43cc5f038b8")] + [Flags] + public enum PRJOB + { + /// The print job is in the queue waiting to be scheduled. + PRJOB_QS_QUEUED = 0, + + /// The print job is in the queue, but it has been paused. (When a job is paused, it cannot be scheduled.) + PRJOB_QS_PAUSED = 1, + + /// The print job is in the process of being spooled. + PRJOB_QS_SPOOLING = 2, + + /// The job is currently printing. + PRJOB_QS_PRINTING = 3, + + /// The job has completed printing. + PRJOB_COMPLETE = 0x4, + + /// The destination printer requires an operator's intervention. + PRJOB_INTERV = 0x8, + + /// There is an error at the destination printer. + PRJOB_ERROR = 0x10, + + /// The destination printer is offline. + PRJOB_DESTOFFLINE = 0x20, + + /// The destination printer is paused. + PRJOB_DESTPAUSED = 0x40, + + /// A printing alert should be raised. + PRJOB_NOTIFY = 0x80, + + /// The destination printer is out of paper. + PRJOB_DESTNOPAPER = 0x100, + + /// The printing job is being deleted. + PRJOB_DELETED = 0x8000, + } + + /// + /// The ALERT_OTHER_INFO macro returns a pointer to the alert-specific data in an alert message. The data follows a STD_ALERT + /// structure, and can be an ADMIN_OTHER_INFO, a PRINT_OTHER_INFO, or a USER_OTHER_INFO structure. + /// + /// Pointer to a STD_ALERT structure that was specified in a call to the NetAlertRaise function. + /// + /// The ALERT_OTHER_INFO macro is defined as follows: + /// + /// See NetAlertRaise for a code sample that uses the ALERT_OTHER_INFO macro to retrieve a pointer to the + /// ADMIN_OTHER_INFO structure. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmalert/nf-lmalert-alert_other_info void ALERT_OTHER_INFO( x ); + [PInvokeData("lmalert.h", MSDNShortId = "e7bcc306-4b44-4230-96aa-a4717bb1fb11")] + public static IntPtr ALERT_OTHER_INFO(IntPtr x) => x.Offset(Marshal.SizeOf(typeof(STD_ALERT))); + + /// + /// The ALERT_VAR_DATA macro returns a pointer to the variable-length portion of an alert message. Variable-length data can + /// follow an ADMIN_OTHER_INFO, a PRINT_OTHER_INFO, or a USER_OTHER_INFO structure. + /// + /// + /// Pointer to an ADMIN_OTHER_INFO, a PRINT_OTHER_INFO, or a USER_OTHER_INFO structure that was specified in a + /// call to the NetAlertRaise function or the NetAlertRaiseEx function. + /// + /// + /// The ALERT_VAR_DATA macro is defined as follows: + /// + /// See NetAlertRaise and NetAlertRaiseEx for code samples that use the ALERT_VAR_DATA macro to retrieve a pointer to the + /// variable-length data in an alert message. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmalert/nf-lmalert-alert_var_data void ALERT_VAR_DATA( p ); + [PInvokeData("lmalert.h", MSDNShortId = "ff71fb3d-8c01-47ac-93f2-108b1f49e2da")] + public static IntPtr ALERT_VAR_DATA(IntPtr p) where T : struct => p.Offset(Marshal.SizeOf(typeof(T))); + + /// + /// [This function is not supported as of Windows Vista because the alerter service is not supported.] + /// The NetAlertRaise function notifies all registered clients when a particular event occurs. + /// + /// To simplify sending an alert message, you can call the extended function NetAlertRaiseEx instead. NetAlertRaiseEx does not + /// require that you specify a STD_ALERT structure. + /// + /// + /// + /// + /// A pointer to a constant string that specifies the alert class (type of alert) to raise. This parameter can be one of the + /// following predefined values, or a user-defined alert class for network applications. The event name for an alert can be any text string. + /// + /// + /// + /// Name + /// Meaning + /// + /// + /// ALERT_ADMIN_EVENT + /// An administrator's intervention is required. + /// + /// + /// ALERT_ERRORLOG_EVENT + /// An entry was added to the error log. + /// + /// + /// ALERT_MESSAGE_EVENT + /// A user or application received a broadcast message. + /// + /// + /// ALERT_PRINT_EVENT + /// A print job completed or a print error occurred. + /// + /// + /// ALERT_USER_EVENT + /// An application or resource was used. + /// + /// + /// + /// + /// + /// A pointer to the data to send to the clients listening for the interrupting message. The data should begin with a fixed-length + /// STD_ALERT structure followed by additional message data in one ADMIN_OTHER_INFO, ERRLOG_OTHER_INFO, PRINT_OTHER_INFO, or + /// USER_OTHER_INFO structure. Finally, the buffer should include any required variable-length information. For more information, see + /// the code sample in the following Remarks section. + /// + /// + /// The calling application must allocate and free the memory for all structures and variable data. For more information, see Network + /// Management Function Buffers. + /// + /// + /// The size, in bytes, of the message buffer. + /// + /// If the function succeeds, the return value is NERR_Success. + /// + /// If the function fails, the return value is a system error code and a can be one of the following error codes. For a list of all + /// possible error codes, see System Error Codes. + /// + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// A parameter is incorrect. This error is returned if the AlertEventName parameter is NULL or an empty string, the Buffer parameter + /// is NULL, or the BufferSize parameter is less than the size of the STD_ALERT structure plus the fixed size for the additional + /// message data structure. + /// + /// + /// + /// ERROR_NOT_SUPPORTED + /// The request is not supported. This error is returned on Windows Vista and later since the Alerter service is not supported. + /// + /// + /// + /// + /// No special group membership is required to successfully execute the NetAlertRaise function. + /// + /// The alerter service must be running on the client computer when you call the NetAlertRaise function, or the function fails + /// with ERROR_FILE_NOT_FOUND. + /// + /// Examples + /// + /// The following code sample demonstrates how to raise an administrative alert by calling the NetAlertRaise function and + /// specifying STD_ALERT and ADMIN_OTHER_INFO structures. First, the sample calculates the size of the message buffer. Then it + /// allocates the buffer with a call to the GlobalAlloc function. The code assigns values to the members of the STD_ALERT and + /// the ADMIN_OTHER_INFO portions of the buffer. The sample retrieves a pointer to the ADMIN_OTHER_INFO structure by + /// calling the ALERT_OTHER_INFO macro. It also retrieves a pointer to the variable data portion of the buffer by calling the + /// ALERT_VAR_DATA macro. Finally, the code sample frees the memory allocated for the buffer with a call to the GlobalFree function. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmalert/nf-lmalert-netalertraise NET_API_STATUS NET_API_FUNCTION + // NetAlertRaise( LPCWSTR AlertType, LPVOID Buffer, DWORD BufferSize ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("lmalert.h", MSDNShortId = "11367a72-c21d-4044-98cf-a7a30cc43a8b")] + public static extern Win32Error NetAlertRaise([MarshalAs(UnmanagedType.LPWStr)] string AlertType, IntPtr Buffer, uint BufferSize); + + /// + /// [This function is not supported as of Windows Vista because the alerter service is not supported.] + /// + /// The NetAlertRaiseEx function notifies all registered clients when a particular event occurs. You can call this extended + /// function to simplify the sending of an alert message because NetAlertRaiseEx does not require that you specify a STD_ALERT structure. + /// + /// + /// + /// + /// A pointer to a constant string that specifies the alert class (type of alert) to raise. This parameter can be one of the + /// following predefined values, or a user-defined alert class for network applications. (The event name for an alert can be any text string.) + /// + /// + /// + /// Name + /// Meaning + /// + /// + /// ALERT_ADMIN_EVENT + /// An administrator's intervention is required. + /// + /// + /// ALERT_ERRORLOG_EVENT + /// An entry was added to the error log. + /// + /// + /// ALERT_MESSAGE_EVENT + /// A user or application received a broadcast message. + /// + /// + /// ALERT_PRINT_EVENT + /// A print job completed or a print error occurred. + /// + /// + /// ALERT_USER_EVENT + /// An application or resource was used. + /// + /// + /// + /// + /// + /// A pointer to the data to send to the clients listening for the interrupting message. The data should consist of one + /// ADMIN_OTHER_INFO, ERRLOG_OTHER_INFO, PRINT_OTHER_INFO, or USER_OTHER_INFO structure followed by any required variable-length + /// information. For more information, see the code sample in the following Remarks section. + /// + /// + /// The calling application must allocate and free the memory for all structures and variable data. For more information, see Network + /// Management Function Buffers. + /// + /// + /// The number of bytes of variable information in the buffer pointed to by the VariableInfo parameter. + /// A pointer to a constant string that specifies the name of the service raising the interrupting message. + /// + /// If the function succeeds, the return value is NERR_Success. + /// + /// If the function fails, the return value is a system error code and a can be one of the following error codes. For a list of all + /// possible error codes, see System Error Codes. + /// + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// A parameter is incorrect. This error is returned if the AlertEventName parameter is NULL or an empty string, the ServiceName + /// parameter is NULL or an empty string, the VariableInfo parameter is NULL, or the VariableInfoSize parameter is greater than 512 + /// minus the size of the STD_ALERT structure. + /// + /// + /// + /// ERROR_NOT_SUPPORTED + /// The request is not supported. This error is returned on Windows Vista and later since the Alerter service is not supported. + /// + /// + /// + /// + /// No special group membership is required to successfully execute the NetAlertRaiseEx function. + /// + /// The alerter service must be running on the client computer when you call the NetAlertRaiseEx function, or the function + /// fails with ERROR_FILE_NOT_FOUND. + /// + /// Examples + /// + /// The following code sample demonstrates how to raise the following types of interrupting messages (alerts) by calling the + /// NetAlertRaiseEx function: + /// + /// + /// + /// An administrative alert by specifying an ADMIN_OTHER_INFO structure + /// + /// + /// A print alert by specifying a PRINT_OTHER_INFO structure + /// + /// + /// A user alert by specifying a USER_OTHER_INFO structure + /// + /// + /// + /// In each instance the code assigns values to the members of the relevant alert information structure. Following this, the sample + /// retrieves a pointer to the portion of the message buffer that follows the structure by calling the ALERT_VAR_DATA macro. The code + /// also fills in the variable-length strings in this portion of the buffer. Finally, the sample calls NetAlertRaiseEx to send + /// the alert. + /// + /// + /// Note that the calling application must allocate and free the memory for all structures and variable-length data in an alert + /// message buffer. + /// + /// + /// To pass a user-defined structure and valid strings in a user alert, you must create an event message file and link it with your + /// application. You must also register the application in the EventMessageFile subkey in the EventLog section of the + /// registry. If you do not register the application, the user alert will contain the information you pass in the variable-length + /// strings that follow the USER_OTHER_INFO structure. For more information about EventMessageFile, see Event Logging. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmalert/nf-lmalert-netalertraiseex NET_API_STATUS NET_API_FUNCTION + // NetAlertRaiseEx( LPCWSTR AlertType, LPVOID VariableInfo, DWORD VariableInfoSize, LPCWSTR ServiceName ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("lmalert.h", MSDNShortId = "9762f0d6-0022-4e05-b2d8-6223d7bbb2c8")] + public static extern Win32Error NetAlertRaiseEx([MarshalAs(UnmanagedType.LPWStr)] string AlertType, IntPtr VariableInfo, uint VariableInfoSize, [MarshalAs(UnmanagedType.LPWStr)] string ServiceName); + + /// + /// The ADMIN_OTHER_INFO structure contains error message information. The NetAlertRaise and NetAlertRaiseEx functions use the + /// ADMIN_OTHER_INFO structure to specify information when raising an administrator's interrupting message. + /// + /// + /// + /// Variable-length data follows the ADMIN_OTHER_INFO structure in the alert message buffer if you specify one or more strings + /// in the alrtad_numstrings member. The calling application must allocate and free the memory for all structures and + /// variable-length data in an alert message buffer. + /// + /// See NetAlertRaise and NetAlertRaiseEx for code samples that demonstrate how to raise an administrative alert. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmalert/ns-lmalert-_admin_other_info typedef struct _ADMIN_OTHER_INFO { DWORD + // alrtad_errcode; DWORD alrtad_numstrings; } ADMIN_OTHER_INFO, *PADMIN_OTHER_INFO, *LPADMIN_OTHER_INFO; + [PInvokeData("lmalert.h", MSDNShortId = "43119dcf-7d04-4e3b-b1dc-20e814fbdc2f")] + [StructLayout(LayoutKind.Sequential)] + public struct ADMIN_OTHER_INFO + { + /// Specifies the error code for the new message written to the message log. + public uint alrtad_errcode; + + /// Specifies the number (0-9) of consecutive Unicode strings written to the message log. + public uint alrtad_numstrings; + } + + /// + /// The ERRLOG_OTHER_INFO structure contains error log information. The NetAlertRaise and NetAlertRaiseEx functions use the + /// ERRLOG_OTHER_INFO structure to specify information when adding a new entry to the error log. + /// + /// + /// The calling application must allocate and free the memory for all structures and variable-length data in an alert message buffer. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmalert/ns-lmalert-_errlog_other_info typedef struct _ERRLOG_OTHER_INFO { + // DWORD alrter_errcode; DWORD alrter_offset; } ERRLOG_OTHER_INFO, *PERRLOG_OTHER_INFO, *LPERRLOG_OTHER_INFO; + [PInvokeData("lmalert.h", MSDNShortId = "832ebe88-e1c4-4ce3-8057-922419b577f7")] + [StructLayout(LayoutKind.Sequential)] + public struct ERRLOG_OTHER_INFO + { + /// Specifies the error code that was written to the error log. + public uint alrter_errcode; + + /// Specifies the offset for the new entry in the error log. + public uint alrter_offset; + } + + /// + /// The PRINT_OTHER_INFO structure contains information about a print job. The NetAlertRaise and NetAlertRaiseEx functions use + /// the PRINT_OTHER_INFO structure to specify information when a job has finished printing, or when a printer needs intervention. + /// + /// + /// + /// Additional variable-length data follows the PRINT_OTHER_INFO structure in the alert message buffer. The information is in + /// the form of contiguous null-terminated character strings, as follows. + /// + /// + /// + /// String + /// Meaning + /// + /// + /// computername + /// The computer that submitted the print job. + /// + /// + /// username + /// The user who submitted the print job. + /// + /// + /// queuename + /// The print queue to which the job was submitted. + /// + /// + /// destination + /// The printer destination (device) to which the print job was routed. + /// + /// + /// status + /// The status of the print job. + /// + /// + /// + /// The calling application must allocate and free the memory for all structures and variable-length data in an alert message buffer. + /// + /// See NetAlertRaiseEx for a code sample that demonstrates how to raise a print alert. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmalert/ns-lmalert-_print_other_info typedef struct _PRINT_OTHER_INFO { DWORD + // alrtpr_jobid; DWORD alrtpr_status; DWORD alrtpr_submitted; DWORD alrtpr_size; } PRINT_OTHER_INFO, *PPRINT_OTHER_INFO, *LPPRINT_OTHER_INFO; + [PInvokeData("lmalert.h", MSDNShortId = "f2fd87bc-abde-43c0-b29d-d43cc5f038b8")] + [StructLayout(LayoutKind.Sequential)] + public struct PRINT_OTHER_INFO + { + /// + /// Type: DWORD + /// The identification number of the print job. + /// + public uint alrtpr_jobid; + + /// + /// Type: DWORD + /// A bitmask describing the status of the print job. + /// You can obtain the overall status of the job by checking PRJOB_QSTATUS (bits 0 and 1). + /// Possible values for the print job status are listed in the Lmalert.h header file. + /// + /// + /// Value + /// Meaning + /// + /// + /// PRJOB_QS_QUEUED 0 + /// The print job is in the queue waiting to be scheduled. + /// + /// + /// PRJOB_QS_PAUSED 1 + /// The print job is in the queue, but it has been paused. (When a job is paused, it cannot be scheduled.) + /// + /// + /// PRJOB_QS_SPOOLING 2 + /// The print job is in the process of being spooled. + /// + /// + /// PRJOB_QS_PRINTING 3 + /// The job is currently printing. + /// + /// + /// + /// If the print job is in the PRJOB_QS_PRINTING state, you can check bits 2 through 8 for the device's status (PRJOB_DEVSTATUS). + /// Bit 15 is also meaningful. + /// + /// Possible values for the device's status are listed in the Lmalert.h header file. + /// + /// + /// Value + /// Meaning + /// + /// + /// PRJOB_COMPLETE 0x4 + /// The job has completed printing. + /// + /// + /// PRJOB_INTERV 0x8 + /// The destination printer requires an operator's intervention. + /// + /// + /// PRJOB_ERROR 0x10 + /// There is an error at the destination printer. + /// + /// + /// PRJOB_DESTOFFLINE 0x20 + /// The destination printer is offline. + /// + /// + /// PRJOB_DESTPAUSED 0x40 + /// The destination printer is paused. + /// + /// + /// PRJOB_NOTIFY 0x80 + /// A printing alert should be raised. + /// + /// + /// PRJOB_DESTNOPAPER 0x100 + /// The destination printer is out of paper. + /// + /// + /// PRJOB_DELETED 0x8000 + /// The printing job is being deleted. + /// + /// + /// + public PRJOB alrtpr_status; + + /// + /// Type: DWORD + /// + /// The time at which the print job was submitted. This value is stored as the number of seconds that have elapsed since + /// 00:00:00, January 1, 1970, GMT. + /// + /// + public uint alrtpr_submitted; + + /// + /// Type: DWORD + /// The size, in bytes, of the print job. + /// + public uint alrtpr_size; + } + + /// + /// The STD_ALERT structure contains the time and date when a significant event occurred. The structure also contains an alert + /// class and the name of the application that is raising the alert message. You must specify the STD_ALERT structure when you + /// send an alert message using the NetAlertRaise function. + /// + /// + /// + /// The STD_ALERT structure must be followed by one ADMIN_OTHER_INFO, ERRLOG_OTHER_INFO, PRINT_OTHER_INFO, or USER_OTHER_INFO + /// structure. These structures can optionally be followed by variable-length data. The calling application must allocate the memory + /// for all structures and variable-length data in an alert message buffer. + /// + /// + /// See NetAlertRaise for a code sample that raises an administrative alert using a STD_ALERT structure and an + /// ADMIN_OTHER_INFO structure. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmalert/ns-lmalert-_std_alert typedef struct _STD_ALERT { DWORD + // alrt_timestamp; WCHAR alrt_eventname[EVLEN + 1]; WCHAR alrt_servicename[SNLEN + 1]; } STD_ALERT, *PSTD_ALERT, *LPSTD_ALERT; + [PInvokeData("lmalert.h", MSDNShortId = "daa4594f-e59e-4f05-8183-677bee4ea446")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + public struct STD_ALERT + { + /// + /// Type: DWORD + /// + /// The time and date of the event. This value is stored as the number of seconds that have elapsed since 00:00:00, January 1, + /// 1970, GMT. + /// + /// + public uint alrt_timestamp; + + /// + /// Type: WCHAR[EVLEN + 1] + /// + /// A Unicode string indicating the alert class (type of event). This parameter can be one of the following predefined values, or + /// another alert class that you have defined for network applications. (The event name for an alert can be any text string.) + /// + /// + /// + /// Name + /// Meaning + /// + /// + /// ALERT_ADMIN_EVENT + /// An administrator's intervention is required. + /// + /// + /// ALERT_ERRORLOG_EVENT + /// An entry was added to the error log. + /// + /// + /// ALERT_MESSAGE_EVENT + /// A user or application received a broadcast message. + /// + /// + /// ALERT_PRINT_EVENT + /// A print job completed or a print error occurred. + /// + /// + /// ALERT_USER_EVENT + /// An application or resource was used. + /// + /// + /// + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 17)] + public string alrt_eventname; + + /// + /// Type: WCHAR[SNLEN + 1] + /// A Unicode string indicating the service application that is raising the alert message. + /// + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 81)] + public string alrt_servicename; + } + + /// + /// The USER_OTHER_INFO structure contains user error code information. The NetAlertRaise and NetAlertRaiseEx functions use + /// the USER_OTHER_INFO structure to specify information about an event or condition of interest to a user. + /// + /// + /// + /// Additional variable-length data follows the USER_OTHER_INFO structure in the alert message buffer. The information is in + /// the form of contiguous null-terminated character strings, as follows. + /// + /// + /// + /// String + /// Meaning + /// + /// + /// username + /// The user who created the session. + /// + /// + /// computername + /// The computer that created the session. + /// + /// + /// + /// The calling application must allocate and free the memory for all structures and variable-length data in an alert message buffer. + /// + /// See NetAlertRaiseEx for a code sample that demonstrates how to raise a user alert. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmalert/ns-lmalert-_user_other_info typedef struct _USER_OTHER_INFO { DWORD + // alrtus_errcode; DWORD alrtus_numstrings; } USER_OTHER_INFO, *PUSER_OTHER_INFO, *LPUSER_OTHER_INFO; + [PInvokeData("lmalert.h", MSDNShortId = "2f6bd906-fdab-410a-8856-4482e047371f")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public struct USER_OTHER_INFO + { + /// Specifies the error code for the new message in the message log. + public uint alrtus_errcode; + + /// Specifies the number (0-9) of consecutive Unicode strings in the message log. + public uint alrtus_numstrings; + } + } +} \ No newline at end of file diff --git a/PInvoke/NetApi32/LmApiBuf.cs b/PInvoke/NetApi32/LmApiBuf.cs new file mode 100644 index 00000000..69941c14 --- /dev/null +++ b/PInvoke/NetApi32/LmApiBuf.cs @@ -0,0 +1,176 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Security; +using Vanara.Extensions; + +namespace Vanara.PInvoke +{ + public static partial class NetApi32 + { + /// + /// The NetApiBufferAllocate function allocates memory from the heap. Use this function only when compatibility with the + /// NetApiBufferFree function is required. Otherwise, use the memory management functions. + /// + /// Number of bytes to be allocated. + /// Receives a pointer to the allocated buffer. + /// + /// If the function succeeds, the return value is NERR_Success. + /// If the function fails, the return value is a system error code. For a list of error codes, see System Error Codes. + /// + /// + /// No special group membership is required to successfully execute the ApiBuffer functions. + /// For more information, see Network Management Function Buffers and Network Management Function Buffer Lengths. + /// Examples + /// The following code sample demonstrates how to use the network management ApiBuffer functions. + /// + /// The sample first calls the NetApiBufferAllocate function to allocate memory and then the NetApiBufferSize function to + /// retrieve the size of the allocated memory. Following this, the sample calls NetApiBufferReallocate to change the size of the + /// memory allocation. Finally, the sample calls NetApiBufferFree to free the memory. In each case, the sample prints a message + /// indicating success or failure. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmapibuf/nf-lmapibuf-netapibufferallocate NET_API_STATUS NET_API_FUNCTION + // NetApiBufferAllocate( DWORD ByteCount, LPVOID *Buffer ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("lmapibuf.h", MSDNShortId = "9ff1e3eb-9417-469f-a8c0-cdcda3cd9583")] + public static extern Win32Error NetApiBufferAllocate(uint ByteCount, out SafeNetApiBuffer Buffer); + + /// + /// The NetApiBufferFree function frees the memory that the NetApiBufferAllocate function allocates. Applications should also call + /// NetApiBufferFree to free the memory that other network management functions use internally to return information. + /// + /// + /// A pointer to a buffer returned previously by another network management function or memory allocated by calling the + /// NetApiBufferAllocate function. + /// + /// + /// If the function succeeds, the return value is NERR_Success. If the function fails, the return value is a system error code. + /// + [DllImport(Lib.NetApi32, ExactSpelling = true), SuppressUnmanagedCodeSecurity] + [PInvokeData("lm.h", MSDNShortId = "aa370304")] + public static extern Win32Error NetApiBufferFree(IntPtr pBuf); + + /// + /// The NetApiBufferReallocate function changes the size of a buffer allocated by a previous call to the NetApiBufferAllocate function. + /// + /// Pointer to the buffer returned by a call to the NetApiBufferAllocate function. + /// Specifies the new size of the buffer, in bytes. + /// Receives the pointer to the reallocated buffer. + /// + /// If the function succeeds, the return value is NERR_Success. + /// If the function fails, the return value is a system error code. For a list of error codes, see System Error Codes. + /// + /// + /// No special group membership is required to successfully execute the ApiBuffer functions. + /// For a code sample that demonstrates how to use the network management ApiBuffer functions, see NetApiBufferAllocate. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmapibuf/nf-lmapibuf-netapibufferreallocate NET_API_STATUS NET_API_FUNCTION + // NetApiBufferReallocate( _Frees_ptr_opt_ LPVOID OldBuffer, DWORD NewByteCount, LPVOID *NewBuffer ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("lmapibuf.h", MSDNShortId = "61153de0-33d3-4c83-a8aa-a7179252328c")] + public static extern Win32Error NetApiBufferReallocate(IntPtr OldBuffer, uint NewByteCount, out IntPtr NewBuffer); + + /// + /// The NetApiBufferSize function returns the size, in bytes, of a buffer allocated by a call to the NetApiBufferAllocate function. + /// + /// Pointer to a buffer returned by the NetApiBufferAllocate function. + /// Receives the size of the buffer, in bytes. + /// + /// If the function succeeds, the return value is NERR_Success. + /// If the function fails, the return value is a system error code. For a list of error codes, see System Error Codes. + /// + /// + /// No special group membership is required to successfully execute the ApiBuffer functions. + /// For a code sample that demonstrates how to use the network management ApiBuffer functions, see NetApiBufferAllocate. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmapibuf/nf-lmapibuf-netapibuffersize NET_API_STATUS NET_API_FUNCTION + // NetApiBufferSize( LPVOID Buffer, LPDWORD ByteCount ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("lmapibuf.h", MSDNShortId = "0c28feeb-00a3-4ad5-b85f-96326515fae2")] + public static extern Win32Error NetApiBufferSize(IntPtr Buffer, out uint ByteCount); + + /// Provides a to a buffer that releases a created handle at disposal using NetApiBufferFree. + public class SafeNetApiBuffer : SafeHANDLE + { + /// Initializes a new instance of the class and assigns an existing handle. + /// An object that represents the pre-existing handle to use. + /// + /// to reliably release the handle during the finalization phase; otherwise, (not recommended). + /// + public SafeNetApiBuffer(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { } + + /// Initializes a new instance of the class. + private SafeNetApiBuffer() : base() { } + + /// + /// Gets or sets the size of the buffer in bytes. When setting, this reallocates the existing buffer and does not guarantee that + /// the currently allocated memory will be untouched or destroyed. + /// + /// The size of the allocated memory in bytes. + public uint Size + { + get { var err = NetApiBufferSize(handle, out var sz); return err.Succeeded ? sz : throw err.GetException(); } + set { NetApiBufferReallocate(handle, value, out var h).ThrowIfFailed(); SetHandle(h); } + } + + /// Allocates memory for a new . + /// The size of the buffer in bytes. + /// A new instance of with the requested number of bytes allocated. + public static SafeNetApiBuffer Allocate(uint size) + { + NetApiBufferAllocate(size, out var b).ThrowIfFailed(); + return b; + } + + /// Extracts a list of structures. + /// The type of the structure. + /// The count of structures in the list. + /// The list of structures. + public IEnumerable ToIEnum(int count) => handle.ToIEnum(count); + + /// + public override string ToString() => Extensions.StringHelper.GetString(handle); + + /// Extracts a list of strings. Used by . + /// The number of elements in the list. + /// The list of strings. + public IEnumerable ToStringEnum(int count) => handle.ToStringEnum(count); + + /// Returns an extracted structure from this buffer. + /// The structure type to extract. + /// Extracted structure or default(T) if the buffer is invalid. + public T ToStructure() where T : struct => IsInvalid ? default : (T)Marshal.PtrToStructure(handle, typeof(T)); + + /// + protected override bool InternalReleaseHandle() => NetApiBufferFree(handle) == 0; + } + + /// A custom marshaler for functions using LSA_UNICODE_STRING so that managed strings can be used. + /// + internal class NetApiBufferUnicodeStringMarshaler : ICustomMarshaler + { + public static ICustomMarshaler GetInstance(string cookie) => new NetApiBufferUnicodeStringMarshaler(); + + public void CleanUpManagedData(object ManagedObj) + { + } + + public void CleanUpNativeData(IntPtr pNativeData) + { + } + + public int GetNativeDataSize() => 0; + + public IntPtr MarshalManagedToNative(object ManagedObj) => throw new NotImplementedException(); + + public object MarshalNativeToManaged(IntPtr pNativeData) + { + if (pNativeData == IntPtr.Zero) return null; + var s = StringHelper.GetString(pNativeData, CharSet.Unicode); + NetApiBufferFree(pNativeData); + return s; + } + } + } +} \ No newline at end of file diff --git a/PInvoke/NetApi32/LmJoin.cs b/PInvoke/NetApi32/LmJoin.cs new file mode 100644 index 00000000..ae8c45fe --- /dev/null +++ b/PInvoke/NetApi32/LmJoin.cs @@ -0,0 +1,3063 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; +using Vanara.Extensions; + +namespace Vanara.PInvoke +{ + public static partial class NetApi32 + { + /// + /// Specifies the possible ways that a device can be joined to Microsoft Azure Active Directory. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmjoin/ne-lmjoin-_dsreg_join_type typedef enum _DSREG_JOIN_TYPE { + // DSREG_UNKNOWN_JOIN, DSREG_DEVICE_JOIN, DSREG_WORKPLACE_JOIN } DSREG_JOIN_TYPE, *PDSREG_JOIN_TYPE; + [PInvokeData("lmjoin.h", MSDNShortId = "E29BCBE0-222F-4CA8-97BC-6FE1B6F97A67")] + public enum DSREG_JOIN_TYPE + { + /// The type of join is not known. + DSREG_UNKNOWN_JOIN, + + /// The device is joined to Azure Active Directory (Azure AD). + DSREG_DEVICE_JOIN, + + /// An Azure AD work account is added on the device. + DSREG_WORKPLACE_JOIN, + } + + /// The type of the name queried in NetEnumerateComputerNames. + [PInvokeData("lmjoin.h", MSDNShortId = "c657ae33-404e-4c36-a956-5fbcfa540be7")] + public enum NET_COMPUTER_NAME_TYPE + { + /// The primary computer name. + NetPrimaryComputerName, + + /// Alternate computer names. + NetAlternateComputerNames, + + /// All computer names. + NetAllComputerNames, + + /// Indicates the end of the range that specifies the possible values for the type of name to be queried. + NetComputerNameTypeMax + } + + /// A set of bit flags defining domain join options. + [PInvokeData("lmjoin.h", MSDNShortId = "4efcb399-03af-4312-9f1d-6bc38f356cac")] + [Flags] + public enum NETSETUP + { + /// Joins the computer to a domain. If this value is not specified, joins the computer to a workgroup. + NETSETUP_JOIN_DOMAIN = 0x00000001, + + /// Creates the account on the domain. + NETSETUP_ACCT_CREATE = 0x00000002, + + /// The account is disabled when the unjoin occurs. + NETSETUP_ACCT_DELETE = 0x00000004, + + /// The join operation is occurring as part of an upgrade. + NETSETUP_WIN9X_UPGRADE = 0x00000010, + + /// Allows a join to a new domain even if the computer is already joined to a domain. + NETSETUP_DOMAIN_JOIN_IF_JOINED = 0x00000020, + + /// + /// Performs an unsecured join. + /// + /// This option requests a domain join to a pre-created account without authenticating with domain user credentials. This option + /// can be used in conjunction with NETSETUP_MACHINE_PWD_PASSED option. In this case, lpPassword is the password of the + /// pre-created machine account. + /// + /// + /// Prior to Windows Vista with SP1 and Windows Server 2008, an unsecure join did not authenticate to the domain controller. All + /// communication was performed using a null (unauthenticated) session.Starting with Windows Vista with SP1 and Windows Server + /// 2008, the machine account name and password are used to authenticate to the domain controller. + /// + /// + NETSETUP_JOIN_UNSECURE = 0x00000040, + + /// + /// Indicates that the lpPassword parameter specifies a local machine account password rather than a user password. This flag is + /// valid only for unsecured joins, which you must indicate by also setting the NETSETUP_JOIN_UNSECURE flag. + /// + /// If you set this flag, then after the join operation succeeds, the machine password will be set to the value of lpPassword, if + /// that value is a valid machine password. + /// + /// + NETSETUP_MACHINE_PWD_PASSED = 0x00000080, + + /// + /// Indicates that the service principal name (SPN) and the DnsHostName properties on the computer object should not be updated + /// at this time. + /// + /// Typically, these properties are updated during the join operation. Instead, these properties should be updated during a + /// subsequent call to the NetRenameMachineInDomain function. These properties are always updated during the rename operation. + /// For more information, see the following Remarks section. + /// + /// + NETSETUP_DEFER_SPN_SET = 0x00000100, + + /// + /// Allow the domain join if existing account is a domain controller. This flag is supported on Windows Vista + /// and later. + /// + NETSETUP_JOIN_DC_ACCOUNT = 0x00000200, + + /// + /// Join the target machine specified in lpServer parameter with a new name queried from the registry on the machine specified in + /// the lpServer parameter. + /// + /// This option is used if SetComputerNameEx has been called prior to rebooting the machine. The new computer name will not take + /// effect until a reboot.With this option, the caller instructs the NetJoinDomain function to use the new name during the domain + /// join operation.A reboot is required after calling NetJoinDomain successfully at which time both the computer name change and + /// domain membership change will have taken affect. + /// + /// This flag is supported on Windows Vista and later. + /// + NETSETUP_JOIN_WITH_NEW_NAME = 0x00000400, + + /// + /// Join the target machine specified in lpServer parameter using a pre-created account without requiring a writable domain controller. + /// + /// This option provides the ability to join a machine to domain if an account has already been provisioned and replicated to a + /// read-only domain controller. The target read-only domain controller is specified as part of the lpDomain parameter, after the + /// domain name delimited by a ‘\’ character. This provisioning must include the machine secret. The machine account must be + /// added via group membership into the allowed list for password replication policy, and the account password must be replicated + /// to the read-only domain controller prior to the join operation. For more information, see the information on Password + /// Replication Policy Administration. + /// + /// + /// Starting with Windows 7, an alternate mechanism is to use the offline domain join mechanism. For more information, see the + /// NetProvisionComputerAccount and NetRequestOfflineDomainJoin functions. + /// + /// This flag is supported on Windows Vista and later. + /// + NETSETUP_JOIN_READONLY = 0x00000800, + + /// Limits any updates to DNS-based names only. + NETSETUP_DNS_NAME_CHANGES_ONLY = 0x00001000, + + /// Indicates that the protocol method was invoked during installation. + NETSETUP_INSTALL_INVOCATION = 0x00040000, + + /// + /// When joining the domain don't try to set the preferred domain controller in the registry. This flag is + /// supported on Windows 7, Windows Server 2008 R2, and later. + /// + NETSETUP_AMBIGUOUS_DC = 0x00001000, + + /// + /// When joining the domain don't create the Netlogon cache. This flag is supported on Windows 7, Windows + /// Server 2008 R2, and later. + /// + NETSETUP_NO_NETLOGON_CACHE = 0x00002000, + + /// + /// When joining the domain don't force Netlogon service to start. This flag is supported on Windows 7, Windows + /// Server 2008 R2, and later. + /// + NETSETUP_DONT_CONTROL_SERVICES = 0x00004000, + + /// + /// When joining the domain for offline join only, set target machine hostname and NetBIOS name. This flag is + /// supported on Windows 7, Windows Server 2008 R2, and later. + /// + NETSETUP_SET_MACHINE_NAME = 0x00008000, + + /// + /// When joining the domain, override other settings during domain join and set the service principal name (SPN). + /// This flag is supported on Windows 7, Windows Server 2008 R2, and later. + /// + NETSETUP_FORCE_SPN_SET = 0x00010000, + + /// + /// When joining the domain, do not reuse an existing account. This flag is supported on Windows 7, Windows + /// Server 2008 R2, and later. + /// + NETSETUP_NO_ACCT_REUSE = 0x00020000, + + /// Undocumented. + NETSETUP_ALT_SAMACCOUNTNAME = 0x00020000, + + /// + /// If this bit is set, unrecognized flags will be ignored by the NetJoinDomain function and NetJoinDomain will behave as if the + /// flags were not set. + /// + NETSETUP_IGNORE_UNSUPPORTED_FLAGS = 0x10000000, + + /// Valid unjoin flags. + NETSETUP_VALID_UNJOIN_FLAGS = NETSETUP_ACCT_DELETE | NETSETUP_IGNORE_UNSUPPORTED_FLAGS | NETSETUP_JOIN_DC_ACCOUNT, + + /// Undocumented. + NETSETUP_PROCESS_OFFLINE_FLAGS = NETSETUP_JOIN_DOMAIN | NETSETUP_DOMAIN_JOIN_IF_JOINED | NETSETUP_JOIN_WITH_NEW_NAME | NETSETUP_DONT_CONTROL_SERVICES | NETSETUP_MACHINE_PWD_PASSED, + } + + /// The join status of the specified computer. + [PInvokeData("lmjoin.h", MSDNShortId = "c7cc1cf2-4530-4039-806b-fbee572f564d")] + public enum NETSETUP_JOIN_STATUS + { + /// The status is unknown. + NetSetupUnknownStatus = 0, + + /// The computer is not joined. + NetSetupUnjoined, + + /// The computer is joined to a workgroup. + NetSetupWorkgroupName, + + /// The computer is joined to a domain. + NetSetupDomainName + } + + /// The type of the name passed in the lpName parameter of to validate. + [PInvokeData("lmjoin.h", MSDNShortId = "772603df-ec17-4a83-a715-2d9a14d5c2bb")] + public enum NETSETUP_NAME_TYPE + { + /// The nametype is unknown. If this value is used, the NetValidateName function fails with ERROR_INVALID_PARAMETER. + NetSetupUnknown = 0, + + /// Verify that the NetBIOS computer name is valid and that it is not in use. + NetSetupMachine, + + /// Verify that the workgroup name is valid. + NetSetupWorkgroup, + + /// Verify that the domain name exists and that it is a domain. + NetSetupDomain, + + /// Verify that the domain name is not in use. + NetSetupNonExistentDomain, + + /// + /// Verify that the DNS computer name is valid. + /// + /// This value is supported on Windows 2000 and later. The application must be compiled with _WIN32_WINNT >= 0x0500 to use + /// this value. + /// + /// + NetSetupDnsMachine + } + + /// Bit flags that define provisioning options. + [PInvokeData("lmjoin.h", MSDNShortId = "4c854258-b84d-4ef3-a6da-ce0a9540ffd5")] + [Flags] + public enum NETSETUP_PROVISION : uint + { + /// + /// If the caller requires account creation by privilege, this option will cause a retry on failure using account creation + /// functions enabling interoperability with domain controllers running on earlier versions of Windows. + /// The lpMachineAccountOU is not supported when using downlevel privilege support. + /// + NETSETUP_PROVISION_DOWNLEVEL_PRIV_SUPPORT = 0x00000001, + + /// + /// If the named account already exists, an attempt will be made to reuse the existing account. + /// This option requires sufficient credentials for this operation (Domain Administrator or the object owner). + /// + NETSETUP_PROVISION_REUSE_ACCOUNT = 0x00000002, + + /// + /// Use the default machine account password which is the machine name in lowercase. This is largely to support the older + /// unsecure join model where the pre-created account typically used this default password. Applications should + /// avoid using this option if possible.This option as well as NetJoinDomain function with dwOptions set to + /// NETSETUP_JOIN_UNSECURE for unsecure join should only be used on earlier versions of Windows. + /// + NETSETUP_PROVISION_USE_DEFAULT_PASSWORD = 0x00000004, + + /// + /// Do not try to find the account on any domain controller in the domain. This option makes the operation faster, but should + /// only be used when the caller is certain that an account by the same name hasn't recently been created. + /// + /// This option is only valid when the lpDcName parameter is specified. When the prerequisites are met, this option allows for + /// must faster provisioning useful for scenarios such as batch processing. + /// + /// + NETSETUP_PROVISION_SKIP_ACCOUNT_SEARCH = 0x00000008, + + /// + /// This option retrieves all of the root Certificate Authority certificates on the local machine and adds them to the + /// provisioning package when no certificate template names are provided as part of the provisioning package (the + /// aCertTemplateNames member of the NETSETUP_PROVISIONING_PARAMS struct passed in the pProvisioningParams parameter to the + /// NetCreateProvisioningPackage function is NULL). This flag is only supported by the + /// NetCreateProvisioningPackage function on Windows 8, Windows Server 2012, and later. + /// + NETSETUP_PROVISION_ROOT_CA_CERTS = 0x00000010, + + /// Undocumented. + NETSETUP_PROVISION_PERSISTENTSITE = 0x00000020, + + /// + /// This flag is required if the lpWindowsPath parameter references the currently running Windows operating system directory + /// rather than an offline Windows operating system image mounted on an accessible volume. If this flag is specified, the + /// NetRequestProvisioningPackageInstall function must be invoked by a member of the local Administrators group. + /// + NETSETUP_PROVISION_ONLINE_CALLER = 0x40000000, + + /// Undocumented. + NETSETUP_PROVISION_CHECK_PWD_ONLY = 0x80000000, + } + + /// The NetAddAlternateComputerName function adds an alternate name for the specified computer. + /// + /// A pointer to a constant string that specifies the name of the computer on which to execute this function. If this parameter is + /// NULL, the local computer is used. + /// + /// + /// A pointer to a constant string that specifies the alternate name to add. This name must be in the form of a fully qualified DNS name. + /// + /// + /// + /// A pointer to a constant string that specifies the domain account to use for accessing the machine account object for the computer + /// specified in the Server parameter in Active Directory. If this parameter is NULL, then the credentials of the user + /// executing this routine are used. + /// + /// This parameter is not used if the server to execute this function is not joined to a domain. + /// + /// + /// + /// A pointer to a constant string that specifies the password matching the domain account passed in the DomainAccount parameter. If + /// this parameter is NULL, then the credentials of the user executing this routine are used. + /// + /// + /// This parameter is ignored if the DomainAccount parameter is NULL. This parameter is not used if the server to execute this + /// function is not joined to a domain. + /// + /// + /// Reserved for future use. This parameter should be NULL. + /// + /// If the function succeeds, the return value is NERR_Success. + /// 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 + /// + /// Access is denied. This error is returned if the caller was not a member of the Administrators local group on the target computer. + /// + /// + /// + /// ERROR_INVALID_NAME + /// A name parameter is incorrect. This error is returned if the AlternateName parameter does not contain valid name. + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// A parameter is incorrect. This error is returned if the DomainAccount parameter does not contain a valid domain. This error is + /// also returned if the DomainAccount parameter is not NULL and the DomainAccountPassword parameter is not NULL but does not contain + /// a Unicode string. + /// + /// + /// + /// ERROR_NOT_ENOUGH_MEMORY + /// Not enough memory is available to process this command. + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The request is not supported. This error is returned if the target computer specified in the Server parameter on which this + /// function executes is running on Windows 2000 and earlier. + /// + /// + /// + /// NERR_WkstaNotStarted + /// The Workstation service has not been started. + /// + /// + /// RPC_S_CALL_IN_PROGRESS + /// A remote procedure call is already in progress for this thread. + /// + /// + /// RPC_S_PROTSEQ_NOT_SUPPORTED + /// The remote procedure call protocol sequence is not supported. + /// + /// + /// + /// + /// The NetAddAlternateComputerName function is supported on Windows XP and later. + /// + /// The NetAddAlternateComputerName function is used to set secondary network names for computers. The primary name is the + /// name used for authentication and maps to the machine account name. + /// + /// + /// The NetAddAlternateComputerName function requires that the caller is a member of the Administrators local group on the + /// target computer. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmjoin/nf-lmjoin-netaddalternatecomputername NET_API_STATUS NET_API_FUNCTION + // NetAddAlternateComputerName( LPCWSTR Server, LPCWSTR AlternateName, LPCWSTR DomainAccount, LPCWSTR DomainAccountPassword, ULONG + // Reserved ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] + [PInvokeData("lmjoin.h", MSDNShortId = "710865c6-e327-439c-931d-de8674d69233")] + public static extern Win32Error NetAddAlternateComputerName([Optional] string Server, string AlternateName, [Optional] string DomainAccount, [Optional] string DomainAccountPassword, uint Reserved = 0); + + /// + /// The NetCreateProvisioningPackage function creates a provisioning package that provisions a computer account for later use in an + /// offline domain join operation. The package may also contain information about certificates and policies to add to the machine + /// during provisioning. + /// + /// + /// A pointer to a NETSETUP_PROVISIONING_PARAMS structure that contains information about the provisioning package. + /// The following values are defined for the members of this structure: + /// + /// + /// Value + /// Meaning + /// + /// + /// dwVersion + /// + /// The version of Windows in the provisioning package. This member should use the following value defined in the Lmjoin.h header + /// file: NETSETUP_PROVISIONING_PARAMS_CURRENT_VERSION (0x00000001) + /// + /// + /// + /// lpDomain + /// + /// A pointer to a constant null-terminated character string that specifies the name of the domain where the computer account is created. + /// + /// + /// + /// lpMachineName + /// + /// A pointer to a constant null-terminated character string that specifies the short name of the machine from which the computer + /// account attribute sAMAccountName is derived by appending a '$'. This parameter must contain a valid DNS or NetBIOS machine name. + /// + /// + /// + /// lpMachineAccountOU + /// + /// An optional pointer to a constant null-terminated character string that contains the RFC 1779 format name of the organizational + /// unit (OU) where the computer account will be created. If you specify this parameter, the string must contain a full path, for + /// example, OU=testOU,DC=domain,DC=Domain,DC=com. Otherwise, this parameter must be NULL. If this parameter is NULL, the well known + /// computer object container will be used as published in the domain. + /// + /// + /// + /// lpDcName + /// + /// An optional pointer to a constant null-terminated character string that contains the name of the domain controller to target. + /// + /// + /// + /// dwProvisionOptions + /// + /// A set of bit flags that define provisioning options. This parameter can be one or more of the values specified for the dwOptions + /// parameter passed to the NetProvisionComputerAccount function. These possible values are defined in the Lmjoin.h header file. The + /// NETSETUP_PROVISION_ROOT_CA_CERTS option is only supported on Windows 8 and Windows Server 2012. + /// + /// + /// + /// aCertTemplateNames + /// A optional pointer to an array of NULL-terminated certificate template names. + /// + /// + /// cCertTemplateNames + /// When aCertTemplateNames is not NULL, this member provides an explicit count of the number of items in the array. + /// + /// + /// aMachinePolicyNames + /// An optional pointer to an array of NULL-terminated machine policy names. + /// + /// + /// cMachinePolicyNames + /// When aMachinePolicyNames is not NULL, this member provides an explicit count of the number of items in the array. + /// + /// + /// aMachinePolicyPaths + /// + /// An optional pointer to an array of character strings. Each array element is a NULL-terminated character string which specifies + /// the full or partial path to a file in the Registry Policy File format. For more information on the Registry Policy File Format , + /// see Registry Policy File Format The path could be a UNC path on a remote server. + /// + /// + /// + /// cMachinePolicyPaths + /// When aMachinePolicyPaths is not NULL, this member provides an explicit count of the number of items in the array. + /// + /// + /// + /// + /// + /// An optional pointer that will receive the package required by NetRequestOfflineDomainJoin function to complete an offline domain + /// join, if the NetProvisionComputerAccount function completes successfully. The data is returned as an opaque binary buffer which + /// may be passed to NetRequestOfflineDomainJoin function. + /// + /// + /// If this parameter is NULL, then pPackageTextData parameter must not be NULL. If this parameter is not NULL, + /// then the pPackageTextData parameter must be NULL. + /// + /// + /// + /// A pointer to a value that receives the size, in bytes, of the buffer returned in the pProvisionBinData parameter. + /// + /// This parameter must not be NULL if the pPackageBinData parameter is not NULL. This parameter must be NULL + /// when the pPackageBinData parameter is NULL. + /// + /// + /// + /// + /// An optional pointer that will receive the package required by NetRequestOfflineDomainJoin function to complete an offline domain + /// join, if the NetProvisionComputerAccount function completes successfully. The data is returned in string form for embedding in an + /// unattended setup answer file. + /// + /// + /// If this parameter is NULL, then the pPackageBinData parameter must not be NULL. If this parameter is not + /// NULL, then the the pPackageBinData parameter must be NULL. + /// + /// + /// + /// If the function succeeds, the return value is NERR_Success. + /// 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 + /// Access is denied. This error is returned if the caller does not have sufficient privileges to complete the operation. + /// + /// + /// ERROR_INVALID_DOMAIN_ROLE + /// + /// This operation is only allowed for the Primary Domain Controller of the domain. This error is returned if a domain controller + /// name was specified in the lpDcName of the NETSETUP_PROVISIONING_PARAMS struct pointed to by the pProvisioningParams parameter, + /// but the computer specified could not be validated as a domain controller for the target domain specified in the lpDomain of the NETSETUP_PROVISIONING_PARAMS. + /// + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// A parameter is incorrect. This error is also returned if both the pProvisioningParams parameter is NULL. This error is also + /// returned if the lpDomain or lpMachineName member of the NETSETUP_PROVISIONING_PARAMS struct pointed to by the pProvisioningParams + /// parameter is NULL. + /// + /// + /// + /// ERROR_NO_SUCH_DOMAIN + /// The specified domain did not exist. + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The request is not supported. This error is returned if the lpMachineAccountOU member was specified in the + /// NETSETUP_PROVISIONING_PARAMS struct pointed to by the pProvisioningParams parameter and the domain controller is running on an + /// earlier versions of Windows that does not support this parameter. + /// + /// + /// + /// NERR_DS8DCRequired + /// The specified domain controller does not meet the version requirement for this operation. + /// + /// + /// NERR_LDAPCapableDCRequired + /// This operation requires a domain controller which supports LDAP. + /// + /// + /// NERR_UserExists + /// + /// The account already exists in the domain and the NETSETUP_PROVISION_REUSE_ACCOUNT bit was not specified in the dwProvisionOptions + /// member of the NETSETUP_PROVISIONING_PARAMS struct pointed to by the pProvisioningParams parameter. + /// + /// + /// + /// NERR_WkstaNotStarted + /// The Workstation service has not been started. + /// + /// + /// RPC_S_CALL_IN_PROGRESS + /// A remote procedure call is already in progress for this thread. + /// + /// + /// RPC_S_PROTSEQ_NOT_SUPPORTED + /// The remote procedure call protocol sequence is not supported. + /// + /// + /// + /// + /// + /// The NetCreateProvisioningPackage function is supported on Windows 8 and Windows Server 2012 for offline join operations. + /// For Windows 7, use the NetProvisionComputerAccount function. + /// + /// + /// The NetCreateProvisioningPackage function is used to provision a computer account for later use in an offline domain join + /// operation using the NetRequestProvisioningPackageInstall function. + /// + /// The offline domain join scenario uses two functions: + /// + /// + /// + /// NetCreateProvisioningPackage is a provisioning function that is first called to perform the network operations necessary + /// to create and configure the computer object in Active Directory. The output from the NetCreateProvisioningPackage is a + /// package used for the next step. + /// + /// + /// + /// + /// NetRequestProvisioningPackageInstall, an image initialization function, is called to inject the output from the + /// NetCreateProvisioningPackage provisioning function into a Windows operating system image for use during pre-installation + /// and post-installation. + /// + /// + /// + /// Changes to Windows initialization code will detect this saved state and affect the local-only portion of domain join. + /// + /// When the pPackageBinData and pdwPackageBinDataSize out pointers are used, set the pPackageTextData out pointer to NULL. When + /// pPackageTextData is used, set the pPackageBinData and pdwPackageBinDataSize out pointers to NULL. + /// + /// + /// The pProvisioningParams parameter specifies data to include in the provisioning package. The package includes information + /// relevant to the domain join, and it can also include information about policies and certificates to install on the machine. The + /// provisioning package can be used in four ways: + /// + /// + /// + /// Domain join + /// + /// + /// Domain join and installation of certificates + /// + /// + /// Domain join and installation of policies + /// + /// + /// Domain join and installation of certificates and policies + /// + /// + /// + /// The NetCreateProvisioningPackage function creates or reuses the machine account in the domain, collects all necessary + /// metadata and returns it in a package. The package can be consumed by the offline domain join request operation supplying all the + /// necessary input to complete the domain join during first boot without any network operations (local state updates only). + /// + /// + /// Security Note: The package returned by the NetCreateProvisioningPackage function contains very sensitive data. It + /// should be treated just as securely as a plaintext password. The package contains the machine account password and other + /// information about the domain, including the domain name, the name of a domain controller, and the security ID (SID) of the + /// domain. If the package is being transported physically or over the network, care must be taken to transport it securely. The + /// design makes no provisions for securing this data. This problem exists today with unattended setup answer files which can carry a + /// number of secrets including domain user passwords. The caller must secure the package. Solutions to this problem are varied. As + /// an example, a pre-exchanged key could be used to encrypt a session between the consumer and provisioning entity enabling a secure + /// transfer of the package. + /// + /// + /// The package returned in the pPackageBinData parameter by the NetCreateProvisioningPackage function is versioned to allow + /// interoperability and serviceability scenarios between different versions of Windows (such as joining a client, provisioning a + /// machine, and using a domain controller). A package created on Windows 8 or Windows Server 2012 can be used Windows 7 or Windows + /// Server 2008 R2, however only domain join information will take effect (certificates and policies are not supported). The offline + /// join scenario currently does not limit the lifetime of the package returned by the NetCreateProvisioningPackage function. + /// + /// + /// For offline domain joins, the access check performed depends on the configuration of the domain. Computer account creation is + /// enabled using three methods: + /// + /// + /// + /// Domain administrators have rights to create computer accounts. + /// + /// + /// The SD on a container can delegate the rights to create computer accounts. + /// + /// + /// + /// By default, authenticated users may create computer accounts by privilege. Authenticated users are limited to creating a limited + /// number of accounts that is specified as a quota on the domain (the default value is 10). For more information, see the + /// ms-DS-MachineAccountQuota attribute in the Active Directory schema. + /// + /// + /// + /// + /// The NetCreateProvisioningPackage function works only with a writable domain controller and does not function against a + /// read-only domain controller. Once provisioning is done against a writable domain controller and the account is replicated to a + /// read-only domain controller, the other portions of the offline domain join operation do not require access to a domain controller. + /// + /// + /// If the NetCreateProvisioningPackage function is successful, the pointer in the pPackageBinData or pPackageTextData + /// parameter (depending on which parameter was not NULL) is returned with the serialized data for use in an offline join + /// operation or as text in an unattended setup file. + /// + /// + /// All phases of the provisioning process append to a NetSetup.log file on the local computer. The provisoning process can include + /// up to three different computers: the computer where the provisioning package is created, the computer that requests the + /// installation of the package, and the computer where the package is installed. There will be NetSetup.log file information stored + /// on all three computers according to the operation performed. Reviewing the contents of these files is the most common means of + /// troubleshooting online and offline provisioning errors. Provisioning operations undertaken by admins are logged to the + /// NetSetup.log file in the %WINDIR%\Debug. Provisioning operations performed by non-admins are logged to the NetSetup.log file in + /// the %USERPROFILE%\Debug folder. + /// + /// For more information on offline domain join operations, see the Offline Domain Join Step-by-Step Guide. + /// + /// Joining (and unjoining) a computer to a domain using NetJoinDomain and NetUnjoinDomain is performed only by a member of the + /// Administrators local group on the target computer. Note that the domain administrator can set additional requirements for joining + /// the domain using delegation and assignment of privileges. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmjoin/nf-lmjoin-netcreateprovisioningpackage NET_API_STATUS NET_API_FUNCTION + // NetCreateProvisioningPackage( PNETSETUP_PROVISIONING_PARAMS pProvisioningParams, PBYTE *ppPackageBinData, DWORD + // *pdwPackageBinDataSize, LPWSTR *ppPackageTextData ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] + [PInvokeData("lmjoin.h", MSDNShortId = "6E2A5578-8308-41E2-B5E9-5E34E9E76C0B")] + public static extern Win32Error NetCreateProvisioningPackage(ref NETSETUP_PROVISIONING_PARAMS pProvisioningParams, out IntPtr ppPackageBinData, + out uint pdwPackageBinDataSize, IntPtr ppPackageTextData = default); + + /// + /// The NetCreateProvisioningPackage function creates a provisioning package that provisions a computer account for later use in an + /// offline domain join operation. The package may also contain information about certificates and policies to add to the machine + /// during provisioning. + /// + /// + /// A pointer to a NETSETUP_PROVISIONING_PARAMS structure that contains information about the provisioning package. + /// The following values are defined for the members of this structure: + /// + /// + /// Value + /// Meaning + /// + /// + /// dwVersion + /// + /// The version of Windows in the provisioning package. This member should use the following value defined in the Lmjoin.h header + /// file: NETSETUP_PROVISIONING_PARAMS_CURRENT_VERSION (0x00000001) + /// + /// + /// + /// lpDomain + /// + /// A pointer to a constant null-terminated character string that specifies the name of the domain where the computer account is created. + /// + /// + /// + /// lpMachineName + /// + /// A pointer to a constant null-terminated character string that specifies the short name of the machine from which the computer + /// account attribute sAMAccountName is derived by appending a '$'. This parameter must contain a valid DNS or NetBIOS machine name. + /// + /// + /// + /// lpMachineAccountOU + /// + /// An optional pointer to a constant null-terminated character string that contains the RFC 1779 format name of the organizational + /// unit (OU) where the computer account will be created. If you specify this parameter, the string must contain a full path, for + /// example, OU=testOU,DC=domain,DC=Domain,DC=com. Otherwise, this parameter must be NULL. If this parameter is NULL, the well known + /// computer object container will be used as published in the domain. + /// + /// + /// + /// lpDcName + /// + /// An optional pointer to a constant null-terminated character string that contains the name of the domain controller to target. + /// + /// + /// + /// dwProvisionOptions + /// + /// A set of bit flags that define provisioning options. This parameter can be one or more of the values specified for the dwOptions + /// parameter passed to the NetProvisionComputerAccount function. These possible values are defined in the Lmjoin.h header file. The + /// NETSETUP_PROVISION_ROOT_CA_CERTS option is only supported on Windows 8 and Windows Server 2012. + /// + /// + /// + /// aCertTemplateNames + /// A optional pointer to an array of NULL-terminated certificate template names. + /// + /// + /// cCertTemplateNames + /// When aCertTemplateNames is not NULL, this member provides an explicit count of the number of items in the array. + /// + /// + /// aMachinePolicyNames + /// An optional pointer to an array of NULL-terminated machine policy names. + /// + /// + /// cMachinePolicyNames + /// When aMachinePolicyNames is not NULL, this member provides an explicit count of the number of items in the array. + /// + /// + /// aMachinePolicyPaths + /// + /// An optional pointer to an array of character strings. Each array element is a NULL-terminated character string which specifies + /// the full or partial path to a file in the Registry Policy File format. For more information on the Registry Policy File Format , + /// see Registry Policy File Format The path could be a UNC path on a remote server. + /// + /// + /// + /// cMachinePolicyPaths + /// When aMachinePolicyPaths is not NULL, this member provides an explicit count of the number of items in the array. + /// + /// + /// + /// + /// + /// An optional pointer that will receive the package required by NetRequestOfflineDomainJoin function to complete an offline domain + /// join, if the NetProvisionComputerAccount function completes successfully. The data is returned as an opaque binary buffer which + /// may be passed to NetRequestOfflineDomainJoin function. + /// + /// + /// If this parameter is NULL, then pPackageTextData parameter must not be NULL. If this parameter is not NULL, + /// then the pPackageTextData parameter must be NULL. + /// + /// + /// + /// A pointer to a value that receives the size, in bytes, of the buffer returned in the pProvisionBinData parameter. + /// + /// This parameter must not be NULL if the pPackageBinData parameter is not NULL. This parameter must be NULL + /// when the pPackageBinData parameter is NULL. + /// + /// + /// + /// + /// An optional pointer that will receive the package required by NetRequestOfflineDomainJoin function to complete an offline domain + /// join, if the NetProvisionComputerAccount function completes successfully. The data is returned in string form for embedding in an + /// unattended setup answer file. + /// + /// + /// If this parameter is NULL, then the pPackageBinData parameter must not be NULL. If this parameter is not + /// NULL, then the the pPackageBinData parameter must be NULL. + /// + /// + /// + /// If the function succeeds, the return value is NERR_Success. + /// 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 + /// Access is denied. This error is returned if the caller does not have sufficient privileges to complete the operation. + /// + /// + /// ERROR_INVALID_DOMAIN_ROLE + /// + /// This operation is only allowed for the Primary Domain Controller of the domain. This error is returned if a domain controller + /// name was specified in the lpDcName of the NETSETUP_PROVISIONING_PARAMS struct pointed to by the pProvisioningParams parameter, + /// but the computer specified could not be validated as a domain controller for the target domain specified in the lpDomain of the NETSETUP_PROVISIONING_PARAMS. + /// + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// A parameter is incorrect. This error is also returned if both the pProvisioningParams parameter is NULL. This error is also + /// returned if the lpDomain or lpMachineName member of the NETSETUP_PROVISIONING_PARAMS struct pointed to by the pProvisioningParams + /// parameter is NULL. + /// + /// + /// + /// ERROR_NO_SUCH_DOMAIN + /// The specified domain did not exist. + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The request is not supported. This error is returned if the lpMachineAccountOU member was specified in the + /// NETSETUP_PROVISIONING_PARAMS struct pointed to by the pProvisioningParams parameter and the domain controller is running on an + /// earlier versions of Windows that does not support this parameter. + /// + /// + /// + /// NERR_DS8DCRequired + /// The specified domain controller does not meet the version requirement for this operation. + /// + /// + /// NERR_LDAPCapableDCRequired + /// This operation requires a domain controller which supports LDAP. + /// + /// + /// NERR_UserExists + /// + /// The account already exists in the domain and the NETSETUP_PROVISION_REUSE_ACCOUNT bit was not specified in the dwProvisionOptions + /// member of the NETSETUP_PROVISIONING_PARAMS struct pointed to by the pProvisioningParams parameter. + /// + /// + /// + /// NERR_WkstaNotStarted + /// The Workstation service has not been started. + /// + /// + /// RPC_S_CALL_IN_PROGRESS + /// A remote procedure call is already in progress for this thread. + /// + /// + /// RPC_S_PROTSEQ_NOT_SUPPORTED + /// The remote procedure call protocol sequence is not supported. + /// + /// + /// + /// + /// + /// The NetCreateProvisioningPackage function is supported on Windows 8 and Windows Server 2012 for offline join operations. + /// For Windows 7, use the NetProvisionComputerAccount function. + /// + /// + /// The NetCreateProvisioningPackage function is used to provision a computer account for later use in an offline domain join + /// operation using the NetRequestProvisioningPackageInstall function. + /// + /// The offline domain join scenario uses two functions: + /// + /// + /// + /// NetCreateProvisioningPackage is a provisioning function that is first called to perform the network operations necessary + /// to create and configure the computer object in Active Directory. The output from the NetCreateProvisioningPackage is a + /// package used for the next step. + /// + /// + /// + /// + /// NetRequestProvisioningPackageInstall, an image initialization function, is called to inject the output from the + /// NetCreateProvisioningPackage provisioning function into a Windows operating system image for use during pre-installation + /// and post-installation. + /// + /// + /// + /// Changes to Windows initialization code will detect this saved state and affect the local-only portion of domain join. + /// + /// When the pPackageBinData and pdwPackageBinDataSize out pointers are used, set the pPackageTextData out pointer to NULL. When + /// pPackageTextData is used, set the pPackageBinData and pdwPackageBinDataSize out pointers to NULL. + /// + /// + /// The pProvisioningParams parameter specifies data to include in the provisioning package. The package includes information + /// relevant to the domain join, and it can also include information about policies and certificates to install on the machine. The + /// provisioning package can be used in four ways: + /// + /// + /// + /// Domain join + /// + /// + /// Domain join and installation of certificates + /// + /// + /// Domain join and installation of policies + /// + /// + /// Domain join and installation of certificates and policies + /// + /// + /// + /// The NetCreateProvisioningPackage function creates or reuses the machine account in the domain, collects all necessary + /// metadata and returns it in a package. The package can be consumed by the offline domain join request operation supplying all the + /// necessary input to complete the domain join during first boot without any network operations (local state updates only). + /// + /// + /// Security Note: The package returned by the NetCreateProvisioningPackage function contains very sensitive data. It + /// should be treated just as securely as a plaintext password. The package contains the machine account password and other + /// information about the domain, including the domain name, the name of a domain controller, and the security ID (SID) of the + /// domain. If the package is being transported physically or over the network, care must be taken to transport it securely. The + /// design makes no provisions for securing this data. This problem exists today with unattended setup answer files which can carry a + /// number of secrets including domain user passwords. The caller must secure the package. Solutions to this problem are varied. As + /// an example, a pre-exchanged key could be used to encrypt a session between the consumer and provisioning entity enabling a secure + /// transfer of the package. + /// + /// + /// The package returned in the pPackageBinData parameter by the NetCreateProvisioningPackage function is versioned to allow + /// interoperability and serviceability scenarios between different versions of Windows (such as joining a client, provisioning a + /// machine, and using a domain controller). A package created on Windows 8 or Windows Server 2012 can be used Windows 7 or Windows + /// Server 2008 R2, however only domain join information will take effect (certificates and policies are not supported). The offline + /// join scenario currently does not limit the lifetime of the package returned by the NetCreateProvisioningPackage function. + /// + /// + /// For offline domain joins, the access check performed depends on the configuration of the domain. Computer account creation is + /// enabled using three methods: + /// + /// + /// + /// Domain administrators have rights to create computer accounts. + /// + /// + /// The SD on a container can delegate the rights to create computer accounts. + /// + /// + /// + /// By default, authenticated users may create computer accounts by privilege. Authenticated users are limited to creating a limited + /// number of accounts that is specified as a quota on the domain (the default value is 10). For more information, see the + /// ms-DS-MachineAccountQuota attribute in the Active Directory schema. + /// + /// + /// + /// + /// The NetCreateProvisioningPackage function works only with a writable domain controller and does not function against a + /// read-only domain controller. Once provisioning is done against a writable domain controller and the account is replicated to a + /// read-only domain controller, the other portions of the offline domain join operation do not require access to a domain controller. + /// + /// + /// If the NetCreateProvisioningPackage function is successful, the pointer in the pPackageBinData or pPackageTextData + /// parameter (depending on which parameter was not NULL) is returned with the serialized data for use in an offline join + /// operation or as text in an unattended setup file. + /// + /// + /// All phases of the provisioning process append to a NetSetup.log file on the local computer. The provisoning process can include + /// up to three different computers: the computer where the provisioning package is created, the computer that requests the + /// installation of the package, and the computer where the package is installed. There will be NetSetup.log file information stored + /// on all three computers according to the operation performed. Reviewing the contents of these files is the most common means of + /// troubleshooting online and offline provisioning errors. Provisioning operations undertaken by admins are logged to the + /// NetSetup.log file in the %WINDIR%\Debug. Provisioning operations performed by non-admins are logged to the NetSetup.log file in + /// the %USERPROFILE%\Debug folder. + /// + /// For more information on offline domain join operations, see the Offline Domain Join Step-by-Step Guide. + /// + /// Joining (and unjoining) a computer to a domain using NetJoinDomain and NetUnjoinDomain is performed only by a member of the + /// Administrators local group on the target computer. Note that the domain administrator can set additional requirements for joining + /// the domain using delegation and assignment of privileges. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmjoin/nf-lmjoin-netcreateprovisioningpackage NET_API_STATUS NET_API_FUNCTION + // NetCreateProvisioningPackage( PNETSETUP_PROVISIONING_PARAMS pProvisioningParams, PBYTE *ppPackageBinData, DWORD + // *pdwPackageBinDataSize, LPWSTR *ppPackageTextData ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] + [PInvokeData("lmjoin.h", MSDNShortId = "6E2A5578-8308-41E2-B5E9-5E34E9E76C0B")] + public static extern Win32Error NetCreateProvisioningPackage(ref NETSETUP_PROVISIONING_PARAMS pProvisioningParams, [Optional] IntPtr ppPackageBinData, + [Optional] IntPtr pdwPackageBinDataSize, ref StringBuilder ppPackageTextData); + + /// The NetEnumerateComputerNames function enumerates names for the specified computer. + /// + /// A pointer to a constant string that specifies the name of the computer on which to execute this function. If this parameter is + /// NULL, the local computer is used. + /// + /// + /// + /// The type of the name queried. This member can be one of the following values defined in the NET_COMPUTER_NAME_TYPE + /// enumeration defined in the Lmjoin.h header file. + /// + /// + /// + /// Value + /// Meaning + /// + /// + /// NetPrimaryComputerName + /// The primary computer name. + /// + /// + /// NetAlternateComputerNames + /// Alternate computer names. + /// + /// + /// NetAllComputerNames + /// All computer names. + /// + /// + /// NetComputerNameTypeMax + /// Indicates the end of the range that specifies the possible values for the type of name to be queried. + /// + /// + /// + /// Reserved for future use. This parameter should be NULL. + /// + /// A pointer to a DWORD value that returns the number of names returned in the buffer pointed to by the ComputerNames parameter if + /// the function succeeds. + /// + /// + /// + /// A pointer to an array of pointers to names. If the function call is successful, this parameter will return the computer names + /// that match the computer type name specified in the NameType parameter. + /// + /// When the application no longer needs this array, this buffer should be freed by calling NetApiBufferFree function. + /// + /// + /// If the function succeeds, the return value is NERR_Success. + /// 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 + /// + /// Access is denied. This error is returned if the caller was not a member of the Administrators local group on the target computer. + /// + /// + /// + /// ERROR_INVALID_PARAMETER + /// A parameter is incorrect. + /// + /// + /// ERROR_NOT_ENOUGH_MEMORY + /// Not enough memory is available to process this command. + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The request is not supported. This error is returned if the target computer specified in the Server parameter on which this + /// function executes is running on Windows 2000 and earlier. + /// + /// + /// + /// NERR_WkstaNotStarted + /// The Workstation service has not been started. + /// + /// + /// RPC_S_CALL_IN_PROGRESS + /// A remote procedure call is already in progress for this thread. + /// + /// + /// RPC_S_PROTSEQ_NOT_SUPPORTED + /// The remote procedure call protocol sequence is not supported. + /// + /// + /// + /// + /// The NetEnumerateComputerNames function is supported on Windows Vista and later. + /// The NetEnumerateComputerNames function is used to request the names a computer currently has configured. + /// + /// The NetEnumerateComputerNames function requires that the caller is a member of the Administrators local group on the + /// target computer. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmjoin/nf-lmjoin-netenumeratecomputernames NET_API_STATUS NET_API_FUNCTION + // NetEnumerateComputerNames( LPCWSTR Server, NET_COMPUTER_NAME_TYPE NameType, ULONG Reserved, PDWORD EntryCount, LPWSTR + // **ComputerNames ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] + [PInvokeData("lmjoin.h", MSDNShortId = "c657ae33-404e-4c36-a956-5fbcfa540be7")] + public static extern Win32Error NetEnumerateComputerNames(string Server, NET_COMPUTER_NAME_TYPE NameType, [Optional] uint Reserved, + out uint EntryCount, out SafeNetApiBuffer ComputerNames); + + /// + /// Frees the memory allocated for the specified DSREG_JOIN_INFO structure, which contains join information for a tenant and which + /// you retrieved by calling the NetGetAadJoinInformation function. + /// + /// Pointer to the DSREG_JOIN_INFO structure for which you want to free the memory. + // https://docs.microsoft.com/en-us/windows/desktop/api/lmjoin/nf-lmjoin-netfreeaadjoininformation VOID NET_API_FUNCTION + // NetFreeAadJoinInformation( PDSREG_JOIN_INFO pJoinInfo ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("lmjoin.h", MSDNShortId = "BDFB6179-4B8C-43E3-8D34-A2B470EA0D0B")] + public static extern void NetFreeAadJoinInformation(HANDLE pJoinInfo); + + /// + /// Retrieves the join information for the specified tenant. This function examines the join information for Microsoft Azure Active + /// Directory and the work account that the current user added. + /// + /// + /// + /// The tenant identifier for the joined account. If the device is not joined to Azure Active Directory (Azure AD), and the user + /// currently logged into Windows added no Azure AD work accounts for the specified tenant, the buffer that the ppJoinInfo parameter + /// points to is set to NULL. + /// + /// + /// If the specified tenant ID is NULL or empty, ppJoinInfo is set to the default join account information, or NULL if the device is + /// not joined to Azure AD and the current user added no Azure AD work accounts. + /// + /// + /// + /// The join information for the tenant that the pcszTenantId parameter specifies. If this parameter is NULL, the device is not + /// joined to Azure AD and the current user added no Azure AD work accounts. You must call the NetFreeAadJoinInformation function to + /// free the memory allocated for this structure. + /// + /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. + // https://docs.microsoft.com/en-us/windows/desktop/api/lmjoin/nf-lmjoin-netgetaadjoininformation HRESULT NET_API_FUNCTION + // NetGetAadJoinInformation( LPCWSTR pcszTenantId, PDSREG_JOIN_INFO *ppJoinInfo ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("lmjoin.h", MSDNShortId = "C63B3AA7-FC7E-4CB9-9318-BD25560591AB")] + public static extern HRESULT NetGetAadJoinInformation([MarshalAs(UnmanagedType.LPWStr), Optional] string pcszTenantId, out DSREG_JOIN_INFO ppJoinInfo); + + /// + /// The NetGetJoinableOUs function retrieves a list of organizational units (OUs) in which a computer account can be created. + /// + /// Pointer to a constant string that specifies the DNS or NetBIOS name of the computer on which to call the function. If this + /// parameter is NULL, the local computer is used. + /// Pointer to a constant string that specifies the name of the domain for which to retrieve the list of OUs that can be joined. + /// Pointer to a constant string that specifies the account name to use when connecting to the domain controller. The string must + /// specify either a domain NetBIOS name and user account (for example, "REDMOND\user") or the user principal name (UPN) of the user + /// in the form of an Internet-style login name (for example, "someone@example.com"). If this parameter is NULL, the caller's + /// context is used. + /// If the lpAccount parameter specifies an account name, this parameter must point to the password to use when connecting to the + /// domain controller. Otherwise, this parameter must be NULL. + /// Receives the count of OUs returned in the list of joinable OUs. + /// Pointer to an array that receives the list of joinable OUs. This array is allocated by the system and must be freed using a + /// single call to the NetApiBufferFree function. For more information, see Network Management Function Buffers and Network + /// Management Function Buffer Lengths. + /// + /// If the function succeeds, the return value is NERR_Success. + /// 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_NOT_ENOUGH_MEMORY + /// Not enough storage is available to process this command. + /// + /// + /// NERR_DefaultJoinRequired + /// The destination domain controller does not support creating computer accounts in OUs. + /// + /// + /// + /// + /// No special group membership is required to successfully execute the NetGetJoinableOUs function. + /// For more information about organizational units, see Managing Users in the Active Directory documentation. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmjoin/nf-lmjoin-netgetjoinableous NET_API_STATUS NET_API_FUNCTION + // NetGetJoinableOUs( LPCWSTR lpServer, LPCWSTR lpDomain, LPCWSTR lpAccount, LPCWSTR lpPassword, DWORD *OUCount, LPWSTR **OUs ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] + [PInvokeData("lmjoin.h", MSDNShortId = "1faa912b-c56d-431c-95d5-d36790b0d467")] + public static extern Win32Error NetGetJoinableOUs([Optional] string lpServer, string lpDomain, [Optional] string lpAccount, [Optional] string lpPassword, out uint OUCount, + out SafeNetApiBuffer OUs); + + /// The NetGetJoinInformation function retrieves join status information for the specified computer. + /// + /// Pointer to a constant string that specifies the DNS or NetBIOS name of the computer on which to call the function. If this + /// parameter is NULL, the local computer is used. + /// + /// + /// Pointer to the buffer that receives the NetBIOS name of the domain or workgroup to which the computer is joined. This buffer is + /// allocated by the system and must be freed using the NetApiBufferFree function. For more information, see Network Management + /// Function Buffers and Network Management Function Buffer Lengths. + /// + /// Receives the join status of the specified computer. This parameter can have one of the following values. + /// + /// If the function succeeds, the return value is NERR_Success. + /// If the function fails, the return value can be the following error code or one of the system error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_NOT_ENOUGH_MEMORY + /// Not enough storage is available to process this command. + /// + /// + /// + /// No special group membership is required to successfully execute the NetGetJoinInformation function. + // https://docs.microsoft.com/en-us/windows/desktop/api/lmjoin/nf-lmjoin-netgetjoininformation NET_API_STATUS NET_API_FUNCTION + // NetGetJoinInformation( LPCWSTR lpServer, LPWSTR *lpNameBuffer, PNETSETUP_JOIN_STATUS BufferType ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] + [PInvokeData("lmjoin.h", MSDNShortId = "c7cc1cf2-4530-4039-806b-fbee572f564d")] + public static extern Win32Error NetGetJoinInformation([Optional] string lpServer, + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(NetApiBufferUnicodeStringMarshaler))] out string lpNameBuffer, out NETSETUP_JOIN_STATUS BufferType); + + /// The NetJoinDomain function joins a computer to a workgroup or domain. + /// + /// A pointer to a constant string that specifies the DNS or NetBIOS name of the computer on which to execute the domain join + /// operation. If this parameter is NULL, the local computer is used. + /// + /// + /// A pointer to a constant null-terminated character string that specifies the name of the domain or workgroup to join. + /// + /// Optionally, you can specify the preferred domain controller to perform the join operation. In this instance, the string must be + /// of the form DomainName\MachineName, where DomainName is the name of the domain to join, and MachineName is the name of the domain + /// controller to perform the join. + /// + /// + /// + /// Optionally specifies the pointer to a constant null-terminated character string that contains the RFC 1779 format name of the + /// organizational unit (OU) for the computer account. If you specify this parameter, the string must contain a full path, for + /// example, OU=testOU,DC=domain,DC=Domain,DC=com. Otherwise, this parameter must be NULL. + /// + /// + /// A pointer to a constant null-terminated character string that specifies the account name to use when connecting to the domain + /// controller. The string must specify either a domain NetBIOS name and user account (for example, REDMOND\user) or the user + /// principal name (UPN) of the user in the form of an Internet-style login name (for example, "someone@example.com"). If this + /// parameter is NULL, the caller's context is used. + /// + /// + /// + /// If the lpAccount parameter specifies an account name, this parameter must point to the password to use when connecting to the + /// domain controller. Otherwise, this parameter must be NULL. + /// + /// + /// You can specify a local machine account password rather than a user password for unsecured joins. For more information, see the + /// description of the NETSETUP_MACHINE_PWD_PASSED flag described in the fJoinOptions parameter. + /// + /// + /// + /// + /// A set of bit flags defining the join options. This parameter can be one or more of the following values defined in the Lmjoin.h + /// header file. + /// + /// + /// + /// Value + /// Meaning + /// + /// + /// NETSETUP_JOIN_DOMAIN 0x00000001 + /// Joins the computer to a domain. If this value is not specified, joins the computer to a workgroup. + /// + /// + /// NETSETUP_ACCT_CREATE 0x00000002 + /// Creates the account on the domain. + /// + /// + /// NETSETUP_WIN9X_UPGRADE 0x00000010 + /// The join operation is occurring as part of an upgrade. + /// + /// + /// NETSETUP_DOMAIN_JOIN_IF_JOINED 0x00000020 + /// Allows a join to a new domain even if the computer is already joined to a domain. + /// + /// + /// NETSETUP_JOIN_UNSECURE 0x00000040 + /// + /// Performs an unsecured join. This option requests a domain join to a pre-created account without authenticating with domain user + /// credentials. This option can be used in conjunction with NETSETUP_MACHINE_PWD_PASSED option. In this case, lpPassword is the + /// password of the pre-created machine account. Prior to Windows Vista with SP1 and Windows Server 2008, an unsecure join did not + /// authenticate to the domain controller. All communication was performed using a null (unauthenticated) session. Starting with + /// Windows Vista with SP1 and Windows Server 2008, the machine account name and password are used to authenticate to the domain controller. + /// + /// + /// + /// NETSETUP_MACHINE_PWD_PASSED 0x00000080 + /// + /// Indicates that the lpPassword parameter specifies a local machine account password rather than a user password. This flag is + /// valid only for unsecured joins, which you must indicate by also setting the NETSETUP_JOIN_UNSECURE flag. If you set this flag, + /// then after the join operation succeeds, the machine password will be set to the value of lpPassword, if that value is a valid + /// machine password. + /// + /// + /// + /// NETSETUP_DEFER_SPN_SET 0x00000100 + /// + /// Indicates that the service principal name (SPN) and the DnsHostName properties on the computer object should not be updated at + /// this time. Typically, these properties are updated during the join operation. Instead, these properties should be updated during + /// a subsequent call to the NetRenameMachineInDomain function. These properties are always updated during the rename operation. For + /// more information, see the following Remarks section. + /// + /// + /// + /// NETSETUP_JOIN_DC_ACCOUNT 0x00000200 + /// Allow the domain join if existing account is a domain controller. + /// + /// + /// NETSETUP_JOIN_WITH_NEW_NAME 0x00000400 + /// + /// Join the target machine specified in lpServer parameter with a new name queried from the registry on the machine specified in the + /// lpServer parameter. This option is used if SetComputerNameEx has been called prior to rebooting the machine. The new computer + /// name will not take effect until a reboot. With this option, the caller instructs the NetJoinDomain function to use the new name + /// during the domain join operation. A reboot is required after calling NetJoinDomain successfully at which time both the computer + /// name change and domain membership change will have taken affect. + /// + /// + /// + /// NETSETUP_JOIN_READONLY 0x00000800 + /// + /// Join the target machine specified in lpServer parameter using a pre-created account without requiring a writable domain + /// controller. This option provides the ability to join a machine to domain if an account has already been provisioned and + /// replicated to a read-only domain controller. The target read-only domain controller is specified as part of the lpDomain + /// parameter, after the domain name delimited by a ‘\’ character. This provisioning must include the machine secret. The machine + /// account must be added via group membership into the allowed list for password replication policy, and the account password must + /// be replicated to the read-only domain controller prior to the join operation. For more information, see the information on + /// Password Replication Policy Administration. Starting with Windows 7, an alternate mechanism is to use the offline domain join + /// mechanism. For more information, see the NetProvisionComputerAccount and NetRequestOfflineDomainJoin functions. + /// + /// + /// + /// NETSETUP_AMBIGUOUS_DC 0x00001000 + /// When joining the domain don't try to set the preferred domain controller in the registry. + /// + /// + /// NETSETUP_NO_NETLOGON_CACHE 0x00002000 + /// When joining the domain don't create the Netlogon cache. + /// + /// + /// NETSETUP_DONT_CONTROL_SERVICES 0x00004000 + /// When joining the domain don't force Netlogon service to start. + /// + /// + /// NETSETUP_SET_MACHINE_NAME 0x00008000 + /// When joining the domain for offline join only, set target machine hostname and NetBIOS name. + /// + /// + /// NETSETUP_FORCE_SPN_SET 0x00010000 + /// When joining the domain, override other settings during domain join and set the service principal name (SPN). + /// + /// + /// NETSETUP_NO_ACCT_REUSE 0x00020000 + /// When joining the domain, do not reuse an existing account. + /// + /// + /// NETSETUP_IGNORE_UNSUPPORTED_FLAGS 0x10000000 + /// + /// If this bit is set, unrecognized flags will be ignored by the NetJoinDomain function and NetJoinDomain will behave as if the + /// flags were not set. + /// + /// + /// + /// + /// + /// If the function succeeds, the return value is NERR_Success. + /// 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 + /// + /// Access is denied. This error is returned if the caller was not a member of the Administrators local group on the target computer. + /// + /// + /// + /// ERROR_INVALID_PARAMETER + /// A parameter is incorrect. This error is returned if the lpDomain parameter is NULL. + /// + /// + /// ERROR_NO_SUCH_DOMAIN + /// The specified domain did not exist. + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The request is not supported. This error is returned if the computer specified in the lpServer parameter does not support some of + /// the options passed in the fJoinOptions parameter. + /// + /// + /// + /// NERR_InvalidWorkgroupName + /// The specified workgroup name is not valid. + /// + /// + /// NERR_SetupAlreadyJoined + /// The computer is already joined to a domain. + /// + /// + /// NERR_WkstaNotStarted + /// The Workstation service has not been started. + /// + /// + /// RPC_S_CALL_IN_PROGRESS + /// A remote procedure call is already in progress for this thread. + /// + /// + /// RPC_S_PROTSEQ_NOT_SUPPORTED + /// The remote procedure call protocol sequence is not supported. + /// + /// + /// + /// + /// + /// Joining (and unjoining) a computer to a domain or workgroup can be performed only by a member of the Administrators local group + /// on the target computer. Note that the domain administrator can set additional requirements for joining the domain using + /// delegation and assignment of privileges. + /// + /// + /// If you call the NetJoinDomain function remotely, you must supply credentials because you cannot delegate credentials under + /// these circumstances. + /// + /// + /// Different processes, or different threads of the same process, should not call the NetJoinDomain function at the same + /// time. This situation can leave the computer in an inconsistent state. + /// + /// + /// If you encounter a problem during a join operation, you should not delete a computer account and immediately follow the deletion + /// with another join attempt. This can lead to replication-related problems that are difficult to investigate. When you delete a + /// computer account, wait until the change has replicated to all domain controllers before attempting another join operation. + /// + /// A system reboot is required after calling the NetJoinDomain function for the operation to complete. + /// + /// Windows Server 2003 and Windows XP: When a call to the NetJoinDomain function precedes a call to the + /// NetRenameMachineInDomain function, you should defer the update of the SPN and DnsHostName properties on the computer object until + /// the rename operation. This is because the join operation can fail in certain situations. An example of such a situation is when + /// the SPN that is derived from the current computer name is not valid in the new domain that the computer is joining, but the SPN + /// derived from the new name that the computer will have after the rename operation is valid in the new domain. In this situation, + /// the call to NetJoinDomain fails unless you defer the update of the two properties until the rename operation by specifying + /// the NETSETUP_DEFER_SPN_SET flag in the fJoinOptions parameter when you call NetJoinDomain. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmjoin/nf-lmjoin-netjoindomain NET_API_STATUS NET_API_FUNCTION NetJoinDomain( + // LPCWSTR lpServer, LPCWSTR lpDomain, LPCWSTR lpMachineAccountOU, LPCWSTR lpAccount, LPCWSTR lpPassword, DWORD fJoinOptions ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] + [PInvokeData("lmjoin.h", MSDNShortId = "4efcb399-03af-4312-9f1d-6bc38f356cac")] + public static extern Win32Error NetJoinDomain([Optional] string lpServer, string lpDomain, [Optional] string lpMachineAccountOU, [Optional] string lpAccount, [Optional] string lpPassword, NETSETUP fJoinOptions); + + /// + /// The NetProvisionComputerAccount function provisions a computer account for later use in an offline domain join operation. + /// + /// + /// A pointer to a NULL-terminated character string that specifies the name of the domain where the computer account is created. + /// + /// + /// A pointer to a NULL-terminated character string that specifies the short name of the machine from which the computer + /// account attribute sAMAccountName is derived by appending a '$'. This parameter must contain a valid DNS or NetBIOS machine name. + /// + /// + /// + /// An optional pointer to a NULL-terminated character string that contains the RFC 1779 format name of the organizational + /// unit (OU) where the computer account will be created. If you specify this parameter, the string must contain a full path, for + /// example, OU=testOU,DC=domain,DC=Domain,DC=com. Otherwise, this parameter must be NULL. + /// + /// If this parameter is NULL, the well known computer object container will be used as published in the domain. + /// + /// + /// An optional pointer to a NULL-terminated character string that contains the name of the domain controller to target. + /// + /// + /// + /// A set of bit flags that define provisioning options. This parameter can be one or more of the following values defined in the + /// Lmjoin.h header file. + /// + /// + /// + /// Value + /// Meaning + /// + /// + /// NETSETUP_PROVISION_DOWNLEVEL_PRIV_SUPPORT 0x00000001 + /// + /// If the caller requires account creation by privilege, this option will cause a retry on failure using account creation functions + /// enabling interoperability with domain controllers running on earlier versions of Windows. The lpMachineAccountOU is not supported + /// when using downlevel privilege support. + /// + /// + /// + /// NETSETUP_PROVISION_REUSE_ACCOUNT 0x00000002 + /// + /// If the named account already exists, an attempt will be made to reuse the existing account. This option requires sufficient + /// credentials for this operation (Domain Administrator or the object owner). + /// + /// + /// + /// NETSETUP_PROVISION_USE_DEFAULT_PASSWORD 0x00000004 + /// + /// Use the default machine account password which is the machine name in lowercase. This is largely to support the older unsecure + /// join model where the pre-created account typically used this default password. + /// + /// + /// + /// NETSETUP_PROVISION_SKIP_ACCOUNT_SEARCH 0x00000008 + /// + /// Do not try to find the account on any domain controller in the domain. This option makes the operation faster, but should only be + /// used when the caller is certain that an account by the same name hasn't recently been created. This option is only valid when the + /// lpDcName parameter is specified. When the prerequisites are met, this option allows for must faster provisioning useful for + /// scenarios such as batch processing. + /// + /// + /// + /// NETSETUP_PROVISION_ROOT_CA_CERTS 0x00000010 + /// + /// This option retrieves all of the root Certificate Authority certificates on the local machine and adds them to the provisioning + /// package when no certificate template names are provided as part of the provisioning package (the aCertTemplateNames member of the + /// NETSETUP_PROVISIONING_PARAMS struct passed in the pProvisioningParams parameter to the NetCreateProvisioningPackage function is NULL). + /// + /// + /// + /// + /// + /// + /// An optional pointer that will receive the opaque binary blob of serialized metadata required by NetRequestOfflineDomainJoin + /// function to complete an offline domain join, if the NetProvisionComputerAccount function completes successfully. The data + /// is returned as an opaque binary buffer which may be passed to NetRequestOfflineDomainJoin function. + /// + /// + /// If this parameter is NULL, then pProvisionTextData parameter must not be NULL. If this parameter is not + /// NULL, then the pProvisionTextData parameter must be NULL. + /// + /// + /// + /// A pointer to a value that receives the size, in bytes, of the buffer returned in the pProvisionBinData parameter. + /// + /// This parameter must not be NULL if the pProvisionBinData parameter is not NULL. This parameter must be NULL + /// when the pProvisionBinData parameter is NULL. + /// + /// + /// + /// + /// An optional pointer that will receive the opaque binary blob of serialized metadata required by NetRequestOfflineDomainJoin + /// function to complete an offline domain join, if the NetProvisionComputerAccount function completes successfully. The data + /// is returned in string form for embedding in an unattended setup answer file. + /// + /// + /// If this parameter is NULL, then the pProvisionBinData parameter must not be NULL. If this parameter is not + /// NULL, then the the pProvisionBinData parameter must be NULL. + /// + /// + /// + /// If the function succeeds, the return value is NERR_Success. + /// 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 + /// Access is denied. This error is returned if the caller does not have sufficient privileges to complete the operation. + /// + /// + /// ERROR_INVALID_DOMAIN_ROLE + /// + /// This operation is only allowed for the Primary Domain Controller of the domain. This error is returned if a domain controller + /// name was specified in the lpDcName parameter, but the computer specified could not be validated as a domain controller for the + /// target domain specified in the lpDomain parameter. + /// + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// A parameter is incorrect. This error is returned if the lpDomain or lpMachineName parameter is NULL. This error is also returned + /// if both the pProvisionBinData and pProvisionTextData parameters are NULL. + /// + /// + /// + /// ERROR_NO_SUCH_DOMAIN + /// The specified domain did not exist. + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The request is not supported. This error is returned if the lpMachineAccountOU parameter was specified and the domain controller + /// is running on an earlier versions of Windows that does not support this parameter. + /// + /// + /// + /// NERR_DS8DCRequired + /// The specified domain controller does not meet the version requirement for this operation. + /// + /// + /// NERR_LDAPCapableDCRequired + /// This operation requires a domain controller which supports LDAP. + /// + /// + /// NERR_UserExists + /// + /// The account already exists in the domain and the NETSETUP_PROVISION_REUSE_ACCOUNT bit was not specified in the dwOptions parameter. + /// + /// + /// + /// NERR_WkstaNotStarted + /// The Workstation service has not been started. + /// + /// + /// RPC_S_CALL_IN_PROGRESS + /// A remote procedure call is already in progress for this thread. + /// + /// + /// RPC_S_PROTSEQ_NOT_SUPPORTED + /// The remote procedure call protocol sequence is not supported. + /// + /// + /// + /// + /// + /// The NetProvisionComputerAccount function is supported on Windows 7 and Windows Server 2008 R2 for offline join operations. + /// On Windows 8 or Windows Server 2008 R2, it is recommended that the NetCreateProvisioningPackage function be used instead of the + /// NetProvisionComputerAccount function. + /// + /// + /// The NetProvisionComputerAccount function is used to provision a computer account for later use in an offline domain join + /// operation using the NetRequestOfflineDomainJoin function. The offline domain join scenario uses these functions as follows: + /// + /// + /// + /// + /// NetProvisionComputerAccount is a provisioning function that is first called to perform the network operations necessary to + /// create and configure the computer object in Active Directory. The output from the NetProvisionComputerAccount is an opaque + /// binary blob of serialized metadata used for the next step. + /// + /// + /// + /// + /// NetRequestOfflineDomainJoin, an image initialization function, is then called to inject the output from the + /// NetProvisionComputerAccount provisioning function into a Windows operating system image to be used during installation. + /// + /// + /// + /// Changes to Windows initialization code will detect this saved state and affect the local only portion of domain join. + /// + /// The NetProvisionComputerAccount function will create or reuse the machine account in the domain, collect all necessary + /// metadata and return it in an opaque versioned binary blob or as text for embedding in an unattended setup answer file. The opaque + /// binary blob can be consumed by the offline domain join request operation supplying all the necessary input to complete the domain + /// join during first boot without any network operations (local state updates only). + /// + /// + /// Security Note: The blob returned by the NetProvisionComputerAccount function contains very sensitive data. It + /// should be treated just as securely as a plaintext password. The blob contains the machine account password and other information + /// about the domain, including the domain name, the name of a domain controller, and the security ID (SID) of the domain. If the + /// blob is being transported physically or over the network, care must be taken to transport it securely. The design makes no + /// provisions for securing this data. This problem exists today with unattended setup answer files which can carry a number of + /// secrets including domain user passwords. The caller must secure the blob and the unattended setup files. Solutions to this + /// problem are varied. As an example, a pre-exchanged key could be used to encrypt a session between the consumer and provisioning + /// entity enabling a secure transfer of the opaque blob. + /// + /// + /// The opaque blob returned in the pProvisionBinData parameter by the NetProvisionComputerAccount function is versioned to + /// allow interoperability and serviceability scenarios between different versions of Windows (joining client, provisioning machine, + /// and domain controller). The offline join scenario currently does not limit the lifetime of the blob returned by the + /// NetProvisionComputerAccount function. + /// + /// + /// For offline domain joins, the access check performed depends on the configuration of the domain. Computer account creation is + /// enabled using three methods: + /// + /// + /// + /// Domain administrators have rights to create computer accounts. + /// + /// + /// The SD on a container can delegate the rights to create computer accounts. + /// + /// + /// + /// By default, authenticated users may create computer accounts by privilege. Authenticated users are limited to creating a limited + /// number of accounts that is specified as a quota on the domain (the default value is 10). For more information, see the + /// ms-DS-MachineAccountQuota attribute in the Active Directory schema. + /// + /// + /// + /// + /// The NetProvisionComputerAccount function works only with a writable domain controller and does not function against a + /// read-only domain controller. Once provisioning is done against a writable domain controller and the account is replicated to a + /// read-only domain controller, then the other portions of offline domain join operation do not require access to a domain controller. + /// + /// + /// If the NetProvisionComputerAccount function is successful, the pointer in the pProvisionBinData or pProvisionTextData + /// parameter (depending on which was parameter was not NULL) is returned with the serialized data for use in an offline join + /// operation or as text in an unattended setup file. + /// + /// For more information on offline domain join operations, see the Offline Domain Join Step-by-Step Guide. + /// + /// Joining (and unjoining) a computer to a domain using NetJoinDomain and NetUnjoinDomain can be performed only by a member of the + /// Administrators local group on the target computer. Note that the domain administrator can set additional requirements for joining + /// the domain using delegation and assignment of privileges. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmjoin/nf-lmjoin-netprovisioncomputeraccount NET_API_STATUS NET_API_FUNCTION + // NetProvisionComputerAccount( LPCWSTR lpDomain, LPCWSTR lpMachineName, LPCWSTR lpMachineAccountOU, LPCWSTR lpDcName, DWORD + // dwOptions, PBYTE *pProvisionBinData, DWORD *pdwProvisionBinDataSize, LPWSTR *pProvisionTextData ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] + [PInvokeData("lmjoin.h", MSDNShortId = "4c854258-b84d-4ef3-a6da-ce0a9540ffd5")] + public static extern Win32Error NetProvisionComputerAccount(string lpDomain, string lpMachineName, [Optional] string lpMachineAccountOU, string lpDcName, NETSETUP_PROVISION dwOptions, + out IntPtr pProvisionBinData, out uint pdwProvisionBinDataSize, [Optional] IntPtr pProvisionTextData); + + /// + /// The NetProvisionComputerAccount function provisions a computer account for later use in an offline domain join operation. + /// + /// + /// A pointer to a NULL-terminated character string that specifies the name of the domain where the computer account is created. + /// + /// + /// A pointer to a NULL-terminated character string that specifies the short name of the machine from which the computer + /// account attribute sAMAccountName is derived by appending a '$'. This parameter must contain a valid DNS or NetBIOS machine name. + /// + /// + /// + /// An optional pointer to a NULL-terminated character string that contains the RFC 1779 format name of the organizational + /// unit (OU) where the computer account will be created. If you specify this parameter, the string must contain a full path, for + /// example, OU=testOU,DC=domain,DC=Domain,DC=com. Otherwise, this parameter must be NULL. + /// + /// If this parameter is NULL, the well known computer object container will be used as published in the domain. + /// + /// + /// An optional pointer to a NULL-terminated character string that contains the name of the domain controller to target. + /// + /// + /// + /// A set of bit flags that define provisioning options. This parameter can be one or more of the following values defined in the + /// Lmjoin.h header file. + /// + /// + /// + /// Value + /// Meaning + /// + /// + /// NETSETUP_PROVISION_DOWNLEVEL_PRIV_SUPPORT 0x00000001 + /// + /// If the caller requires account creation by privilege, this option will cause a retry on failure using account creation functions + /// enabling interoperability with domain controllers running on earlier versions of Windows. The lpMachineAccountOU is not supported + /// when using downlevel privilege support. + /// + /// + /// + /// NETSETUP_PROVISION_REUSE_ACCOUNT 0x00000002 + /// + /// If the named account already exists, an attempt will be made to reuse the existing account. This option requires sufficient + /// credentials for this operation (Domain Administrator or the object owner). + /// + /// + /// + /// NETSETUP_PROVISION_USE_DEFAULT_PASSWORD 0x00000004 + /// + /// Use the default machine account password which is the machine name in lowercase. This is largely to support the older unsecure + /// join model where the pre-created account typically used this default password. + /// + /// + /// + /// NETSETUP_PROVISION_SKIP_ACCOUNT_SEARCH 0x00000008 + /// + /// Do not try to find the account on any domain controller in the domain. This option makes the operation faster, but should only be + /// used when the caller is certain that an account by the same name hasn't recently been created. This option is only valid when the + /// lpDcName parameter is specified. When the prerequisites are met, this option allows for must faster provisioning useful for + /// scenarios such as batch processing. + /// + /// + /// + /// NETSETUP_PROVISION_ROOT_CA_CERTS 0x00000010 + /// + /// This option retrieves all of the root Certificate Authority certificates on the local machine and adds them to the provisioning + /// package when no certificate template names are provided as part of the provisioning package (the aCertTemplateNames member of the + /// NETSETUP_PROVISIONING_PARAMS struct passed in the pProvisioningParams parameter to the NetCreateProvisioningPackage function is NULL). + /// + /// + /// + /// + /// + /// + /// An optional pointer that will receive the opaque binary blob of serialized metadata required by NetRequestOfflineDomainJoin + /// function to complete an offline domain join, if the NetProvisionComputerAccount function completes successfully. The data + /// is returned as an opaque binary buffer which may be passed to NetRequestOfflineDomainJoin function. + /// + /// + /// If this parameter is NULL, then pProvisionTextData parameter must not be NULL. If this parameter is not + /// NULL, then the pProvisionTextData parameter must be NULL. + /// + /// + /// + /// A pointer to a value that receives the size, in bytes, of the buffer returned in the pProvisionBinData parameter. + /// + /// This parameter must not be NULL if the pProvisionBinData parameter is not NULL. This parameter must be NULL + /// when the pProvisionBinData parameter is NULL. + /// + /// + /// + /// + /// An optional pointer that will receive the opaque binary blob of serialized metadata required by NetRequestOfflineDomainJoin + /// function to complete an offline domain join, if the NetProvisionComputerAccount function completes successfully. The data + /// is returned in string form for embedding in an unattended setup answer file. + /// + /// + /// If this parameter is NULL, then the pProvisionBinData parameter must not be NULL. If this parameter is not + /// NULL, then the the pProvisionBinData parameter must be NULL. + /// + /// + /// + /// If the function succeeds, the return value is NERR_Success. + /// 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 + /// Access is denied. This error is returned if the caller does not have sufficient privileges to complete the operation. + /// + /// + /// ERROR_INVALID_DOMAIN_ROLE + /// + /// This operation is only allowed for the Primary Domain Controller of the domain. This error is returned if a domain controller + /// name was specified in the lpDcName parameter, but the computer specified could not be validated as a domain controller for the + /// target domain specified in the lpDomain parameter. + /// + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// A parameter is incorrect. This error is returned if the lpDomain or lpMachineName parameter is NULL. This error is also returned + /// if both the pProvisionBinData and pProvisionTextData parameters are NULL. + /// + /// + /// + /// ERROR_NO_SUCH_DOMAIN + /// The specified domain did not exist. + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The request is not supported. This error is returned if the lpMachineAccountOU parameter was specified and the domain controller + /// is running on an earlier versions of Windows that does not support this parameter. + /// + /// + /// + /// NERR_DS8DCRequired + /// The specified domain controller does not meet the version requirement for this operation. + /// + /// + /// NERR_LDAPCapableDCRequired + /// This operation requires a domain controller which supports LDAP. + /// + /// + /// NERR_UserExists + /// + /// The account already exists in the domain and the NETSETUP_PROVISION_REUSE_ACCOUNT bit was not specified in the dwOptions parameter. + /// + /// + /// + /// NERR_WkstaNotStarted + /// The Workstation service has not been started. + /// + /// + /// RPC_S_CALL_IN_PROGRESS + /// A remote procedure call is already in progress for this thread. + /// + /// + /// RPC_S_PROTSEQ_NOT_SUPPORTED + /// The remote procedure call protocol sequence is not supported. + /// + /// + /// + /// + /// + /// The NetProvisionComputerAccount function is supported on Windows 7 and Windows Server 2008 R2 for offline join operations. + /// On Windows 8 or Windows Server 2008 R2, it is recommended that the NetCreateProvisioningPackage function be used instead of the + /// NetProvisionComputerAccount function. + /// + /// + /// The NetProvisionComputerAccount function is used to provision a computer account for later use in an offline domain join + /// operation using the NetRequestOfflineDomainJoin function. The offline domain join scenario uses these functions as follows: + /// + /// + /// + /// + /// NetProvisionComputerAccount is a provisioning function that is first called to perform the network operations necessary to + /// create and configure the computer object in Active Directory. The output from the NetProvisionComputerAccount is an opaque + /// binary blob of serialized metadata used for the next step. + /// + /// + /// + /// + /// NetRequestOfflineDomainJoin, an image initialization function, is then called to inject the output from the + /// NetProvisionComputerAccount provisioning function into a Windows operating system image to be used during installation. + /// + /// + /// + /// Changes to Windows initialization code will detect this saved state and affect the local only portion of domain join. + /// + /// The NetProvisionComputerAccount function will create or reuse the machine account in the domain, collect all necessary + /// metadata and return it in an opaque versioned binary blob or as text for embedding in an unattended setup answer file. The opaque + /// binary blob can be consumed by the offline domain join request operation supplying all the necessary input to complete the domain + /// join during first boot without any network operations (local state updates only). + /// + /// + /// Security Note: The blob returned by the NetProvisionComputerAccount function contains very sensitive data. It + /// should be treated just as securely as a plaintext password. The blob contains the machine account password and other information + /// about the domain, including the domain name, the name of a domain controller, and the security ID (SID) of the domain. If the + /// blob is being transported physically or over the network, care must be taken to transport it securely. The design makes no + /// provisions for securing this data. This problem exists today with unattended setup answer files which can carry a number of + /// secrets including domain user passwords. The caller must secure the blob and the unattended setup files. Solutions to this + /// problem are varied. As an example, a pre-exchanged key could be used to encrypt a session between the consumer and provisioning + /// entity enabling a secure transfer of the opaque blob. + /// + /// + /// The opaque blob returned in the pProvisionBinData parameter by the NetProvisionComputerAccount function is versioned to + /// allow interoperability and serviceability scenarios between different versions of Windows (joining client, provisioning machine, + /// and domain controller). The offline join scenario currently does not limit the lifetime of the blob returned by the + /// NetProvisionComputerAccount function. + /// + /// + /// For offline domain joins, the access check performed depends on the configuration of the domain. Computer account creation is + /// enabled using three methods: + /// + /// + /// + /// Domain administrators have rights to create computer accounts. + /// + /// + /// The SD on a container can delegate the rights to create computer accounts. + /// + /// + /// + /// By default, authenticated users may create computer accounts by privilege. Authenticated users are limited to creating a limited + /// number of accounts that is specified as a quota on the domain (the default value is 10). For more information, see the + /// ms-DS-MachineAccountQuota attribute in the Active Directory schema. + /// + /// + /// + /// + /// The NetProvisionComputerAccount function works only with a writable domain controller and does not function against a + /// read-only domain controller. Once provisioning is done against a writable domain controller and the account is replicated to a + /// read-only domain controller, then the other portions of offline domain join operation do not require access to a domain controller. + /// + /// + /// If the NetProvisionComputerAccount function is successful, the pointer in the pProvisionBinData or pProvisionTextData + /// parameter (depending on which was parameter was not NULL) is returned with the serialized data for use in an offline join + /// operation or as text in an unattended setup file. + /// + /// For more information on offline domain join operations, see the Offline Domain Join Step-by-Step Guide. + /// + /// Joining (and unjoining) a computer to a domain using NetJoinDomain and NetUnjoinDomain can be performed only by a member of the + /// Administrators local group on the target computer. Note that the domain administrator can set additional requirements for joining + /// the domain using delegation and assignment of privileges. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmjoin/nf-lmjoin-netprovisioncomputeraccount NET_API_STATUS NET_API_FUNCTION + // NetProvisionComputerAccount( LPCWSTR lpDomain, LPCWSTR lpMachineName, LPCWSTR lpMachineAccountOU, LPCWSTR lpDcName, DWORD + // dwOptions, PBYTE *pProvisionBinData, DWORD *pdwProvisionBinDataSize, LPWSTR *pProvisionTextData ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] + [PInvokeData("lmjoin.h", MSDNShortId = "4c854258-b84d-4ef3-a6da-ce0a9540ffd5")] + public static extern Win32Error NetProvisionComputerAccount(string lpDomain, string lpMachineName, [Optional] string lpMachineAccountOU, string lpDcName, NETSETUP_PROVISION dwOptions, + [Optional] IntPtr pProvisionBinData, [Optional] IntPtr pdwProvisionBinDataSize, ref StringBuilder pProvisionTextData); + + /// The NetRemoveAlternateComputerName function removes an alternate name for the specified computer. + /// + /// A pointer to a constant string that specifies the name of the computer on which to execute this function. If this parameter is + /// NULL, the local computer is used. + /// + /// + /// A pointer to a constant string that specifies the alternate name to remove. This name must be in the form of a fully qualified + /// DNS name. + /// + /// + /// + /// A pointer to a constant string that specifies the domain account to use for accessing the machine account object for the computer + /// specified in the Server parameter in Active Directory. If this parameter is NULL, then the credentials of the user + /// executing this routine are used. + /// + /// This parameter is not used if the server to execute this function is not joined to a domain. + /// + /// + /// + /// A pointer to a constant string that specifies the password matching the domain account passed in the DomainAccount parameter. If + /// this parameter is NULL, then the credentials of the user executing this routine are used. + /// + /// + /// This parameter is ignored if the DomainAccount parameter is NULL. This parameter is not used if the server to execute this + /// function is not joined to a domain. + /// + /// + /// Reserved for future use. This parameter should be NULL. + /// + /// If the function succeeds, the return value is NERR_Success. + /// 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 + /// + /// Access is denied. This error is returned if the caller was not a member of the Administrators local group on the target computer. + /// + /// + /// + /// ERROR_INVALID_NAME + /// A name parameter is incorrect. This error is returned if the AlternateName parameter does not contain valid name. + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// A parameter is incorrect. This error is returned if the DomainAccount parameter does not contain a valid domain. This error is + /// also returned if the DomainAccount parameter is not NULL and the DomainAccountPassword parameter is not NULL but does not contain + /// a Unicode string. + /// + /// + /// + /// ERROR_NOT_ENOUGH_MEMORY + /// Not enough memory is available to process this command. + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The request is not supported. This error is returned if the target computer specified in the Server parameter on which this + /// function executes is running on Windows 2000 and earlier. + /// + /// + /// + /// NERR_WkstaNotStarted + /// The Workstation service has not been started. + /// + /// + /// RPC_S_CALL_IN_PROGRESS + /// A remote procedure call is already in progress for this thread. + /// + /// + /// RPC_S_PROTSEQ_NOT_SUPPORTED + /// The remote procedure call protocol sequence is not supported. + /// + /// + /// + /// + /// The NetRemoveAlternateComputerName function is supported on Windows XP and later. + /// + /// The NetRemoveAlternateComputerName function is used to remove secondary computer names configured for the target computer. + /// + /// + /// The NetRemoveAlternateComputerName function requires that the caller is a member of the Administrators local group on the + /// target computer. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmjoin/nf-lmjoin-netremovealternatecomputername NET_API_STATUS + // NET_API_FUNCTION NetRemoveAlternateComputerName( LPCWSTR Server, LPCWSTR AlternateName, LPCWSTR DomainAccount, LPCWSTR + // DomainAccountPassword, ULONG Reserved ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] + [PInvokeData("lmjoin.h", MSDNShortId = "3c7ab44e-d5fa-40da-83fe-a44bf85b2ba5")] + public static extern Win32Error NetRemoveAlternateComputerName([Optional] string Server, string AlternateName, [Optional] string DomainAccount, [Optional] string DomainAccountPassword, uint Reserved = 0); + + /// The NetRenameMachineInDomain function changes the name of a computer in a domain. + /// + /// A pointer to a constant string that specifies the DNS or NetBIOS name of the computer on which to call the function. If this + /// parameter is NULL, the local computer is used. + /// + /// + /// A pointer to a constant string that specifies the new name of the computer. If specified, the local computer name is changed as + /// well. If this parameter is NULL, the function assumes you have already called the SetComputerNameEx function. + /// + /// + /// A pointer to a constant string that specifies an account name to use when connecting to the domain controller. If this parameter + /// is NULL, the caller's context is used. + /// + /// + /// If the lpAccount parameter specifies an account name, this parameter must point to the password to use when connecting to the + /// domain controller. Otherwise, this parameter must be NULL. + /// + /// + /// The rename options. If this parameter is NETSETUP_ACCT_CREATE, the function renames the account in the domain. + /// + /// + /// If the function succeeds, the return value is NERR_Success. + /// 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 + /// + /// Access is denied. This error is returned if the account name passed in the lpAccount parameter did not have sufficient access + /// rights for the operation. + /// + /// + /// + /// ERROR_INVALID_PARAMETER + /// A parameter is incorrect. + /// + /// + /// NERR_SetupNotJoined + /// The computer is not currently joined to a domain. + /// + /// + /// NERR_SetupDomainController + /// This computer is a domain controller and cannot be unjoined from a domain. + /// + /// + /// + /// + /// + /// Renaming a domain computer can be performed only by a user that is a member of the Administrators local group on the target + /// computer and that also is a member of the Administrators group on the domain or has the Account Operator privilege on the domain. + /// If you call the NetRenameMachineInDomain function remotely, you must supply credentials because you cannot delegate + /// credentials under these circumstances. + /// + /// + /// Different processes, or different threads of the same process, should not call the NetRenameMachineInDomain function at + /// the same time. This situation can leave the computer in an inconsistent state. + /// + /// + /// The NERR_SetupNotJoined and NERR_SetupDomainController return values are defined in the Lmerr.h header file. This + /// header file is automatically included by the Lm.h header file and should not be included directly. + /// + /// A system reboot is required after calling the NetRenameMachineInDomain function for the operation to complete. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmjoin/nf-lmjoin-netrenamemachineindomain NET_API_STATUS NET_API_FUNCTION + // NetRenameMachineInDomain( LPCWSTR lpServer, LPCWSTR lpNewMachineName, LPCWSTR lpAccount, LPCWSTR lpPassword, DWORD fRenameOptions ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] + [PInvokeData("lmjoin.h", MSDNShortId = "1f7ddaa1-a349-49a6-856d-a2fde2f1dc3b")] + public static extern Win32Error NetRenameMachineInDomain([Optional] string lpServer, [Optional] string lpNewMachineName, [Optional] string lpAccount, [Optional] string lpPassword, NETSETUP fRenameOptions); + + /// + /// The NetRequestOfflineDomainJoin function executes locally on a machine to modify a Windows operating system image mounted + /// on a volume. The registry is loaded from the image and provisioning blob data is written where it can be retrieved during the + /// completion phase of an offline domain join operation. + /// + /// + /// + /// A pointer to a buffer required to initialize the registry of a Windows operating system image to process the final local state + /// change during the completion phase of the offline domain join operation. + /// + /// + /// The opaque binary blob of serialized metadata passed in the pProvisionBinData parameter is returned by the + /// NetProvisionComputerAccount function. + /// + /// + /// + /// The size, in bytes, of the buffer pointed to by the pProvisionBinData parameter. + /// This parameter must not be NULL. + /// + /// + /// + /// A set of bit flags that define options for this function. This parameter can be one or more of the following values defined in + /// the Lmjoin.h header file. + /// + /// + /// + /// Value + /// Meaning + /// + /// + /// NETSETUP_PROVISION_ONLINE_CALLER 0x40000000 + /// + /// This flag is required if the lpWindowsPath parameter references the currently running Windows operating system directory rather + /// than an offline Windows operating system image mounted on an accessible volume. If this flag is specified, the + /// NetRequestOfflineDomainJoin function must be invoked by a member of the local Administrators group. + /// + /// + /// + /// + /// + /// + /// A pointer to a constant null-terminated character string that specifies the path to a Windows operating system image under which + /// the registry hives are located. This image must be offline and not currently booted unless the dwOptions parameter contains + /// NETSETUP_PROVISION_ONLINE_CALLER in which case the locally running operating system directory is allowed. + /// + /// This path could be a UNC path on a remote server. + /// + /// + /// If the function succeeds, the return value is NERR_Success. + /// 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 + /// Access is denied. This error is returned if the caller does not have sufficient privileges to complete the operation. + /// + /// + /// ERROR_ELEVATION_REQUIRED + /// The requested operation requires elevation. + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// A parameter is incorrect. This error is returned if the pProvisionBinData, cbProvisionBinDataSize, or lpWindowsPath parameters + /// are NULL. This error is also returned if the buffer pointed to by the pProvisionBinData parameter does not contain valid data in + /// the blob for the domain, machine account name, or machine account password. This error is also returned if the string pointed to + /// lpWindowsPath parameter does not specific the path to a Windows operating system image. + /// + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The request is not supported. This error is returned if the specified server does not support this operation. For example, if the + /// lpWindowsPath parameter references a Windows installation configured as a domain controller. + /// + /// + /// + /// NERR_WkstaNotStarted + /// The Workstation service has not been started. + /// + /// + /// + /// + /// The NetRequestOfflineDomainJoin function is supported on Windows 7 for offline domain join operations. + /// + /// The NetRequestOfflineDomainJoin function is used locally on a machine to modify a Windows operating system image mounted + /// on a volume. The registry is loaded for the image and provisioning blob data is written where it can be retrieved during the + /// completion phase of an offline domain join operation. The offline domain join scenario uses these functions as follows: + /// + /// + /// + /// + /// NetProvisionComputerAccount is a provisioning function that is first called to perform the network operations necessary to create + /// and configure the computer object in Active Directory. The output from the NetProvisionComputerAccount is an opaque binary + /// blob of serialized metadata used for the next step. + /// + /// + /// + /// + /// NetRequestOfflineDomainJoin , an image initialization function, is then called to inject the output from the + /// NetProvisionComputerAccount provisioning function into a Windows operating system image to be used during installation. Changes + /// to Windows initialization code will detect this saved state and affect the local only portion of domain join. + /// + /// + /// + /// + /// The NetProvisionComputerAccount function will create or reuse the machine account in the domain, collect all necessary metadata + /// and return it in an opaque versioned binary blob or as text for embedding in an unattended setup answer file. The opaque binary + /// blob can be consumed by the offline domain join request operation supplying all the necessary input to complete the domain join + /// during first boot without any network operations (local state updates only). Note that the blob contains machine account password + /// material essentially in the clear. The design makes no provisions for securing this data. This problem exists today with + /// unattended setup answer files which can carry a number of secrets including domain user passwords. The caller must secure the + /// blob and the unattended setup files. Solutions to this problem are varied. As an example, a pre-exchanged key could be used to + /// encrypt a session between the consumer and provisioning entity enabling a secure transfer of the opaque blob . + /// + /// + /// The opaque blob returned in the pProvisionBinData parameter by the NetProvisionComputerAccount function is versioned to allow + /// interoperability and serviceability scenarios between different versions of Windows (joining client, provisioning machine, and + /// domain controller). The offline join scenario currently does not limit the lifetime of the blob returned by the + /// NetProvisionComputerAccount function. + /// + /// For more information on offline domain join operations, see the Offline Domain Join Step-by-Step Guide. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmjoin/nf-lmjoin-netrequestofflinedomainjoin NET_API_STATUS NET_API_FUNCTION + // NetRequestOfflineDomainJoin( BYTE *pProvisionBinData, DWORD cbProvisionBinDataSize, DWORD dwOptions, LPCWSTR lpWindowsPath ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] + [PInvokeData("lmjoin.h", MSDNShortId = "f3f8fe00-d6f7-4d59-a4e7-6aef7f507e1a")] + public static extern Win32Error NetRequestOfflineDomainJoin([In] IntPtr pProvisionBinData, uint cbProvisionBinDataSize, NETSETUP_PROVISION dwOptions, string lpWindowsPath); + + /// + /// The NetRequestProvisioningPackageInstall function executes locally on a machine to modify a Windows operating system image + /// mounted on a volume. The registry is loaded from the image and provisioning package data is written where it can be retrieved + /// during the completion phase of an offline domain join operation. + /// + /// + /// + /// A pointer to a buffer required to initialize the registry of a Windows operating system image to process the final local state + /// change during the completion phase of the offline domain join operation. + /// + /// + /// The opaque binary blob of serialized metadata passed in the pPackageBinData parameter is returned by the + /// NetCreateProvisioningPackage function. + /// + /// + /// + /// The size, in bytes, of the buffer pointed to by the pPackageBinData parameter. + /// This parameter must not be NULL. + /// + /// + /// + /// A set of bit flags that define options for this function. This parameter uses one or more of the following values defined in the + /// Lmjoin.h header file. + /// + /// + /// + /// Value + /// Meaning + /// + /// + /// NETSETUP_PROVISION_ONLINE_CALLER 0x40000000 + /// + /// This flag is required if the lpWindowsPath parameter references the currently running Windows operating system directory rather + /// than an offline Windows operating system image mounted on an accessible volume. If this flag is specified, the + /// NetRequestProvisioningPackageInstall function must be invoked by a member of the local Administrators group. + /// + /// + /// + /// + /// + /// + /// A pointer to a NULL-terminated character string that specifies the path to a Windows operating system image under which + /// the registry hives are located. This image must be offline and not currently booted unless the dwProvisionOptions parameter + /// contains NETSETUP_PROVISION_ONLINE_CALLER, in which case, the locally running operating system directory is allowed. + /// + /// This path could be a UNC path on a remote server. + /// + /// Reserved for future use. + /// + /// If the function succeeds, the return value is NERR_Success. + /// If the function fails, the return value can be one of the following Network Management error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// NERR_NoOfflineJoinInfo + /// The offline join completion information was not found. + /// + /// + /// NERR_BadOfflineJoinInfo + /// The offline join completion information was bad. + /// + /// + /// NERR_CantCreateJoinInfo + /// + /// Unable to create offline join information. Please ensure you have access to the specified path location and permissions to modify + /// its contents. Running as an elevated administrator may be required. + /// + /// + /// + /// NERR_BadDomainJoinInfo + /// The domain join info being saved was incomplete or bad. + /// + /// + /// NERR_JoinPerformedMustRestart + /// Offline join operation successfully completed but a restart is needed. + /// + /// + /// NERR_NoJoinPending + /// There was no offline join operation pending. + /// + /// + /// NERR_ValuesNotSet + /// Unable to set one or more requested machine or domain name values on the local computer. + /// + /// + /// NERR_CantVerifyHostname + /// Could not verify the current machine's hostname against the saved value in the join completion information. + /// + /// + /// NERR_CantLoadOfflineHive + /// + /// Unable to load the specified offline registry hive. Please ensure you have access to the specified path location and permissions + /// to modify its contents. Running as an elevated administrator may be required. + /// + /// + /// + /// NERR_ConnectionInsecure + /// The minimum session security requirements for this operation were not met. + /// + /// + /// NERR_ProvisioningBlobUnsupported + /// Computer account provisioning blob version is not supported. + /// + /// + /// + /// + /// + /// The NetRequestProvisioningPackageInstall function is supported on Windows 8 for offline domain join operations. For Windows 7, + /// use NetRequestOfflineDomainJoin. + /// + /// The offline domain join scenario uses two functions: + /// + /// + /// + /// NetCreateProvisioningPackage is a provisioning function that is first called to perform the network operations necessary to + /// create and configure the computer object in Active Directory. The output from the NetCreateProvisioningPackage is a + /// package used for the next step. + /// + /// + /// + /// + /// NetRequestProvisioningPackageInstall, an image initialization function, is called to inject the output from the + /// NetCreateProvisioningPackage provisioning function into a Windows operating system image for use during installation. + /// + /// + /// + /// + /// Changes to Windows initialization code will detect this saved state and affect the local-only portion of domain join and install + /// any certificate and policy information that may have been present in the package. + /// + /// + /// The NetCreateProvisioningPackage function will create or reuse the machine account in the domain, collect all necessary metadata + /// and return it in a package. The package can be consumed by the offline domain join request operation supplying all the necessary + /// input to complete the domain join during first boot without any network operations (local state updates only). + /// + /// + /// Security Note: The package created by the NetCreateProvisioningPackage function contains very sensitive data. It should be + /// treated just as securely as a plaintext password. The package contains the machine account password and other information about + /// the domain, including the domain name, the name of a domain controller, and the security ID (SID) of the domain. If the package + /// is being transported physically or over the network, care must be taken to transport it securely. The design makes no provisions + /// for securing this data. This problem exists today with unattended setup answer files which can carry a number of secrets + /// including domain user passwords. The caller must secure the package. Solutions to this problem are varied. As an example, a + /// pre-exchanged key could be used to encrypt a session between the consumer and provisioning entity enabling a secure transfer of + /// the package. + /// + /// + /// The package returned in the pPackageBinData parameter by the NetCreateProvisioningPackage function is versioned to allow + /// interoperability and serviceability scenarios between different versions of Windows (such as joining a client, provisioning a + /// machine, and using a domain controller). The offline join scenario currently does not limit the lifetime of the package returned + /// by the NetCreateProvisioningPackage function. + /// + /// + /// All phases of the provisioning process append to a NetSetup.log file on the local computer. The provisoning process can include + /// up to three different computers: the computer where the provisioning package is created, the computer that requests the + /// installation of the package, and the computer where the package is installed. There will be NetSetup.log file information stored + /// on all three computers according to the operation performed. Reviewing the contents of these files is the most common means of + /// troubleshooting online and offline provisioning errors. Provisioning operations undertaken by admins are logged to the + /// NetSetup.log file in the %WINDIR%\Debug. Provisioning operations performed by non-admins are logged to the NetSetup.log file in + /// the %USERPROFILE%\Debug folder. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmjoin/nf-lmjoin-netrequestprovisioningpackageinstall NET_API_STATUS + // NET_API_FUNCTION NetRequestProvisioningPackageInstall( BYTE *pPackageBinData, DWORD dwPackageBinDataSize, DWORD + // dwProvisionOptions, LPCWSTR lpWindowsPath, PVOID pvReserved ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] + [PInvokeData("lmjoin.h", MSDNShortId = "107ED0F7-8DDD-4C18-8C34-3A67F771FA62")] + public static extern Win32Error NetRequestProvisioningPackageInstall([In] IntPtr pPackageBinData, uint dwPackageBinDataSize, NETSETUP_PROVISION dwProvisionOptions, string lpWindowsPath, IntPtr pvReserved = default); + + /// The NetSetPrimaryComputerName function sets the primary computer name for the specified computer. + /// + /// A pointer to a constant string that specifies the name of the computer on which to execute this function. If this parameter is + /// NULL, the local computer is used. + /// + /// + /// A pointer to a constant string that specifies the primary name to set. This name must be in the form of a fully qualified DNS name. + /// + /// + /// + /// A pointer to a constant string that specifies the domain account to use for accessing the machine account object for the computer + /// specified in the Server parameter in Active Directory. If this parameter is NULL, then the credentials of the user + /// executing this routine are used. + /// + /// This parameter is not used if the server to execute this function is not joined to a domain. + /// + /// + /// + /// A pointer to a constant string that specifies the password matching the domain account passed in the DomainAccount parameter. If + /// this parameter is NULL, then the credentials of the user executing this routine are used. + /// + /// + /// This parameter is ignored if the DomainAccount parameter is NULL. This parameter is not used if the server to execute this + /// function is not joined to a domain. + /// + /// + /// Reserved for future use. This parameter should be NULL. + /// + /// If the function succeeds, the return value is NERR_Success. + /// 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 + /// + /// Access is denied. This error is returned if the caller was not a member of the Administrators local group on the target computer. + /// + /// + /// + /// ERROR_INVALID_NAME + /// A name parameter is incorrect. This error is returned if the PrimaryName parameter does not contain valid name. + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// A parameter is incorrect. This error is returned if the DomainAccount parameter does not contain a valid domain. This error is + /// also returned if the DomainAccount parameter is not NULL and the DomainAccountPassword parameter is not NULL but does not contain + /// a Unicode string. + /// + /// + /// + /// ERROR_NOT_ENOUGH_MEMORY + /// Not enough memory is available to process this command. + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The request is not supported. This error is returned if the target computer specified in the Server parameter on which this + /// function executes is running on Windows 2000 and earlier. + /// + /// + /// + /// NERR_WkstaNotStarted + /// The Workstation service has not been started. + /// + /// + /// RPC_S_CALL_IN_PROGRESS + /// A remote procedure call is already in progress for this thread. + /// + /// + /// RPC_S_PROTSEQ_NOT_SUPPORTED + /// The remote procedure call protocol sequence is not supported. + /// + /// + /// + /// + /// The NetSetPrimaryComputerName function is supported on Windows XP and later. + /// + /// The NetSetPrimaryComputerName function is used as part of computer rename operations. The specified name will be removed + /// from the alternate name list configured for the target computer and configured as the primary name. The computer account name + /// will be changed to match the primary name. The previous primary computer name is moved to the alternate computer name list + /// configured for the computer. + /// + /// + /// The NetSetPrimaryComputerName function requires that the caller is a member of the Administrators local group on the + /// target computer. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmjoin/nf-lmjoin-netsetprimarycomputername NET_API_STATUS NET_API_FUNCTION + // NetSetPrimaryComputerName( LPCWSTR Server, LPCWSTR PrimaryName, LPCWSTR DomainAccount, LPCWSTR DomainAccountPassword, ULONG + // Reserved ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] + [PInvokeData("lmjoin.h", MSDNShortId = "524c8219-a303-45ab-95e2-91319b477568")] + public static extern Win32Error NetSetPrimaryComputerName([Optional] string Server, string PrimaryName, [Optional] string DomainAccount, [Optional] string DomainAccountPassword, uint Reserved = 0); + + /// The NetUnjoinDomain function unjoins a computer from a workgroup or a domain. + /// + /// A pointer to a constant string that specifies the DNS or NetBIOS name of the computer on which the function is to execute. If + /// this parameter is NULL, the local computer is used. + /// + /// + /// A pointer to a constant string that specifies the account name to use when connecting to the domain controller. The string must + /// specify either a domain NetBIOS name and user account (for example, REDMOND\user) or the user principal name (UPN) of the user in + /// the form of an Internet-style login name (for example, "someone@example.com"). If this parameter is NULL, the caller's + /// context is used. + /// + /// + /// If the lpAccount parameter specifies an account name, this parameter must point to the password to use when connecting to the + /// domain controller. Otherwise, this parameter must be NULL. + /// + /// + /// Specifies the unjoin options. If this parameter is NETSETUP_ACCT_DELETE, the account is disabled when the unjoin occurs. Note + /// that this option does not delete the account. Currently, there are no other unjoin options defined. + /// + /// + /// If the function succeeds, the return value is NERR_Success. + /// 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_INVALID_PARAMETER + /// A parameter is incorrect. + /// + /// + /// NERR_SetupNotJoined + /// The computer is not currently joined to a domain. + /// + /// + /// NERR_SetupDomainController + /// This computer is a domain controller and cannot be unjoined from a domain. + /// + /// + /// + /// + /// + /// Unjoining (and joining) a computer to a domain or workgroup can be performed only by a member of the Administrators local group + /// on the target computer. If you call the NetUnjoinDomain function remotely, you must supply credentials because you cannot + /// delegate credentials under these circumstances. + /// + /// + /// Different processes, or different threads of the same process, should not call the NetUnjoinDomain function at the same + /// time. This situation can leave the computer in an inconsistent state. + /// + /// A system reboot is required after calling the NetRenameMachineInDomain function for the operation to complete. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmjoin/nf-lmjoin-netunjoindomain NET_API_STATUS NET_API_FUNCTION + // NetUnjoinDomain( LPCWSTR lpServer, LPCWSTR lpAccount, LPCWSTR lpPassword, DWORD fUnjoinOptions ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] + [PInvokeData("lmjoin.h", MSDNShortId = "cc755c22-1fd6-4787-999e-a43258287a05")] + public static extern Win32Error NetUnjoinDomain([Optional] string lpServer, [Optional] string lpAccount, [Optional] string lpPassword, NETSETUP fUnjoinOptions); + + /// + /// The NetValidateName function verifies that a name is valid for name type specified(computer name, workgroup name, domain + /// name, or DNS computer name). + /// + /// + /// A pointer to a constant string that specifies the DNS or NetBIOS name of the computer on which to call the function. If this + /// parameter is NULL, the local computer is used. + /// + /// + /// A pointer to a constant string that specifies the name to validate. Depending on the value specified in the NameType parameter, + /// the lpName parameter can point to a computer name, workgroup name, domain name, or DNS computer name. + /// + /// + /// If the lpName parameter is a domain name, this parameter points to an account name to use when connecting to the domain + /// controller. The string must specify either a domain NetBIOS name and user account (for example, "REDMOND\user") or the user + /// principal name (UPN) of the user in the form of an Internet-style login name (for example, "someone@example.com"). If this + /// parameter is NULL, the caller's context is used. + /// + /// + /// If the lpAccount parameter specifies an account name, this parameter must point to the password to use when connecting to the + /// domain controller. Otherwise, this parameter must be NULL. + /// + /// + /// + /// The type of the name passed in the lpName parameter to validate. This parameter can be one of the values from the + /// NETSETUP_NAME_TYPE enumeration type defined in the Lmjoin.h header file. + /// + /// + /// Note that the Lmjoin.h header is automatically included by the Lm.h header file. The Lmjoin.h header files should not be used directly. + /// + /// The following list shows the possible values for this parameter. + /// + /// + /// Value + /// Meaning + /// + /// + /// NetSetupUnknown 0 + /// The nametype is unknown. If this value is used, the NetValidateName function fails with ERROR_INVALID_PARAMETER. + /// + /// + /// NetSetupMachine 1 + /// Verify that the NetBIOS computer name is valid and that it is not in use. + /// + /// + /// NetSetupWorkgroup 2 + /// Verify that the workgroup name is valid. + /// + /// + /// NetSetupDomain 3 + /// Verify that the domain name exists and that it is a domain. + /// + /// + /// NetSetupNonExistentDomain 4 + /// Verify that the domain name is not in use. + /// + /// + /// NetSetupDnsMachine 5 + /// + /// Verify that the DNS computer name is valid. This value is supported on Windows 2000 and later. The application must be compiled + /// with _WIN32_WINNT >= 0x0500 to use this value. + /// + /// + /// + /// + /// + /// If the function succeeds, the return value is NERR_Success. + /// If the function fails, the return value can be one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// DNS_ERROR_INVALID_NAME_CHAR + /// + /// The DNS name contains an invalid character. This error is returned if the NameType parameter specified is NetSetupDnsMachine and + /// the DNS name in the lpName parameter contains an invalid character. + /// + /// + /// + /// DNS_ERROR_NON_RFC_NAME + /// + /// The DNS name does not comply with RFC specifications. This error is returned if the NameType parameter specified is + /// NetSetupDnsMachine and the DNS name in the lpName parameter does not comply with RFC specifications. + /// + /// + /// + /// ERROR_DUP_NAME + /// A duplicate name already exists on the network. + /// + /// + /// ERROR_INVALID_COMPUTERNAME + /// The format of the specified computer name is not valid. + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// A parameter is incorrect. This error is returned if the lpName parameter is NULL or the NameType parameter is specified as + /// NetSetupUnknown or an unknown nametype. + /// + /// + /// + /// ERROR_NO_SUCH_DOMAIN + /// The specified domain does not exist. + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The request is not supported. This error is returned if a remote computer was specified in the lpServer parameter and this call + /// is not supported on the remote computer. + /// + /// + /// + /// NERR_InvalidComputer + /// + /// The specified computer name is not valid. This error is returned if the NameType parameter specified is NetSetupDnsMachine or + /// NetSetupMachine and the specified computer name is not valid. + /// + /// + /// + /// NERR_InvalidWorkgroupName + /// + /// The specified workgroup name is not valid. This error is returned if the NameType parameter specified is NetSetupWorkgroup and + /// the specified workgroup name is not valid. + /// + /// + /// + /// RPC_S_SERVER_UNAVAILABLE + /// + /// The RPC server is not available. This error is returned if a remote computer was specified in the lpServer parameter and the RPC + /// server is not available. + /// + /// + /// + /// RPC_E_REMOTE_DISABLED + /// + /// Remote calls are not allowed for this process. This error is returned if a remote computer was specified in the lpServer + /// parameter and remote calls are not allowed for this process. + /// + /// + /// + /// + /// + /// The NetValidateName function validates a name based on the nametype specified. + /// + /// If the NameType parameter is NetSetupMachine, the name passed in the lpName parameter must be syntactically correct as a + /// NetBIOS name and the name must not currently be in use on the network. + /// + /// + /// If the NameType parameter is NetSetupWorkgroup, the name passed in the lpName parameter must be syntactically correct as a + /// NetBIOS name, the name must not currently be in use on the network as a unique name, and the name must be different from the + /// computer name. + /// + /// + /// If the NameType parameter is NetSetupDomain, the name passed in the lpName parameter must be syntactically correct as a + /// NetBIOS or DNS name and the name must currently be registered as a domain name. + /// + /// + /// If the NameType parameter is NetSetupNonExistentDomain, the name passed in the lpName parameter must be syntactically + /// correct as a NetBIOS or DNS name and the name must currently not be registered as a domain name. + /// + /// + /// If the NameType parameter is NetSetupDnsMachine, the name passed in the lpName parameter must be syntactically correct as + /// a DNS name. + /// + /// NetBIOS names are limited to maximum length of 16 characters. + /// No special group membership is required to successfully execute the NetValidateName function. + /// Examples + /// The following example validates a name for a specific type. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmjoin/nf-lmjoin-netvalidatename NET_API_STATUS NET_API_FUNCTION + // NetValidateName( LPCWSTR lpServer, LPCWSTR lpName, LPCWSTR lpAccount, LPCWSTR lpPassword, NETSETUP_NAME_TYPE NameType ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] + [PInvokeData("lmjoin.h", MSDNShortId = "772603df-ec17-4a83-a715-2d9a14d5c2bb")] + public static extern Win32Error NetValidateName([Optional] string lpServer, string lpName, [Optional] string lpAccount, [Optional] string lpPassword, NETSETUP_NAME_TYPE NameType); + + /// Contains information about a user account that is used to join a device to Microsoft Azure Active Directory. + // https://docs.microsoft.com/en-us/windows/desktop/api/lmjoin/ns-lmjoin-_dsreg_user_info typedef struct _DSREG_USER_INFO { LPWSTR + // pszUserEmail; LPWSTR pszUserKeyId; LPWSTR pszUserKeyName; } DSREG_USER_INFO, *PDSREG_USER_INFO; + [PInvokeData("lmjoin.h", MSDNShortId = "5E639988-0F53-40D7-BBEC-F78B3D124CC0")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + public struct DSREG_USER_INFO + { + /// The email address of the user. + public string pszUserEmail; + + /// The identifier of the Microsoft Passport key that is provisioned for the user. + public string pszUserKeyId; + + /// The name of the Microsoft Passport key that is provisioned for the user. + public string pszUserKeyName; + } + + /// + /// The NETSETUP_PROVISIONING_PARAMS structure contains information that is used when creating a provisioning package using + /// the NetCreateProvisionPackage function. + /// + /// + /// + /// The NETSETUP_PROVISIONING_PARAMS structure provides flags for the NetCreateProvisioningPackage function which is supported + /// on Windows 8 and Windows Server 2012 for offline join operations. + /// + /// + /// In addition to domain joins, the provisioning package can provide certificates and policies to the machine. The provisioning + /// package can be used in four ways: + /// + /// + /// + /// Domain join + /// + /// + /// Domain join and installation of certificates + /// + /// + /// Domain join and installation of policies + /// + /// + /// Domain join and installation of certificates and policies + /// + /// + /// + /// When certificates need to be added to the package, this structure provides the aCertTemplateNames member as an array of + /// NULL-terminated certificate template names. The aCertTemplateNames member requires the cCertTemplateNames + /// member to provide an explicit count of the number of items in the array. + /// + /// There are two different ways to add policies. You can use one or both methods: + /// + /// + /// + /// Policy name—An array of NULL-terminated policy names is provided in the aMachinePolicyNames member. During runtime, + /// the policy name is mapped to the policy name in AD and the GUID that represents the policy in the enterprise space is retrieved. + /// The aMachinePolicyNames member requires the cMachinePolicyNames member to provide an explicit count of the number + /// of items in the array. + /// + /// + /// + /// + /// Policy path—A pointer to an array of NULL-terminated character strings provided in the aMachinePolicyPaths member + /// which specify the path to a file in the Registry Policy File format. For more information on the Registry Policy File Format , + /// see Registry Policy File Format. The policy path is a full or relative path to the policy file. + /// + /// + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmjoin/ns-lmjoin-_netsetup_provisioning_params typedef struct + // _NETSETUP_PROVISIONING_PARAMS { DWORD dwVersion; LPCWSTR lpDomain; LPCWSTR lpHostName; LPCWSTR lpMachineAccountOU; LPCWSTR + // lpDcName; DWORD dwProvisionOptions; LPCWSTR *aCertTemplateNames; DWORD cCertTemplateNames; LPCWSTR *aMachinePolicyNames; DWORD + // cMachinePolicyNames; LPCWSTR *aMachinePolicyPaths; DWORD cMachinePolicyPaths; LPWSTR lpNetbiosName; LPWSTR lpSiteName; LPWSTR + // lpPrimaryDNSDomain; } NETSETUP_PROVISIONING_PARAMS, *PNETSETUP_PROVISIONING_PARAMS; + [PInvokeData("lmjoin.h", MSDNShortId = "E965804F-145A-4D8F-BB8E-466580AC65DA")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + public struct NETSETUP_PROVISIONING_PARAMS + { + /// + /// + /// The version of Windows in the provisioning package. This parameter should use the following value defined in the Lmjoin.h + /// header file. + /// + /// + /// + /// Value + /// Meaning + /// + /// + /// NETSETUP_PROVISIONING_PARAMS_CURRENT_VERSION 0x00000001 + /// The version for this package is Windows Server 2012. + /// + /// + /// + public uint dwVersion; + + /// + /// A pointer to a NULL-terminated character string that specifies the name of the domain where the computer account is created. + /// + public string lpDomain; + + /// The lp host name + public string lpHostName; + + /// + /// + /// A optional pointer to a NULL-terminated character string that contains the RFC 1779 format name of the organizational + /// unit (OU) where the computer account will be created. If you specify this parameter, the string must contain a full path, for + /// example, OU=testOU,DC=domain,DC=Domain,DC=com. Otherwise, this parameter must be NULL. + /// + /// If this parameter is NULL, the well known computer object container will be used as published in the domain. + /// + public string lpMachineAccountOU; + + /// + /// An optional pointer to a NULL-terminated character string that contains the name of the domain controller to target. + /// + public string lpDcName; + + /// + /// + /// A set of bit flags that define provisioning options. This parameter can be one or more of the following values defined in the + /// Lmjoin.h header file. + /// + /// + /// + /// Value + /// Meaning + /// + /// + /// NETSETUP_PROVISION_DOWNLEVEL_PRIV_SUPPORT 0x00000001 + /// + /// If the caller requires account creation by privilege, this option will cause a retry on failure using account creation + /// functions enabling interoperability with domain controllers running on earlier versions of Windows. The lpMachineAccountOU is + /// not supported when using downlevel privilege support. + /// + /// + /// + /// NETSETUP_PROVISION_REUSE_ACCOUNT 0x00000002 + /// + /// If the named account already exists, an attempt will be made to reuse the existing account. This option requires sufficient + /// credentials for this operation (Domain Administrator or the object owner). + /// + /// + /// + /// NETSETUP_PROVISION_USE_DEFAULT_PASSWORD 0x00000004 + /// + /// Use the default machine account password which is the machine name in lowercase. This is largely to support the older + /// unsecure join model where the pre-created account typically used this default password. + /// + /// + /// + /// NETSETUP_PROVISION_SKIP_ACCOUNT_SEARCH 0x00000008 + /// + /// Do not try to find the account on any domain controller in the domain. This option makes the operation faster, but should + /// only be used when the caller is certain that an account by the same name hasn't recently been created. This option is only + /// valid when the lpDcName parameter is specified. When the prerequisites are met, this option allows for must faster + /// provisioning useful for scenarios such as batch processing. + /// + /// + /// + /// NETSETUP_PROVISION_ROOT_CA_CERTS 0x00000010 + /// + /// This option retrieves all of the root Certificate Authority certificates on the local machine and adds them to the + /// provisioning package. + /// + /// + /// + /// + public uint dwProvisionOptions; + + /// A pointer to an array of NULL-terminated certificate template names. + public IntPtr aCertTemplateNames; + + /// + /// When aCertTemplateNames is not NULL, this member provides an explicit count of the number of items in the array. + /// + public uint cCertTemplateNames; + + /// A pointer to an array of NULL-terminated machine policy names. + public IntPtr aMachinePolicyNames; + + /// + /// When aMachinePolicyNames is not NULL, this member provides an explicit count of the number of items in the array. + /// + public uint cMachinePolicyNames; + + /// + /// + /// A pointer to an array of character strings. Each array element is a NULL-terminated character string which specifies the full + /// or partial path to a file in the Registry Policy File format. For more information on the Registry Policy File Format , see + /// Registry Policy File Format + /// + /// This path could be a UNC path on a remote server. + /// + public IntPtr aMachinePolicyPaths; + + /// + /// When aMachinePolicyPaths is not NULL, this member provides an explicit count of the number of items in the array. + /// + public uint cMachinePolicyPaths; + + /// The lp netbios name + public string lpNetbiosName; + + /// The lp site name + public string lpSiteName; + + /// The lp primary DNS domain + public string lpPrimaryDNSDomain; + } + + /// Contains information about how a device is joined to Microsoft Azure Active Directory. + // https://docs.microsoft.com/en-us/windows/desktop/api/lmjoin/ns-lmjoin-_dsreg_join_info typedef struct _DSREG_JOIN_INFO { + // DSREG_JOIN_TYPE joinType; PCCERT_CONTEXT pJoinCertificate; LPWSTR pszDeviceId; LPWSTR pszIdpDomain; LPWSTR pszTenantId; LPWSTR + // pszJoinUserEmail; LPWSTR pszTenantDisplayName; LPWSTR pszMdmEnrollmentUrl; LPWSTR pszMdmTermsOfUseUrl; LPWSTR pszMdmComplianceUrl; + // LPWSTR pszUserSettingSyncUrl; DSREG_USER_INFO *pUserInfo; } DSREG_JOIN_INFO, *PDSREG_JOIN_INFO; + [PInvokeData("lmjoin.h", MSDNShortId = "9B0F7BE3-BDCD-437E-9157-9A646A2A20E2")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + public class DSREG_JOIN_INFO : SafeHANDLE + { + /// An enumeration value that specifies the type of the join. + public DSREG_JOIN_TYPE joinType; + + /// + /// Representations of the certification for the join. This is a pointer to CERT_CONTEXT structure which can be found in Vanara.PInvoke.Cryptography. + /// + public IntPtr pJoinCertificate; + + /// The PSZ device identifier + public string pszDeviceId; + + /// A string that represents Azure Active Directory (Azure AD). + public string pszIdpDomain; + + /// The identifier of the joined Azure AD tenant. + public string pszTenantId; + + /// The email address for the joined account. + public string pszJoinUserEmail; + + /// The display name for the joined account. + public string pszTenantDisplayName; + + /// The URL to use to enroll in the Mobile Device Management (MDM) service. + public string pszMdmEnrollmentUrl; + + /// The URL that provides information about the terms of use for the MDM service. + public string pszMdmTermsOfUseUrl; + + /// The URL that provides information about compliance for the MDM service. + public string pszMdmComplianceUrl; + + /// The URL for synchronizing user settings. + public string pszUserSettingSyncUrl; + + /// Information about the user account that was used to join a device to Azure AD. + public IntPtr _pUserInfo; + + /// Information about the user account that was used to join a device to Azure AD. + public DSREG_USER_INFO pUserInfo => _pUserInfo.ToStructure(); + + /// + /// Internal method that actually releases the handle. This is called by + /// for valid handles and afterwards zeros the handle. + /// + /// true to indicate successful release of the handle; false otherwise. + protected override bool InternalReleaseHandle() { NetFreeAadJoinInformation(handle); return true; } + } + } +} \ No newline at end of file diff --git a/PInvoke/NetApi32/LmRemUtl.cs b/PInvoke/NetApi32/LmRemUtl.cs new file mode 100644 index 00000000..7682ae23 --- /dev/null +++ b/PInvoke/NetApi32/LmRemUtl.cs @@ -0,0 +1,230 @@ +using System; +using System.Runtime.InteropServices; + +namespace Vanara.PInvoke +{ + public static partial class NetApi32 + { + /// + /// A set of bit flags indicating the features of interest in OptionsWanted or features supported OptionsSupported in . + /// + [PInvokeData("lmremutl.h", MSDNShortId = "e807489a-250e-4d4c-adb6-eff8ac30603b")] + [Flags] + public enum RemoteSupportFlags : uint + { + /// Requests Remote Administration Protocol support. + SUPPORTS_REMOTE_ADMIN_PROTOCOL = 0x00000002, + + /// Requests RPC support. + SUPPORTS_RPC = 0x00000004, + + /// Requests Security Account Manager (SAM) support. + SUPPORTS_SAM_PROTOCOL = 0x00000008, + + /// Requests Unicode standard support. + SUPPORTS_UNICODE = 0x00000010, + + /// + /// Requests support for the first three values listed in this table. If UNICODE is defined by the calling application, requests + /// the four features listed previously. + /// + SUPPORTS_LOCAL = 0x00000020, + + /// Requests all supported options. + SUPPORTS_ANY = 0xFFFFFFFF, + } + + /// + /// The NetRemoteComputerSupports function queries the redirector to retrieve the optional features the remote system + /// supports. Features include Unicode, Remote Procedure Call (RPC), and Remote Administration Protocol support. The function + /// establishes a network connection if one does not exist. + /// + /// + /// Pointer to a constant string that specifies the name of the remote server to query. If this parameter is NULL, the local + /// computer is used. + /// + /// + /// + /// Specifies a value that contains a set of bit flags indicating the features of interest. This parameter must be at least one of + /// the following values. + /// + /// + /// + /// Value + /// Meaning + /// + /// + /// SUPPORTS_REMOTE_ADMIN_PROTOCOL + /// Requests Remote Administration Protocol support. + /// + /// + /// SUPPORTS_RPC + /// Requests RPC support. + /// + /// + /// SUPPORTS_SAM_PROTOCOL + /// Requests Security Account Manager (SAM) support. + /// + /// + /// SUPPORTS_UNICODE + /// Requests Unicode standard support. + /// + /// + /// SUPPORTS_LOCAL + /// + /// Requests support for the first three values listed in this table. If UNICODE is defined by the calling application, requests the + /// four features listed previously. + /// + /// + /// + /// + /// + /// + /// Pointer to a value that receives a set of bit flags. The flags indicate which features specified by the OptionsWanted parameter + /// are implemented on the computer specified by the UncServerName parameter. (All other bits are set to zero.) + /// + /// The value of this parameter is valid only when the NetRemoteComputerSupports function returns NERR_Success. + /// + /// + /// If the function succeeds, the return value is NERR_Success. + /// If the function fails, the return value can be one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_INVALID_PARAMETER + /// Either the OptionsWanted parameter or the OptionsSupported parameter is NULL; both parameters are required. + /// + /// + /// ERROR_NOT_ENOUGH_MEMORY + /// Insufficient memory is available. + /// + /// + /// + /// No special group membership is required to successfully execute the NetRemoteComputerSupports function. + // https://docs.microsoft.com/en-us/windows/desktop/api/lmremutl/nf-lmremutl-netremotecomputersupports NET_API_STATUS + // NET_API_FUNCTION NetRemoteComputerSupports( IN LPCWSTR UncServerName, IN DWORD OptionsWanted, OUT LPDWORD OptionsSupported ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("lmremutl.h", MSDNShortId = "e807489a-250e-4d4c-adb6-eff8ac30603b")] + public static extern Win32Error NetRemoteComputerSupports([MarshalAs(UnmanagedType.LPWStr), Optional] string UncServerName, RemoteSupportFlags OptionsWanted, out RemoteSupportFlags OptionsSupported); + + /// The NetRemoteTOD function returns the time of day information from a specified server. + /// + /// Pointer to a constant string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If + /// this parameter is NULL, the local computer is used. + /// + /// + /// Pointer to the address that receives the TIME_OF_DAY_INFO information structure. This buffer is allocated by the system and must + /// be freed using the NetApiBufferFree function. + /// + /// + /// If the function succeeds, the return value is NERR_Success. + /// If the function fails, the return value is a system error code. For a list of error codes, see System Error Codes. + /// + /// + /// No special group membership is required to successfully execute the NetRemoteTOD function. + /// Examples + /// + /// The following code sample demonstrates how to retrieve and print the current date and time with a call to the NetRemoteTOD + /// function. To do this, the sample uses the TIME_OF_DAY_INFO structure. Finally, the sample frees the memory allocated for the + /// information buffer. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmremutl/nf-lmremutl-netremotetod NET_API_STATUS NET_API_FUNCTION + // NetRemoteTOD( LPCWSTR UncServerName, LPBYTE *BufferPtr ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("lmremutl.h", MSDNShortId = "5a935e09-f188-4ee1-b998-c67488475baa")] + public static extern Win32Error NetRemoteTOD([MarshalAs(UnmanagedType.LPWStr), Optional] string UncServerName, out SafeNetApiBuffer BufferPtr); + + /// The TIME_OF_DAY_INFO structure contains information about the time of day from a remote server. + // https://docs.microsoft.com/en-us/windows/desktop/api/lmremutl/ns-lmremutl-_time_of_day_info typedef struct _TIME_OF_DAY_INFO { + // DWORD tod_elapsedt; DWORD tod_msecs; DWORD tod_hours; DWORD tod_mins; DWORD tod_secs; DWORD tod_hunds; LONG tod_timezone; DWORD + // tod_tinterval; DWORD tod_day; DWORD tod_month; DWORD tod_year; DWORD tod_weekday; } TIME_OF_DAY_INFO, *PTIME_OF_DAY_INFO, *LPTIME_OF_DAY_INFO; + [PInvokeData("lmremutl.h", MSDNShortId = "bf89f071-5c04-40c2-a7b7-4e59fc9eaa02")] + [StructLayout(LayoutKind.Sequential)] + public struct TIME_OF_DAY_INFO + { + /// + /// Type: DWORD + /// The number of seconds since 00:00:00, January 1, 1970, GMT. + /// + public uint tod_elapsedt; + + /// + /// Type: DWORD + /// The number of milliseconds from an arbitrary starting point (system reset). + /// + /// Typically, this member is read twice, once when the process begins and again at the end. To determine the elapsed time + /// between the process's start and finish, you can subtract the first value from the second. + /// + /// + public uint tod_msecs; + + /// + /// Type: DWORD + /// The current hour. Valid values are 0 through 23. + /// + public uint tod_hours; + + /// + /// Type: DWORD + /// The current minute. Valid values are 0 through 59. + /// + public uint tod_mins; + + /// + /// Type: DWORD + /// The current second. Valid values are 0 through 59. + /// + public uint tod_secs; + + /// + /// Type: DWORD + /// The current hundredth second (0.01 second). Valid values are 0 through 99. + /// + public uint tod_hunds; + + /// + /// Type: LONG + /// + /// The time zone of the server. This value is calculated, in minutes, from Greenwich Mean Time (GMT). For time zones west of + /// Greenwich, the value is positive; for time zones east of Greenwich, the value is negative. A value of –1 indicates that the + /// time zone is undefined. + /// + /// + public int tod_timezone; + + /// + /// Type: DWORD + /// The time interval for each tick of the clock. Each integral integer represents one ten-thousandth second (0.0001 second). + /// + public uint tod_tinterval; + + /// + /// Type: DWORD + /// The day of the month. Valid values are 1 through 31. + /// + public uint tod_day; + + /// + /// Type: DWORD + /// The month of the year. Valid values are 1 through 12. + /// + public uint tod_month; + + /// + /// Type: DWORD + /// The year. + /// + public uint tod_year; + + /// + /// Type: DWORD + /// The day of the week. Valid values are 0 through 6, where 0 is Sunday, 1 is Monday, and so on. + /// + public uint tod_weekday; + } + } +} \ No newline at end of file diff --git a/PInvoke/NetApi32/Lm.cs b/PInvoke/NetApi32/LmServer.cs similarity index 87% rename from PInvoke/NetApi32/Lm.cs rename to PInvoke/NetApi32/LmServer.cs index 521c73c2..24444196 100644 --- a/PInvoke/NetApi32/Lm.cs +++ b/PInvoke/NetApi32/LmServer.cs @@ -1,8 +1,5 @@ using System; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Security; -using Vanara.Extensions; namespace Vanara.PInvoke { @@ -14,13 +11,11 @@ namespace Vanara.PInvoke /// PreferedMaximumLength parameter. When specified as an input parameter, this value indicates that the method MUST allocate as much /// space as the data requires. /// - public const int MAX_PREFERRED_LENGTH = -1; + public const uint MAX_PREFERRED_LENGTH = unchecked((uint)-1); - /// - /// Filters used by . - /// + /// Filters used by . [Flags] - [PInvokeData("lm.h", MSDNShortId = "aa370623")] + [PInvokeData("lmserver.h", MSDNShortId = "aa370623")] public enum NetServerEnumFilter : uint { /// All workstations. @@ -126,6 +121,8 @@ namespace Vanara.PInvoke SV_TYPE_ALL = 0xFFFFFFFF, } + [Flags] + [PInvokeData("lmserver.h")] public enum SERVER_TRANSPORT_FLAGS : uint { /// @@ -158,7 +155,7 @@ namespace Vanara.PInvoke } /// The information level to use for platform-specific information. - [PInvokeData("lm.h", MSDNShortId = "aa370903")] + [PInvokeData("lmserver.h", MSDNShortId = "aa370903")] public enum ServerPlatform { /// The MS-DOS platform. @@ -177,20 +174,8 @@ namespace Vanara.PInvoke PLATFORM_ID_VMS = 700 } - /// - /// The NetApiBufferFree function frees the memory that the NetApiBufferAllocate function allocates. Applications should also call - /// NetApiBufferFree to free the memory that other network management functions use internally to return information. - /// - /// - /// A pointer to a buffer returned previously by another network management function or memory allocated by calling the - /// NetApiBufferAllocate function. - /// - /// - /// If the function succeeds, the return value is NERR_Success. If the function fails, the return value is a system error code. - /// - [DllImport(Lib.NetApi32, ExactSpelling = true), SuppressUnmanagedCodeSecurity] - [PInvokeData("lm.h", MSDNShortId = "aa370304")] - public static extern Win32Error NetApiBufferFree(IntPtr pBuf); + /// Inherit from this interface for any implementation of the SERVER_INFO_XXXX structures to use the helper functions. + public interface INetServerInfo { } /// /// @@ -338,26 +323,18 @@ namespace Vanara.PInvoke public static extern Win32Error NetServerComputerNameDel([Optional] string ServerName, string EmulatedServerName); /// - /// /// The NetServerDiskEnum function retrieves a list of disk drives on a server. The function returns an array of /// three-character strings (a drive letter, a colon, and a terminating null character). - /// /// /// - /// /// A pointer to a string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this /// parameter is NULL, the local computer is used. - /// - /// - /// - /// The level of information required. A value of zero is the only valid level. /// + /// The level of information required. A value of zero is the only valid level. /// - /// /// A pointer to the buffer that receives the data. The data is an array of three-character strings (a drive letter, a colon, and a /// terminating null character). This buffer is allocated by the system and must be freed using the NetApiBufferFree function. Note /// that you must free the buffer even if the function fails with ERROR_MORE_DATA. - /// /// /// /// @@ -368,21 +345,15 @@ namespace Vanara.PInvoke /// /// Note This parameter is currently ignored. /// - /// - /// A pointer to a value that receives the count of elements actually enumerated. - /// + /// A pointer to a value that receives the count of elements actually enumerated. /// - /// /// A pointer to a value that receives the total number of entries that could have been enumerated from the current resume position. /// Note that applications should consider this value only as a hint. - /// /// /// - /// /// A pointer to a value that contains a resume handle which is used to continue an existing server disk search. The handle should be /// zero on the first call and left unchanged for subsequent calls. If the resume_handle parameter is a NULL pointer, then no /// resume handle is stored. - /// /// /// /// If the function succeeds, the return value is NERR_Success. @@ -441,11 +412,27 @@ namespace Vanara.PInvoke // LPDWORD resume_handle ); [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("lmserver.h", MSDNShortId = "56c981f4-7a1d-4465-bd7b-5996222c4210")] - public static extern Win32Error NetServerDiskEnum([Optional] string servername, int level, out SafeNetApiBuffer bufptr, int prefmaxlen, out int entriesread, out int totalentries, ref uint resume_handle); + public static extern Win32Error NetServerDiskEnum([Optional] string servername, [Optional] uint level, out SafeNetApiBuffer bufptr, uint prefmaxlen, out uint entriesread, out uint totalentries, ref uint resume_handle); - /// The NetServerEnum function lists all servers of the specified type that are visible in a domain. - /// Reserved; must be NULL. - /// The information level of the data requested. + /// The NetServerEnum function lists all servers of the specified type that are visible in a domain. + /// Reserved; must be NULL. + /// + /// The information level of the data requested. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// 100 + /// Return server names and platform information. The bufptr parameter points to an array of SERVER_INFO_100 structures. + /// + /// + /// 101 + /// Return server names, types, and associated data. The bufptr parameter points to an array of SERVER_INFO_101 structures. + /// + /// + /// /// /// A pointer to the buffer that receives the data. The format of this data depends on the value of the level parameter. This buffer /// is allocated by the system and must be freed using the NetApiBufferFree function. Note that you must free the buffer even if the @@ -462,18 +449,254 @@ namespace Vanara.PInvoke /// A pointer to a value that receives the total number of visible servers and workstations on the network. Note that applications /// should consider this value only as a hint. /// - /// A value that filters the server entries to return from the enumeration. + /// + /// + /// A value that filters the server entries to return from the enumeration. This parameter can be a combination of the following + /// values defined in the Lmserver.h header file. + /// + /// + /// + /// Value + /// Meaning + /// + /// + /// SV_TYPE_WORKSTATION 0x00000001 + /// All workstations. + /// + /// + /// SV_TYPE_SERVER 0x00000002 + /// All computers that run the Server service. + /// + /// + /// SV_TYPE_SQLSERVER 0x00000004 + /// Any server that runs an instance of Microsoft SQL Server. + /// + /// + /// SV_TYPE_DOMAIN_CTRL 0x00000008 + /// A server that is primary domain controller. + /// + /// + /// SV_TYPE_DOMAIN_BAKCTRL 0x00000010 + /// Any server that is a backup domain controller. + /// + /// + /// SV_TYPE_TIME_SOURCE 0x00000020 + /// Any server that runs the Timesource service. + /// + /// + /// SV_TYPE_AFP 0x00000040 + /// Any server that runs the Apple Filing Protocol (AFP) file service. + /// + /// + /// SV_TYPE_NOVELL 0x00000080 + /// Any server that is a Novell server. + /// + /// + /// SV_TYPE_DOMAIN_MEMBER 0x00000100 + /// Any computer that is LAN Manager 2.x domain member. + /// + /// + /// SV_TYPE_PRINTQ_SERVER 0x00000200 + /// Any computer that shares a print queue. + /// + /// + /// SV_TYPE_DIALIN_SERVER 0x00000400 + /// Any server that runs a dial-in service. + /// + /// + /// SV_TYPE_XENIX_SERVER 0x00000800 + /// Any server that is a Xenix server. + /// + /// + /// SV_TYPE_SERVER_UNIX 0x00000800 + /// Any server that is a UNIX server. This is the same as the SV_TYPE_XENIX_SERVER. + /// + /// + /// SV_TYPE_NT 0x00001000 + /// A workstation or server. + /// + /// + /// SV_TYPE_WFW 0x00002000 + /// Any computer that runs Windows for Workgroups. + /// + /// + /// SV_TYPE_SERVER_MFPN 0x00004000 + /// Any server that runs the Microsoft File and Print for NetWare service. + /// + /// + /// SV_TYPE_SERVER_NT 0x00008000 + /// Any server that is not a domain controller. + /// + /// + /// SV_TYPE_POTENTIAL_BROWSER 0x00010000 + /// Any computer that can run the browser service. + /// + /// + /// SV_TYPE_BACKUP_BROWSER 0x00020000 + /// A computer that runs a browser service as backup. + /// + /// + /// SV_TYPE_MASTER_BROWSER 0x00040000 + /// A computer that runs the master browser service. + /// + /// + /// SV_TYPE_DOMAIN_MASTER 0x00080000 + /// A computer that runs the domain master browser. + /// + /// + /// SV_TYPE_SERVER_OSF 0x00100000 + /// A computer that runs OSF/1. + /// + /// + /// SV_TYPE_SERVER_VMS 0x00200000 + /// A computer that runs Open Virtual Memory System (VMS). + /// + /// + /// SV_TYPE_WINDOWS 0x00400000 + /// A computer that runs Windows. + /// + /// + /// SV_TYPE_DFS 0x00800000 + /// A computer that is the root of Distributed File System (DFS) tree. + /// + /// + /// SV_TYPE_CLUSTER_NT 0x01000000 + /// Server clusters available in the domain. + /// + /// + /// SV_TYPE_TERMINALSERVER 0x02000000 + /// A server running the Terminal Server service. + /// + /// + /// SV_TYPE_CLUSTER_VS_NT 0x04000000 + /// Cluster virtual servers available in the domain. Windows 2000: This value is not supported. + /// + /// + /// SV_TYPE_DCE 0x10000000 + /// A computer that runs IBM Directory and Security Services (DSS) or equivalent. + /// + /// + /// SV_TYPE_ALTERNATE_XPORT 0x20000000 + /// A computer that over an alternate transport. + /// + /// + /// SV_TYPE_LOCAL_LIST_ONLY 0x40000000 + /// Any computer maintained in a list by the browser. See the following Remarks section. + /// + /// + /// SV_TYPE_DOMAIN_ENUM 0x80000000 + /// The primary domain. + /// + /// + /// SV_TYPE_ALL 0xFFFFFFFF + /// All servers. This is a convenience that will return all possible servers. + /// + /// + /// /// + /// /// A pointer to a constant string that specifies the name of the domain for which a list of servers is to be returned. The domain - /// name must be a NetBIOS domain name (for example, microsoft). The NetServerEnum function does not support DNS-style names (for - /// example, microsoft.com). If this parameter is NULL, the primary domain is implied. + /// name must be a NetBIOS domain name (for example, microsoft). The NetServerEnum function does not support DNS-style names + /// (for example, microsoft.com). + /// + /// If this parameter is NULL, the primary domain is implied. /// /// Reserved; must be set to zero. - /// If the function succeeds, the return value is NERR_Success. - [DllImport(Lib.NetApi32, ExactSpelling = true, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity] - [PInvokeData("lm.h", MSDNShortId = "aa370623")] - public static extern Win32Error NetServerEnum([Optional] string servernane, int level, out SafeNetApiBuffer bufptr, int prefmaxlen, out int entriesread, - out int totalentries, NetServerEnumFilter servertype, string domain, [Optional] IntPtr resume_handle); + /// + /// If the function succeeds, the return value is NERR_Success. + /// If the function fails, the return value can be one of the following error codes: + /// + /// + /// Return code/value + /// Description + /// + /// + /// ERROR_ACCESS_DENIED 5 + /// Access was denied. + /// + /// + /// ERROR_INVALID_PARAMETER 87 + /// The parameter is incorrect. + /// + /// + /// ERROR_MORE_DATA 234 + /// More entries are available. Specify a large enough buffer to receive all entries. + /// + /// + /// ERROR_NO_BROWSER_SERVERS_FOUND 6118 + /// No browser servers found. + /// + /// + /// ERROR_NOT_SUPPORTED 50 + /// The request is not supported. + /// + /// + /// NERR_RemoteErr 2127 + /// A remote error occurred with no data returned by the server. + /// + /// + /// NERR_ServerNotStarted 2114 + /// The server service is not started. + /// + /// + /// NERR_ServiceNotInstalled 2184 + /// The service has not been started. + /// + /// + /// NERR_WkstaNotStarted 2138 + /// + /// The Workstation service has not been started. The local workstation service is used to communicate with a downlevel remote server. + /// + /// + /// + /// + /// + /// + /// The NetServerEnum function is used to list all servers of the specified type that are visible in a domain. For example, an + /// application can call NetServerEnum to list all domain controllers only or all servers that run instances of SQL server only. + /// + /// + /// An application combine the bit masks for various server types in the servertype parameter to list several types. For example, a + /// value of SV_TYPE_WORKSTATION | SVTYPE_SERVER (0x00000003) combines the bit masks for SV_TYPE_WORKSTATION (0x00000001) and + /// SV_TYPE_SERVER (0x00000002). + /// + /// If you require more information for a specific server, call the WNetEnumResource function. + /// No special group membership is required to successfully execute the NetServerEnum function. + /// + /// If you specify the value SV_TYPE_LOCAL_LIST_ONLY, the NetServerEnum function returns the list of servers that the browser + /// maintains internally. This has meaning only on the master browser (or on a computer that has been the master browser in the + /// past). The master browser is the computer that currently has rights to determine which computers can be servers or workstations + /// on the network. + /// + /// + /// If there are no servers found that match the types specified in the servertype parameter, the NetServerEnum function + /// returns the bufptr parameter as NULL and DWORD values pointed to by the entriesread and totalentries parameters are set to zero. + /// + /// + /// The NetServerEnum function depends on the browser service being installed and running. If no browser servers are found, + /// then NetServerEnum fails with ERROR_NO_BROWSER_SERVERS_FOUND. + /// + /// + /// If you are programming for Active Directory, you may be able to call certain Active Directory Service Interface (ADSI) methods to + /// achieve the same function you can achieve by calling the network management server functions. For more information, see IADsComputer. + /// + /// Examples + /// + /// The following code sample demonstrates how to list all servers that are visible in a domain with a call to the + /// NetServerEnum function. The sample calls NetServerEnum, specifying information level 101 ( SERVER_INFO_101). If any + /// servers are found, the sample code loops through the entries and prints the retrieved data. If the server is a domain controller, + /// it identifies the server as either a primary domain controller (PDC) or a backup domain controller (BDC). The sample also prints + /// the total number of entries available and a hint about the number of entries actually enumerated, warning the user if all entries + /// were not enumerated. Finally, the sample frees the memory allocated for the information buffer. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmserver/nf-lmserver-netserverenum NET_API_STATUS NET_API_FUNCTION + // NetServerEnum( IN LMCSTR servername, IN DWORD level, OUT LPBYTE *bufptr, IN DWORD prefmaxlen, OUT LPDWORD entriesread, OUT LPDWORD + // totalentries, IN DWORD servertype, IN LMCSTR domain, IN OUT LPDWORD resume_handle ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] + [PInvokeData("lmserver.h", MSDNShortId = "10012a87-805e-4817-9f09-9e5632b1fa09")] + public static extern Win32Error NetServerEnum([Optional] string servername, uint level, out SafeNetApiBuffer bufptr, uint prefmaxlen, out uint entriesread, + out uint totalentries, NetServerEnumFilter servertype, [Optional] string domain, [Optional] IntPtr resume_handle); /// The NetServerGetInfo function retrieves current configuration information for the specified server. /// @@ -487,7 +710,7 @@ namespace Vanara.PInvoke /// /// If the function succeeds, the return value is NERR_Success. [DllImport(Lib.NetApi32, ExactSpelling = true, CharSet = CharSet.Unicode)] - [PInvokeData("lm.h", MSDNShortId = "aa370624")] + [PInvokeData("lmserver.h", MSDNShortId = "aa370624")] public static extern Win32Error NetServerGetInfo([Optional] string servername, int level, out SafeNetApiBuffer bufptr); /// @@ -1093,13 +1316,11 @@ namespace Vanara.PInvoke public static extern Win32Error NetServerTransportDel([Optional] string servername, int level, IntPtr bufptr); /// - /// The NetServerTransportEnum function supplies information about transport protocols that are managed by the server. + /// The NetServerTransportEnum function supplies information about transport protocols that are managed by the server. /// /// - /// /// Pointer to a string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this /// parameter is NULL, the local computer is used. - /// /// /// /// Specifies the information level of the data. This parameter can be one of the following values. @@ -1125,30 +1346,22 @@ namespace Vanara.PInvoke /// /// /// - /// /// Pointer to the buffer that receives the data. The format of this data depends on the value of the level parameter. This buffer is /// allocated by the system and must be freed using the NetApiBufferFree function. Note that you must free the buffer even if the /// function fails with ERROR_MORE_DATA. - /// /// /// - /// /// Specifies the preferred maximum length of returned data, in bytes. If you specify MAX_PREFERRED_LENGTH, the function allocates /// the amount of memory required for the data. If you specify another value in this parameter, it can restrict the number of bytes /// that the function returns. If the buffer size is insufficient to hold all entries, the function returns ERROR_MORE_DATA. For more /// information, see Network Management Function Buffers and Network Management Function Buffer Lengths. - /// - /// - /// - /// Pointer to a value that receives the count of elements actually enumerated. /// + /// Pointer to a value that receives the count of elements actually enumerated. /// - /// /// Pointer to a value that receives the total number of entries that could have been enumerated from the current resume position. /// Note that applications should consider this value only as a hint. - /// /// - /// + /// The resume handle. /// /// If the function succeeds, the return value is NERR_Success. /// If the function fails, the return value can be one of the following error codes. @@ -1193,12 +1406,12 @@ namespace Vanara.PInvoke // totalentries, LPDWORD resume_handle ); [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("lmserver.h", MSDNShortId = "db42ac44-d70d-4b89-882a-6ac83fd611fd")] - public static extern Win32Error NetServerTransportEnum([Optional] string servername, int level, out SafeNetApiBuffer bufptr, int prefmaxlen, out int entriesread, out int totalentries, ref uint resume_handle); + public static extern Win32Error NetServerTransportEnum([Optional] string servername, int level, out SafeNetApiBuffer bufptr, uint prefmaxlen, out uint entriesread, out uint totalentries, ref uint resume_handle); /// The SERVER_INFO_100 structure contains information about the specified server, including the name and platform. /// [StructLayout(LayoutKind.Sequential)] - [PInvokeData("lm.h", MSDNShortId = "aa370897")] + [PInvokeData("lmserver.h", MSDNShortId = "aa370897")] public struct SERVER_INFO_100 : INetServerInfo { /// The information level to use for platform-specific information. @@ -1215,7 +1428,7 @@ namespace Vanara.PInvoke /// /// [StructLayout(LayoutKind.Sequential)] - [PInvokeData("lm.h", MSDNShortId = "aa370903")] + [PInvokeData("lmserver.h", MSDNShortId = "aa370903")] public struct SERVER_INFO_101 : INetServerInfo { /// The information level to use for platform-specific information. @@ -1256,7 +1469,7 @@ namespace Vanara.PInvoke /// /// [StructLayout(LayoutKind.Sequential)] - [PInvokeData("lm.h", MSDNShortId = "aa370904")] + [PInvokeData("lmserver.h", MSDNShortId = "aa370904")] public struct SERVER_INFO_102 : INetServerInfo { /// The information level to use for platform-specific information. @@ -2316,40 +2529,40 @@ namespace Vanara.PInvoke public byte[] svti3_password; } - /// Provides a to a buffer that releases a created handle at disposal using NetApiBufferFree. - public class SafeNetApiBuffer : SafeHANDLE - { - /// Initializes a new instance of the class and assigns an existing handle. - /// An object that represents the pre-existing handle to use. - /// - /// to reliably release the handle during the finalization phase; otherwise, (not recommended). - /// - public SafeNetApiBuffer(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { } - - /// Initializes a new instance of the class. - private SafeNetApiBuffer() : base() { } - - /// Returns an extracted structure from this buffer. - /// The structure type to extract. - /// Extracted structure or default(T) if the buffer is invalid. - public T ToStructure() where T : struct => IsInvalid ? default : (T)Marshal.PtrToStructure(handle, typeof(T)); - - /// - public override string ToString() => Extensions.StringHelper.GetString(handle); - - /// Extracts a list of structures. - /// The type of the structure. - /// The count of structures in the list. - /// The list of structures. - public IEnumerable ToIEnum(int count) => handle.ToIEnum(count); - - /// Extracts a list of strings. Used by . - /// The number of elements in the list. - /// The list of strings. - public IEnumerable ToStringEnum(int count) => handle.ToStringEnum(count); - - /// - protected override bool InternalReleaseHandle() => NetApiBufferFree(handle) == 0; - } + /* + SERVER_INFO_1005 structure + SERVER_INFO_1010 structure + SERVER_INFO_1016 structure + SERVER_INFO_1017 structure + SERVER_INFO_1018 structure + SERVER_INFO_1107 structure + SERVER_INFO_1501 structure + SERVER_INFO_1502 structure + SERVER_INFO_1503 structure + SERVER_INFO_1506 structure + SERVER_INFO_1509 structure + SERVER_INFO_1510 structure + SERVER_INFO_1511 structure + SERVER_INFO_1512 structure + SERVER_INFO_1513 structure + SERVER_INFO_1515 structure + SERVER_INFO_1516 structure + SERVER_INFO_1518 structure + SERVER_INFO_1523 structure + SERVER_INFO_1528 structure + SERVER_INFO_1529 structure + SERVER_INFO_1530 structure + SERVER_INFO_1533 structure + SERVER_INFO_1536 structure + SERVER_INFO_1538 structure + SERVER_INFO_1539 structure + SERVER_INFO_1540 structure + SERVER_INFO_1541 structure + SERVER_INFO_1542 structure + SERVER_INFO_1544 structure + SERVER_INFO_1550 structure + SERVER_INFO_1552 structure + SERVER_INFO_502 structure + SERVER_INFO_503 structure*/ } } \ No newline at end of file diff --git a/PInvoke/NetApi32/LmShare.cs b/PInvoke/NetApi32/LmShare.cs index 77f167d8..008b09f5 100644 --- a/PInvoke/NetApi32/LmShare.cs +++ b/PInvoke/NetApi32/LmShare.cs @@ -10,6 +10,7 @@ namespace Vanara.PInvoke { /// Flags used by SESSION_INFO_XX structures [PInvokeData("lmshare.h", MSDNShortId = "a86a00ae-f60a-4b12-a9ac-4b96f9abd6a2")] + [Flags] public enum SESS { /// The user specified by the sesi502_username member established the session using a guest account. @@ -20,6 +21,7 @@ namespace Vanara.PInvoke } [PInvokeData("lmshare.h", MSDNShortId = "9fb3e0ae-76b5-4432-80dd-f3361738aa7c")] + [Flags] public enum SHI1005_FLAGS { /// The specified share is present in a Dfs tree structure. This flag cannot be set with NetShareSetInfo. @@ -140,64 +142,50 @@ namespace Vanara.PInvoke /// is more than one user using this connection, then it is possible to get more than one structure for the same connection, but with /// a different user name. /// - /// - /// + /// /// Pointer to a string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this /// parameter is NULL, the local computer is used. /// - /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE is defined. - /// - /// - /// + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE is defined. + /// /// Pointer to a string that specifies a share name or computer name for the connections of interest. If it is a share name, then all /// the connections made to that share name are listed. If it is a computer name (for example, it starts with two backslash /// characters), then NetConnectionEnum lists all connections made from that computer to the server specified. /// - /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE is defined. - /// - /// - /// Specifies the information level of the data. This parameter can be one of the following values. + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE is defined. + /// Specifies the information level of the data. This parameter can be one of the following values. /// - /// - /// Value - /// Meaning - /// - /// - /// 0 - /// Return connection identifiers. The bufptr parameter is a pointer to an array of CONNECTION_INFO_0 structures. - /// - /// - /// 1 - /// + /// + /// Value + /// Meaning + /// + /// + /// 0 + /// Return connection identifiers. The bufptr parameter is a pointer to an array of CONNECTION_INFO_0 structures. + /// + /// + /// 1 + /// /// Return connection identifiers and connection information. The bufptr parameter is a pointer to an array of CONNECTION_INFO_1 structures. /// - /// - /// - /// - /// - /// + /// + /// + /// /// Pointer to the address of the buffer that receives the information. The format of this data depends on the value of the level parameter. /// /// /// This buffer is allocated by the system and must be freed using the NetApiBufferFree function. Note that you must free the buffer /// even if the function fails with ERROR_MORE_DATA. - /// - /// - /// - /// Specifies the preferred maximum length of returned data, in bytes. If you specify MAX_PREFERRED_LENGTH, the function + /// + /// Specifies the preferred maximum length of returned data, in bytes. If you specify MAX_PREFERRED_LENGTH, the function /// allocates the amount of memory required for the data. If you specify another value in this parameter, it can restrict the number /// of bytes that the function returns. If the buffer size is insufficient to hold all entries, the function returns - /// ERROR_MORE_DATA. For more information, see Network Management Function Buffers and Network Management Function Buffer Lengths. - /// + /// ERROR_MORE_DATA. For more information, see Network Management Function Buffers and Network Management Function Buffer Lengths. /// Pointer to a value that receives the count of elements actually enumerated. - /// - /// Pointer to a value that receives the total number of entries that could have been enumerated from the current resume position. - /// Note that applications should consider this value only as a hint. - /// - /// - /// Pointer to a value that contains a resume handle which is used to continue an existing connection search. The handle should be - /// zero on the first call and left unchanged for subsequent calls. If this parameter is NULL, then no resume handle is stored. - /// + /// Pointer to a value that receives the total number of entries that could have been enumerated from the current resume position. + /// Note that applications should consider this value only as a hint. + /// Pointer to a value that contains a resume handle which is used to continue an existing connection search. The handle should be + /// zero on the first call and left unchanged for subsequent calls. If this parameter is NULL, then no resume handle is stored. /// /// If the function succeeds, the return value is NERR_Success. /// If the function fails, the return value is a system error code. For a list of error codes, see System Error Codes. @@ -221,7 +209,7 @@ namespace Vanara.PInvoke // totalentries, LPDWORD resume_handle ); [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("lmshare.h", MSDNShortId = "935ac6e9-78e0-42ae-a454-0a14b03ddc21")] - public static extern Win32Error NetConnectionEnum(string servername, string qualifier, uint level, out SafeNetApiBuffer bufptr, + public static extern Win32Error NetConnectionEnum([Optional] string servername, string qualifier, uint level, out SafeNetApiBuffer bufptr, uint prefmaxlen, out uint entriesread, out uint totalentries, ref uint resume_handle); /// @@ -380,7 +368,7 @@ namespace Vanara.PInvoke // totalentries, PDWORD_PTR resume_handle ); [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("lmshare.h", MSDNShortId = "1375b337-efb0-4be1-94f7-473456a825b5")] - public static extern Win32Error NetFileEnum(string servername, string basepath, string username, uint level, out SafeNetApiBuffer bufptr, + public static extern Win32Error NetFileEnum([Optional] string servername, [Optional] string basepath, [Optional] string username, uint level, out SafeNetApiBuffer bufptr, uint prefmaxlen, out uint entriesread, out uint totalentries, ref IntPtr resume_handle); /// Retrieves information about a particular opening of a server resource. @@ -667,7 +655,7 @@ namespace Vanara.PInvoke // entriesread, LPDWORD totalentries, LPDWORD resume_handle ); [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("lmshare.h", MSDNShortId = "5923a8cc-bf7a-4ffa-b089-fd7f26ee42d2")] - public static extern Win32Error NetSessionEnum(string servername, string UncClientName, string username, uint level, out SafeNetApiBuffer bufptr, + public static extern Win32Error NetSessionEnum([Optional] string servername, string UncClientName, [Optional] string username, uint level, out SafeNetApiBuffer bufptr, uint prefmaxlen, out uint entriesread, out uint totalentries, ref uint resume_handle); /// Retrieves information about a session established between a particular server and workstation. @@ -786,7 +774,7 @@ namespace Vanara.PInvoke // NetSessionGetInfo( LMSTR servername, LMSTR UncClientName, LMSTR username, DWORD level, LPBYTE *bufptr ); [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("lmshare.h", MSDNShortId = "d44fb8d8-2b64-4268-8603-7784e2c5f2d5")] - public static extern Win32Error NetSessionGetInfo(string servername, string UncClientName, string username, uint level, out SafeNetApiBuffer bufptr); + public static extern Win32Error NetSessionGetInfo([Optional] string servername, string UncClientName, string username, uint level, out SafeNetApiBuffer bufptr); /// Shares a server resource. /// @@ -900,7 +888,7 @@ namespace Vanara.PInvoke // LMSTR servername, DWORD level, LPBYTE buf, LPDWORD parm_err ); [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("lmshare.h", MSDNShortId = "8b51c155-24e8-4d39-b818-eb2d1bb0ee8b")] - public static extern Win32Error NetShareAdd(string servername, uint level, IntPtr buf, out uint parm_err); + public static extern Win32Error NetShareAdd([Optional] string servername, uint level, IntPtr buf, out uint parm_err); /// Checks whether or not a server is sharing a device. /// @@ -994,7 +982,7 @@ namespace Vanara.PInvoke // NetShareCheck( LMSTR servername, LMSTR device, LPDWORD type ); [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("lmshare.h", MSDNShortId = "8453dcd2-5c58-4fe4-9426-0fd51647394d")] - public static extern Win32Error NetShareCheck(string servername, string device, out STYPE type); + public static extern Win32Error NetShareCheck([Optional] string servername, string device, out STYPE type); /// /// Deletes a share name from a server's list of shared resources, disconnecting all connections to the shared resource. @@ -1061,7 +1049,7 @@ namespace Vanara.PInvoke // LMSTR servername, LMSTR netname, DWORD reserved ); [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("lmshare.h", MSDNShortId = "374b8f81-b3d6-4967-bd4a-ffd3fdc3cf7c")] - public static extern Win32Error NetShareDel(string servername, string netname, uint reserved = 0); + public static extern Win32Error NetShareDel([Optional] string servername, string netname, uint reserved = 0); /// /// Deletes a share name from a server's list of shared resources, which disconnects all connections to that share. This function, @@ -1143,7 +1131,7 @@ namespace Vanara.PInvoke // NetShareDelEx( LMSTR servername, DWORD level, LPBYTE buf ); [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("lmshare.h", MSDNShortId = "2461c533-351b-48f4-b660-cb17ac3398fa")] - public static extern Win32Error NetShareDelEx(string servername, uint level, IntPtr buf); + public static extern Win32Error NetShareDelEx([Optional] string servername, uint level, IntPtr buf); /// /// Retrieves information about each shared resource on a server. @@ -1262,7 +1250,7 @@ namespace Vanara.PInvoke // LMSTR servername, DWORD level, LPBYTE *bufptr, DWORD prefmaxlen, LPDWORD entriesread, LPDWORD totalentries, LPDWORD resume_handle ); [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("lmshare.h", MSDNShortId = "9114c54d-3905-4d40-9162-b3ea605f6fcb")] - public static extern Win32Error NetShareEnum(string servername, uint level, out SafeNetApiBuffer bufptr, uint prefmaxlen, + public static extern Win32Error NetShareEnum([Optional] string servername, uint level, out SafeNetApiBuffer bufptr, uint prefmaxlen, out uint entriesread, out uint totalentries, ref uint resume_handle); /// Retrieves information about a particular shared resource on a server. @@ -1401,7 +1389,7 @@ namespace Vanara.PInvoke // NetShareGetInfo( LMSTR servername, LMSTR netname, DWORD level, LPBYTE *bufptr ); [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("lmshare.h", MSDNShortId = "672ea208-4048-4d2f-9606-ee3e2133765b")] - public static extern Win32Error NetShareGetInfo(string servername, string netname, uint level, out SafeNetApiBuffer bufptr); + public static extern Win32Error NetShareGetInfo([Optional] string servername, string netname, uint level, out SafeNetApiBuffer bufptr); /// Sets the parameters of a shared resource. /// @@ -1579,7 +1567,7 @@ namespace Vanara.PInvoke // NetShareSetInfo( LMSTR servername, LMSTR netname, DWORD level, LPBYTE buf, LPDWORD parm_err ); [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("lmshare.h", MSDNShortId = "216b0b78-87da-4734-ad07-5ad1c9edf494")] - public static extern Win32Error NetShareSetInfo(string servername, string netname, uint level, IntPtr buf, out uint parm_err); + public static extern Win32Error NetShareSetInfo([Optional] string servername, string netname, uint level, IntPtr buf, out uint parm_err); /// Contains the identification number of a connection. // https://docs.microsoft.com/en-us/windows/desktop/api/lmshare/ns-lmshare-_connection_info_0 typedef struct _CONNECTION_INFO_0 { diff --git a/PInvoke/NetApi32/LmUse.cs b/PInvoke/NetApi32/LmUse.cs new file mode 100644 index 00000000..6c272847 --- /dev/null +++ b/PInvoke/NetApi32/LmUse.cs @@ -0,0 +1,815 @@ +using System; +using System.Runtime.InteropServices; + +namespace Vanara.PInvoke +{ + public static partial class NetApi32 + { + /// A set of bit flags that describe connection behavior and credential handling. + [PInvokeData("lmuse.h", MSDNShortId = "3fb3ad35-f9e5-46ba-b930-fc2ccafd8ee9")] + [Flags] + public enum NetUseFlags + { + /// Do not connect to the server. + CREATE_NO_CONNECT = 0x1, + + /// Force a connection to the server, bypassing the CSC. + CREATE_BYPASS_CSC = 0x2, + + /// + /// Create a connection with credentials passed in this netuse if none exist. If connection already exists then update + /// credentials after issuing remote tree connection. This is needed as CSC cannot verify credentials while offline. + /// + CREATE_CRED_RESET = 0x4, + + /// No explicit credentials are supplied in the call to NetUseAdd. + USE_DEFAULT_CREDENTIALS = 0x4, + + /// Enforce connection level integrity. + CREATE_REQUIRE_CONNECTION_INTEGRITY = 0x8, + + /// Enforce connection level privacy. + CREATE_REQUIRE_CONNECTION_PRIVACY = 0x10, + + /// Persist the mapping in the registry. (Only valid for global mappings.) + CREATE_PERSIST_MAPPING = 0x20, + + /// Enables write-through semantics on all files opened via this mapping. + CREATE_WRITE_THROUGH_SEMANTICS = 0x40, + } + + /// The level of force to use in deleting the connection. + [PInvokeData("lmuse.h", MSDNShortId = "200b0640-71e9-4f60-bf4c-c8df10bfe095")] + public enum NetUseForce + { + /// Fail the disconnection if open files exist on the connection. + USE_NOFORCE = 0, + + /// Do not fail the disconnection if open files exist on the connection. + USE_FORCE = 1, + + /// Close any open files and delete the connection. + USE_LOTS_OF_FORCE = 2 + } + + /// The status of the connection. + [PInvokeData("lmuse.h", MSDNShortId = "b9f680b8-b56a-42be-9af1-d7b18328ded4")] + public enum NetUseStatus + { + /// The connection is valid. + USE_OK = 0, + + /// Paused by local workstation. + USE_PAUSED = 1, + + /// Disconnected. + USE_SESSLOST = 2, + + /// An error occurred. + USE_DISCONN = 2, + + /// A network error occurred. + USE_NETERR = 3, + + /// The connection is being made. + USE_CONN = 4, + + /// Reconnecting. + USE_RECONN = 5, + } + + /// The type of remote resource being accessed. + [PInvokeData("lmuse.h", MSDNShortId = "b9f680b8-b56a-42be-9af1-d7b18328ded4")] + public enum NetUseType + { + /// + /// Matches the type of the server's shared resources. Wildcards can be used only with the NetUseAdd function, and only when the + /// ui1_local member is NULL. For more information, see the following Remarks section. + /// + USE_WILDCARD = -1, + + /// Disk device. + USE_DISKDEV = 0, + + /// Spooled printer. + USE_SPOOLDEV = 1, + + /// Undocumented + USE_CHARDEV = 2, + + /// Interprocess communication (IPC). + USE_IPC = 3, + } + + /// + /// The NetUseAdd function establishes a connection between the local computer and a remote server. You can specify a local + /// drive letter or a printer device to connect. If you do not specify a local drive letter or printer device, the function + /// authenticates the client with the server for future connections. + /// + /// + /// + /// The UNC name of the computer on which to execute this function. If this parameter is NULL, then the local computer is + /// used. If the UncServerName parameter specified is a remote computer, then the remote computer must support remote RPC calls using + /// the legacy Remote Access Protocol mechanism. + /// + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + /// + /// A value that specifies the information level of the data. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// 1 + /// + /// Specifies information about the connection between a local device and a shared resource. Information includes the connection + /// status and type. The Buf parameter is a pointer to a USE_INFO_1 structure. + /// + /// + /// + /// 2 + /// + /// Specifies information about the connection between a local device and a shared resource. Information includes the connection + /// status and type, and a user name and domain name. The Buf parameter is a pointer to a USE_INFO_2 structure. + /// + /// + /// + /// + /// + /// A pointer to the buffer that specifies the data. The format of this data depends on the value of the Level parameter. For more + /// information, see Network Management Function Buffers. + /// + /// + /// A pointer to a value that receives the index of the first member of the information structure in error when the + /// ERROR_INVALID_PARAMETER error is returned. If this parameter is NULL, the index is not returned on error. For more + /// information, see the following Remarks section. + /// + /// + /// If the function succeeds, the return value is NERR_Success. + /// If the function fails, the return value is a system error code. For a list of error codes, see System Error Codes. + /// + /// + /// You can also use the WNetAddConnection2 and WNetAddConnection3 functions to redirect a local device to a network resource. + /// + /// No special group membership is required to call the NetUseAdd function. This function cannot be executed on a remote + /// server except in cases of downlevel compatibility. + /// + /// + /// This function applies only to the Server Message Block (LAN Manager Workstation) client. The NetUseAdd function does not + /// support Distributed File System (DFS) shares. To add a share using a different network provider (WebDAV or a DFS share, for + /// example), use the WNetAddConnection2 or WNetAddConnection3 function. + /// + /// + /// If the NetUseAdd function returns ERROR_INVALID_PARAMETER, you can use the ParmError parameter to indicate the first + /// member of the information structure that is invalid. (The information structure begins with USE_INFO_ and its format is specified + /// by the Level parameter.) The following table lists the values that can be returned in the ParmError parameter and the + /// corresponding structure member that is in error. (The prefix ui*_ indicates that the member can begin with multiple prefixes, for + /// example, ui1_ or ui2_.) + /// + /// + /// + /// Constant + /// Value + /// Member + /// + /// + /// USE_LOCAL_PARMNUM + /// 1 + /// ui*_local + /// + /// + /// USE_REMOTE_PARMNUM + /// 2 + /// ui*_remote + /// + /// + /// USE_PASSWORD_PARMNUM + /// 3 + /// ui*_password + /// + /// + /// USE_ASGTYPE_PARMNUM + /// 4 + /// ui*_asg_type + /// + /// + /// USE_USERNAME_PARMNUM + /// 5 + /// ui*_username + /// + /// + /// USE_DOMAINNAME_PARMNUM + /// 6 + /// ui*_domainname + /// + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmuse/nf-lmuse-netuseadd NET_API_STATUS NET_API_FUNCTION NetUseAdd( LPTSTR + // servername, DWORD LevelFlags, LPBYTE buf, LPDWORD parm_err ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Auto)] + [PInvokeData("lmuse.h", MSDNShortId = "22550c17-003a-4f59-80f0-58fa3e286844")] + public static extern Win32Error NetUseAdd(string servername, uint LevelFlags, IntPtr buf, out uint parm_err); + + /// + /// The NetUseDel function ends a connection to a shared resource. + /// You can also use the WNetCancelConnection2 function to terminate a network connection. + /// + /// + /// + /// The UNC name of the computer on which to execute this function. If this is parameter is NULL, then the local computer is used. + /// + /// + /// If the UncServerName parameter specified is a remote computer, then the remote computer must support remote RPC calls using the + /// legacy Remote Access Protocol mechanism. + /// + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + /// + /// A pointer to a string that specifies the path of the connection to delete. + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + /// + /// The level of force to use in deleting the connection. + /// This parameter can be one of the following values defined in the lmuseflg.h header file. + /// + /// + /// Value + /// Meaning + /// + /// + /// USE_NOFORCE + /// Fail the disconnection if open files exist on the connection. + /// + /// + /// USE_FORCE + /// Do not fail the disconnection if open files exist on the connection. + /// + /// + /// USE_LOTS_OF_FORCE + /// Close any open files and delete the connection. + /// + /// + /// + /// + /// If the function succeeds, the return value is NERR_Success. + /// If the function fails, the return value is a system error code. For a list of error codes, see System Error Codes. + /// + /// + /// + /// The NetUseDel function applies only to the Server Message Block (LAN Manager Workstation) client. The NetUseDel + /// function does not support Distributed File System (DFS) shares or other network file systems. To terminate a connection to a + /// share using a different network provider (WebDAV or a DFS share, for example), use the WNetCancelConnection2 function. + /// + /// + /// No special group membership is required to call the NetUseDel function. This function cannot be executed on a remote + /// server except in cases of downlevel compatibility. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmuse/nf-lmuse-netusedel NET_API_STATUS NET_API_FUNCTION NetUseDel( LMSTR + // UncServerName, LMSTR UseName, DWORD ForceLevelFlags ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Auto)] + [PInvokeData("lmuse.h", MSDNShortId = "200b0640-71e9-4f60-bf4c-c8df10bfe095")] + public static extern Win32Error NetUseDel([Optional] string UncServerName, string UseName, NetUseForce ForceLevelFlags); + + /// + /// The NetUseEnum function lists all current connections between the local computer and resources on remote servers. + /// You can also use the WNetOpenEnum and the WNetEnumResource functions to enumerate network resources or connections. + /// + /// + /// + /// The UNC name of the computer on which to execute this function. If this is parameter is NULL, then the local computer is + /// used. If the UncServerName parameter specified is a remote computer, then the remote computer must support remote RPC calls using + /// the legacy Remote Access Protocol mechanism. + /// + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + /// + /// The information level of the data requested. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// 0 + /// + /// Specifies a local device name and the share name of a remote resource. The BufPtr parameter points to an array of USE_INFO_0 structures. + /// + /// + /// + /// 1 + /// + /// Specifies information about the connection between a local device and a shared resource, including connection status and type. + /// The BufPtr parameter points to an array of USE_INFO_1 structures. + /// + /// + /// + /// 2 + /// + /// Specifies information about the connection between a local device and a shared resource. Information includes the connection + /// status, connection type, user name, and domain name. The BufPtr parameter points to an array of USE_INFO_2 structures. + /// + /// + /// + /// + /// + /// A pointer to the buffer that receives the information structures. The format of this data depends on the value of the Level + /// parameter. This buffer is allocated by the system and must be freed using the NetApiBufferFree function when the information is + /// no longer needed. Note that you must free the buffer even if the function fails with ERROR_MORE_DATA. + /// + /// + /// The preferred maximum length, in bytes, of the data to return. If MAX_PREFERRED_LENGTH is specified, the function + /// allocates the amount of memory required for the data. If another value is specified in this parameter, it can restrict the number + /// of bytes that the function returns. If the buffer size is insufficient to hold all entries, the function returns + /// ERROR_MORE_DATA. For more information, see Network Management Function Buffers and Network Management Function Buffer Lengths. + /// + /// A pointer to a value that receives the count of elements actually enumerated. + /// + /// A pointer to a value that receives the total number of entries that could have been enumerated from the current resume position. + /// Note that applications should consider this value only as a hint. + /// + /// + /// A pointer to a value that contains a resume handle which is used to continue the search. The handle should be zero on the first + /// call and left unchanged for subsequent calls. If ResumeHandle is NULL, then no resume handle is stored. + /// + /// + /// If the function succeeds, the return value is NERR_Success. + /// If the function fails, the return value is a system error code. For a list of error codes, see System Error Codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the BufPtr or entriesread parameters. + /// + /// + /// + /// ERROR_MORE_DATA + /// There is more data to return. This error is returned if the buffer size is insufficient to hold all entries. + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The request is not supported. This error is returned if the UncServerName parameter was not NULL and the remote server does not + /// support remote RPC calls using the legacy Remote Access Protocol mechanism. + /// + /// + /// + /// Other + /// Use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// + /// No special group membership is required to call the NetUseEnum function. This function cannot be executed on a remote + /// server except in cases of downlevel compatibility using the legacy Remote Access Protocol. + /// + /// To retrieve information about one network connection, you can call the NetUseGetInfo function. + /// + /// This function applies only to the Server Message Block (LAN Manager Workstation) client. The NetUseEnum function does not + /// support Distributed File System (DFS) shares. To enumerate shares using a different network provider (WebDAV or a DFS share, for + /// example), use the WNetOpenEnum, WNetEnumResource, and WNetCloseEnum functions. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmuse/nf-lmuse-netuseenum NET_API_STATUS NET_API_FUNCTION NetUseEnum( LMSTR + // UncServerName, DWORD LevelFlags, LPBYTE *BufPtr, DWORD PreferedMaximumSize, LPDWORD EntriesRead, LPDWORD TotalEntries, LPDWORD + // ResumeHandle ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Auto)] + [PInvokeData("lmuse.h", MSDNShortId = "fb527f85-baea-48e8-b837-967870834ec5")] + public static extern Win32Error NetUseEnum([Optional] string UncServerName, uint LevelFlags, out SafeNetApiBuffer BufPtr, uint PreferedMaximumSize, out uint EntriesRead, out uint TotalEntries, ref uint ResumeHandle); + + /// + /// The NetUseGetInfo function retrieves information about a connection to a shared resource. + /// You can also use the WNetGetConnection function to retrieve the name of a network resource associated with a local device. + /// + /// + /// + /// The UNC name of computer on which to execute this function. If this is parameter is NULL, then the local computer is used. + /// If the UncServerName parameter specified is a remote computer, then the remote computer must support remote RPC calls using the + /// legacy Remote Access Protocol mechanism. + /// + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + /// + /// A pointer to a string that specifies the name of the connection for which to return information. + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + /// + /// The information level of the data requested. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// 0 + /// + /// Specifies a local device name and the share name of a remote resource. The BufPtr parameter is a pointer to a USE_INFO_0 structure. + /// + /// + /// + /// 1 + /// + /// Specifies information about the connection between a local device and a shared resource, including connection status and type. + /// The BufPtr parameter is a pointer to a USE_INFO_1 structure. + /// + /// + /// + /// 2 + /// + /// Specifies information about the connection between a local device and a shared resource. Information includes the connection + /// status, connection type, user name, and domain name. The BufPtr parameter is a pointer to a USE_INFO_2 structure. + /// + /// + /// + /// + /// + /// A pointer to the buffer that receives the data. The format of this data depends on the value of the Level parameter. This buffer + /// is allocated by the system and must be freed using the NetApiBufferFree function. For more information, see Network Management + /// Function Buffers and Network Management Function Buffer Lengths. + /// + /// + /// If the function succeeds, the return value is NERR_Success. + /// If the function fails, the return value is a system error code. For a list of error codes, see System Error Codes. + /// + /// + /// + /// No special group membership is required to call the NetUseGetInfo function. This function cannot be executed on a remote + /// server except in cases of downlevel compatibility. + /// + /// + /// To list all current connections between the local computer and resources on remote servers, you can call the NetUseEnum function. + /// + /// + /// This function applies only to the Server Message Block (LAN Manager Workstation) client. The NetUseGetInfo function does + /// not support Distributed File System (DFS) shares. To retrieve information for a share using a different network provider (WebDAV + /// or a DFS share, for example), use the WNetGetConnection function. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmuse/nf-lmuse-netusegetinfo NET_API_STATUS NET_API_FUNCTION NetUseGetInfo( + // LMSTR UncServerName, LMSTR UseName, DWORD LevelFlags, LPBYTE *bufptr ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Auto)] + [PInvokeData("lmuse.h", MSDNShortId = "257875db-5ed9-4569-8dbb-5dcc7a6af95c")] + public static extern Win32Error NetUseGetInfo([Optional] string UncServerName, string UseName, uint LevelFlags, out SafeNetApiBuffer bufptr); + + /// The USE_INFO_0 structure contains the name of a shared resource and the local device redirected to it. + // https://docs.microsoft.com/en-us/windows/desktop/api/lmuse/ns-lmuse-_use_info_0 typedef struct _USE_INFO_0 { LMSTR ui0_local; + // LMSTR ui0_remote; } USE_INFO_0, *PUSE_INFO_0, *LPUSE_INFO_0; + [PInvokeData("lmuse.h", MSDNShortId = "86db3f19-84c5-4e89-82cb-f01d17dcf4ec")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public struct USE_INFO_0 + { + /// + /// Pointer to a Unicode string that specifies the local device name (for example, drive E or LPT1) being redirected to the + /// shared resource. The constant DEVLEN specifies the maximum number of characters in the string. + /// + public string ui0_local; + + /// + /// Pointer to a Unicode string that specifies the share name of the remote resource being accessed. The string is in the form: + /// + public string ui0_remote; + } + + /// + /// The USE_INFO_1 structure contains information about the connection between a local device and a shared resource. The + /// information includes connection status and connection type. + /// + /// + /// Specifying a ui1_local member that is NULL requests authentication with the server without redirecting a drive + /// letter or a device. Future redirections involving the server while the same connection is in effect use the password specified by + /// the ui1_password member in the initial call to the NetUseAdd function. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmuse/ns-lmuse-use_info_1 typedef struct _USE_INFO_1 { LMSTR ui1_local; LMSTR + // ui1_remote; LMSTR ui1_password; DWORD ui1_status; DWORD ui1_asg_type; DWORD ui1_refcount; DWORD ui1_usecount; } USE_INFO_1, + // *PUSE_INFO_1, *LPUSE_INFO_1; + [PInvokeData("lmuse.h", MSDNShortId = "b9f680b8-b56a-42be-9af1-d7b18328ded4")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public struct USE_INFO_1 + { + /// + /// Type: LMSTR + /// + /// A pointer to a string that contains the local device name (for example, drive E or LPT1) being redirected to the shared + /// resource. The constant DEVLEN specifies the maximum number of characters in the string. This member can be NULL. For + /// more information, see the following Remarks section. + /// + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + public string ui1_local; + + /// + /// Type: LMSTR + /// A pointer to a string that contains the share name of the remote resource being accessed. The string is in the form: + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + public string ui1_remote; + + /// + /// Type: LMSTR + /// + /// A pointer to a string that contains the password needed to establish a session between a specific workstation and a server. + /// + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + public string ui1_password; + + /// + /// Type: DWORD + /// The status of the connection. This element is not used by the NetUseAdd function. The following values are defined. + /// + /// + /// Value + /// Meaning + /// + /// + /// USE_OK + /// The connection is valid. + /// + /// + /// USE_PAUSED + /// Paused by local workstation. + /// + /// + /// USE_SESSLOST + /// Disconnected. + /// + /// + /// USE_DISCONN + /// An error occurred. + /// + /// + /// USE_NETERR + /// A network error occurred. + /// + /// + /// USE_CONN + /// The connection is being made. + /// + /// + /// USE_RECONN + /// Reconnecting. + /// + /// + /// + public NetUseStatus ui1_status; + + /// + /// Type: DWORD + /// The type of remote resource being accessed. This member can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// USE_WILDCARD + /// + /// Matches the type of the server's shared resources. Wildcards can be used only with the NetUseAdd function, and only when the + /// ui1_local member is NULL. For more information, see the following Remarks section. + /// + /// + /// + /// USE_DISKDEV + /// Disk device. + /// + /// + /// USE_SPOOLDEV + /// Spooled printer. + /// + /// + /// USE_IPC + /// Interprocess communication (IPC). + /// + /// + /// + public NetUseType ui1_asg_type; + + /// + /// Type: DWORD + /// + /// The number of files, directories, and other processes that are open on the remote resource. This element is not used by the + /// NetUseAdd function. + /// + /// + public uint ui1_refcount; + + /// + /// Type: DWORD + /// + /// The number of explicit connections (redirection with a local device name) or implicit UNC connections (redirection without a + /// local device name) that are established with the resource. + /// + /// + public uint ui1_usecount; + } + + /// + /// The USE_INFO_2 structure contains information about a connection between a local computer and a shared resource, including + /// connection type, connection status, user name, and domain name. + /// + /// + /// Specifying a ui2_local member that is NULL requests authentication with the server without redirecting a drive + /// letter or a device. Future redirections involving the server while the same connection is in effect use the authentication + /// information specified in the initial call to the NetUseAdd function. This information includes the combination of the + /// ui2_password, ui2_username, and ui2_domainname members. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmuse/ns-lmuse-_use_info_2 typedef struct _USE_INFO_2 { LMSTR ui2_local; + // LMSTR ui2_remote; LMSTR ui2_password; DWORD ui2_status; DWORD ui2_asg_type; DWORD ui2_refcount; DWORD ui2_usecount; LMSTR + // ui2_username; LMSTR ui2_domainname; } USE_INFO_2, *PUSE_INFO_2, *LPUSE_INFO_2; + [PInvokeData("lmuse.h", MSDNShortId = "4cc36108-085a-47c4-9dfa-b46f7e208c8b")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public struct USE_INFO_2 + { + /// + /// Type: LMSTR + /// + /// A pointer to a string that contains the local device name (for example, drive E or LPT1) being redirected to the shared + /// resource. The constant DEVLEN specifies the maximum number of characters in the string. This member can be NULL. For + /// more information, see the following Remarks section. + /// + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + public string ui2_local; + + /// + /// Type: LMSTR + /// A pointer to a string that contains the share name of the remote resource. The string is in the form + /// + public string ui2_remote; + + /// + /// Type: LMSTR + /// A pointer to a string that contains the password needed to establish a session with a specific workstation. + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + public string ui2_password; + + /// + /// Type: DWORD + /// The status of the connection. This element is not used by the NetUseAdd function. The following values are defined. + /// + /// + /// Value + /// Meaning + /// + /// + /// USE_OK + /// The connection is successful. + /// + /// + /// USE_PAUSED + /// Paused by a local workstation. + /// + /// + /// USE_SESSLOST + /// Disconnected. + /// + /// + /// USE_DISCONN + /// An error occurred. + /// + /// + /// USE_NETERR + /// A network error occurred. + /// + /// + /// USE_CONN + /// The connection is being made. + /// + /// + /// USE_RECONN + /// Reconnecting. + /// + /// + /// + public NetUseStatus ui2_status; + + /// + /// Type: DWORD + /// The type of remote resource being accessed. This member can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// USE_WILDCARD + /// + /// Matches the type of the server's shared resources. Wildcards can be used only with the NetUseAdd function, and only when the + /// ui2_local member is a NULL string. For more information, see the following Remarks section. + /// + /// + /// + /// USE_DISKDEV + /// Disk device. + /// + /// + /// USE_SPOOLDEV + /// Spooled printer. + /// + /// + /// USE_IPC + /// Interprocess communication (IPC). + /// + /// + /// + public NetUseType ui2_asg_type; + + /// + /// Type: DWORD + /// + /// The number of files, directories, and other processes that are open on the remote resource. This element is not used by the + /// NetUseAdd function. + /// + /// + public uint ui2_refcount; + + /// + /// Type: DWORD + /// + /// The number of explicit connections (redirection with a local device name) or implicit UNC connections (redirection without a + /// local device name) that are established with the resource. + /// + /// + public uint ui2_usecount; + + /// + /// Type: LPWSTR + /// A pointer to a string that contains the name of the user who initiated the connection. + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + public string ui2_username; + + /// + /// Type: LMSTR + /// A pointer to a string that contains the domain name of the remote resource. + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + public string ui2_domainname; + } + + /// + /// The USE_INFO_3 structure contains information about a connection between a local computer and a shared resource, including + /// connection type, connection status, user name, domain name, and specific flags that describe connection behavior. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmuse/ns-lmuse-_use_info_3 typedef struct _USE_INFO_3 { USE_INFO_2 ui3_ui2; + // ULONG ui3_flags; } USE_INFO_3, *PUSE_INFO_3, *LPUSE_INFO_3; + [PInvokeData("lmuse.h", MSDNShortId = "3fb3ad35-f9e5-46ba-b930-fc2ccafd8ee9")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public struct USE_INFO_3 + { + /// USE_INFO_2 structure that contains + public USE_INFO_2 ui3_ui2; + + /// A set of bit flags that describe connection behavior and credential handling. + public NetUseFlags ui3_flags; + } + + /// Undocumented. + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public struct USE_INFO_4 + { + /// Undocumented. + public USE_INFO_3 ui4_ui3; + + /// Undocumented. + public uint ui4_auth_identity_length; + + /// Undocumented. + public IntPtr ui4_auth_identity; + } + + /// Undocumented. + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public struct USE_INFO_5 + { + /// Undocumented. + public USE_INFO_3 ui4_ui3; + + /// Undocumented. + public uint ui4_auth_identity_length; + + /// Undocumented. + public IntPtr ui4_auth_identity; + + /// Undocumented. + public uint ui5_security_descriptor_length; + + /// Undocumented. + public IntPtr ui5_security_descriptor; + + /// Undocumented. + public uint ui5_use_options_length; + + /// Undocumented. + public IntPtr ui5_use_options; + } + } +} \ No newline at end of file diff --git a/PInvoke/NetApi32/LmWkSta.cs b/PInvoke/NetApi32/LmWkSta.cs new file mode 100644 index 00000000..ed8c8d5c --- /dev/null +++ b/PInvoke/NetApi32/LmWkSta.cs @@ -0,0 +1,1688 @@ +using System; +using System.Runtime.InteropServices; + +namespace Vanara.PInvoke +{ + public static partial class NetApi32 + { + /// The information level to use to retrieve platform-specific information. + [PInvokeData("lmwksta.h", MSDNShortId = "c705dadd-cf55-44d9-bf36-09e078112479")] + public enum PLATFORM_ID + { + /// The MS-DOS platform. + PLATFORM_ID_DOS = 300, + + /// The OS/2 platform. + PLATFORM_ID_OS2 = 400, + + /// The Windows NT platform. + PLATFORM_ID_NT = 500, + + /// The OSF platform. + PLATFORM_ID_OSF = 600, + + /// The VMS platform. + PLATFORM_ID_VMS = 700, + } + + /// The NetWkstaGetInfo function returns information about the configuration of a workstation. + /// + /// Pointer to a string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this + /// parameter is NULL, the local computer is used. + /// + /// + /// Specifies the information level of the data. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// 100 + /// + /// Return information about the workstation environment, including platform-specific information, the name of the domain and the + /// local computer, and information concerning the operating system. The bufptr parameter points to a WKSTA_INFO_100 structure. + /// + /// + /// + /// 101 + /// + /// In addition to level 100 information, return the path to the LANMAN directory. The bufptr parameter points to a WKSTA_INFO_101 structure. + /// + /// + /// + /// 102 + /// + /// In addition to level 101 information, return the number of users who are logged on to the local computer. The bufptr parameter + /// points to a WKSTA_INFO_102 structure. + /// + /// + /// + /// + /// + /// Pointer to the buffer that receives the data. The format of this data depends on the value of the level parameter. This buffer is + /// allocated by the system and must be freed using the NetApiBufferFree function. For more information, see Network Management + /// Function Buffers and Network Management Function Buffer Lengths. + /// + /// + /// If the function succeeds, the return value is NERR_Success. + /// If the function fails, the return value can be one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_ACCESS_DENIED + /// The user does not have access to the requested information. + /// + /// + /// ERROR_INVALID_LEVEL + /// The level parameter is invalid. + /// + /// + /// + /// + /// + /// Windows Server 2003 and Windows XP: If you call this function on a domain controller that is running Active Directory, + /// access is allowed or denied based on the ACL for the securable object. To enable anonymous access, the user Anonymous must be a + /// member of the "Pre-Windows 2000 compatible access" group. This is because anonymous tokens do not include the Everyone group SID + /// by default. If you call this function on a member server or workstation, all authenticated users can view the information. + /// Anonymous access is also permitted if the EveryoneIncludesAnonymous policy setting allows anonymous access. Anonymous access is + /// always permitted for level 100. If you call this function at level 101, authenticated users can view the information. Members of + /// the Administrators, and the Server, System and Print Operator local groups can view information at levels 102 and 502. For more + /// information about restricting anonymous access, see Security Requirements for the Network Management Functions. For more + /// information on ACLs, ACEs, and access tokens, see Access Control Model. + /// + /// + /// Windows 2000: If you call this function on a domain controller that is running Active Directory, access is allowed or + /// denied based on the access control list (ACL) for the securable object. The default ACL permits all authenticated users and + /// members of the " Pre-Windows 2000 compatible access" group to view the information. By default, the "Pre-Windows 2000 compatible + /// access" group includes Everyone as a member. This enables anonymous access to the information if the system allows anonymous + /// access. If you call this function on a member server or workstation, all authenticated users can view the information. Anonymous + /// access is also permitted if the RestrictAnonymous policy setting allows anonymous access. + /// + /// + /// To compile an application that uses this function, define the _WIN32_WINNT macro as 0x0400 or later. For more information,see + /// Using the Windows Headers. + /// + /// Examples + /// + /// The following code sample demonstrates how to retrieve information about the configuration elements for a workstation using a + /// call to the NetWkstaGetInfo function. The sample calls NetWkstaGetInfo, specifying information level 102 ( + /// WKSTA_INFO_102). If the call succeeds, the sample prints information about the workstation. Finally, the code sample frees the + /// memory allocated for the information buffer. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmwksta/nf-lmwksta-netwkstagetinfo NET_API_STATUS NET_API_FUNCTION + // NetWkstaGetInfo( LMSTR servername, DWORD level, OUT LPBYTE *bufptr ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("lmwksta.h", MSDNShortId = "08777069-1afd-4482-8090-c65ef0bec1ea")] + public static extern Win32Error NetWkstaGetInfo([Optional] string servername, uint level, out SafeNetApiBuffer bufptr); + + /// + /// The NetWkstaSetInfo function configures a workstation with information that remains in effect after the system has been reinitialized. + /// + /// + /// A pointer to a string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this + /// parameter is NULL, the local computer is used. + /// + /// + /// The information level of the data. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// 100 + /// + /// Windows NT: Specifies information about a workstation environment, including platform-specific information, the names of the + /// domain and the local computer, and information concerning the operating system. The buffer parameter points to a WKSTA_INFO_100 + /// structure. The wk100_computername and wk100_langroup fields of this structure cannot be set by calling this function. To set + /// these values, call SetComputerName/SetComputerNameEx or NetJoinDomain, respectively. + /// + /// + /// + /// 101 + /// + /// Windows NT: In addition to level 100 information, specifies the path to the LANMAN directory. The buffer parameter points to a + /// WKSTA_INFO_101 structure. The wk101_computername and wk101_langroup fields of this structure cannot be set by calling this + /// function. To set these values, call SetComputerName/SetComputerNameEx or NetJoinDomain, respectively. + /// + /// + /// + /// 102 + /// + /// Windows NT: In addition to level 101 information, specifies the number of users who are logged on to the local computer. The + /// buffer parameter points to a WKSTA_INFO_102 structure. The wk102_computername and wk102_langroup fields of this structure cannot + /// be set by calling this function. To set these values, call SetComputerName/SetComputerNameEx or NetJoinDomain, respectively. + /// + /// + /// + /// 502 + /// + /// Windows NT: The buffer parameter points to a WKSTA_INFO_502 structure that contains information about the workstation environment. + /// + /// + /// + /// Do not set levels 1010-1013, 1018, 1023, 1027, 1028, 1032, 1033, 1035, or 1041-1062. + /// + /// + /// A pointer to the buffer that specifies the data. The format of this data depends on the value of the level parameter. For more + /// information, see Network Management Function Buffers. + /// + /// + /// A pointer to a value that receives the index of the first member of the workstation information structure that causes the + /// ERROR_INVALID_PARAMETER error. If this parameter is NULL, the index is not returned on error. For more information, see + /// the Remarks section. + /// + /// + /// If the function succeeds, the return value is NERR_Success. + /// If the function fails, the return value can be one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_ACCESS_DENIED + /// The user does not have access to the requested information. + /// + /// + /// ERROR_INVALID_PARAMETER + /// One of the function parameters is invalid. For more information, see the following Remarks section. + /// + /// + /// + /// + /// Only members of the Administrators group can successfully execute the NetWkstaSetInfo function on a remote server. + /// + /// The NetWkstaSetInfo function calls the workstation service on the local system or a remote system. Only a limited number + /// of members of the WKSTA_INFO_502 structure can actually be changed using the NetWkstaSetInfo function. No errors are + /// returned if a member is set that is ignored by the workstation service. The workstation service is primarily configured using + /// settings in the registry. + /// + /// + /// The NetWkstaUserSetInfo function can be used instead of the NetWkstaSetInfo function to set configuration information on + /// the local system. The NetWkstaUserSetInfo function calls the Local Security Authority (LSA). + /// + /// + /// If the NetWkstaSetInfo function returns ERROR_INVALID_PARAMETER, you can use the parm_err parameter to indicate the first + /// member of the workstation information structure that is invalid. (A workstation information structure begins with WKSTA_INFO_ and + /// its format is specified by the level parameter.) The following table lists the values that can be returned in the parm_err + /// parameter and the corresponding structure member that is in error. (The prefix wki*_ indicates that the member can begin with + /// multiple prefixes, for example, wki100_ or wki402_.) + /// + /// + /// + /// Value + /// Member + /// + /// + /// WKSTA_PLATFORM_ID_PARMNUM + /// wki*_platform_id + /// + /// + /// WKSTA_COMPUTERNAME_PARMNUM + /// wki*_computername + /// + /// + /// WKSTA_LANGROUP_PARMNUM + /// wki*_langroup + /// + /// + /// WKSTA_VER_MAJOR_PARMNUM + /// wki*_ver_major + /// + /// + /// WKSTA_VER_MINOR_PARMNUM + /// wki*_ver_minor + /// + /// + /// WKSTA_LOGGED_ON_USERS_PARMNUM + /// wki*_logged_on_users + /// + /// + /// WKSTA_LANROOT_PARMNUM + /// wki*_lanroot + /// + /// + /// WKSTA_LOGON_DOMAIN_PARMNUM + /// wki*_logon_domain + /// + /// + /// WKSTA_LOGON_SERVER_PARMNUM + /// wki*_logon_server + /// + /// + /// WKSTA_CHARWAIT_PARMNUM + /// wki*_char_wait + /// + /// + /// WKSTA_CHARTIME_PARMNUM + /// wki*_collection_time + /// + /// + /// WKSTA_CHARCOUNT_PARMNUM + /// wki*_maximum_collection_count + /// + /// + /// WKSTA_KEEPCONN_PARMNUM + /// wki*_keep_conn + /// + /// + /// WKSTA_KEEPSEARCH_PARMNUM + /// wki*_keep_search + /// + /// + /// WKSTA_MAXCMDS_PARMNUM + /// wki*_max_cmds + /// + /// + /// WKSTA_NUMWORKBUF_PARMNUM + /// wki*_num_work_buf + /// + /// + /// WKSTA_MAXWRKCACHE_PARMNUM + /// wki*_max_wrk_cache + /// + /// + /// WKSTA_SESSTIMEOUT_PARMNUM + /// wki*_sess_timeout + /// + /// + /// WKSTA_SIZERROR_PARMNUM + /// wki*_siz_error + /// + /// + /// WKSTA_NUMALERTS_PARMNUM + /// wki*_num_alerts + /// + /// + /// WKSTA_NUMSERVICES_PARMNUM + /// wki*_num_services + /// + /// + /// WKSTA_ERRLOGSZ_PARMNUM + /// wki*_errlog_sz + /// + /// + /// WKSTA_PRINTBUFTIME_PARMNUM + /// wki*_print_buf_time + /// + /// + /// WKSTA_NUMCHARBUF_PARMNU + /// wki*_num_char_buf + /// + /// + /// WKSTA_SIZCHARBUF_PARMNUM + /// wki*_siz_char_buf + /// + /// + /// WKSTA_WRKHEURISTICS_PARMNUM + /// wki*_wrk_heuristics + /// + /// + /// WKSTA_MAILSLOTS_PARMNUM + /// wki*_mailslots + /// + /// + /// WKSTA_MAXTHREADS_PARMNUM + /// wki*_max_threads + /// + /// + /// WKSTA_SIZWORKBUF_PARMNUM + /// wki*_siz_work_buf + /// + /// + /// WKSTA_NUMDGRAMBUF_PARMNUM + /// wki*_num_dgram_buf + /// + /// + /// + /// The workstation service parameter settings are stored in the registry, not in the LanMan.ini file used prveiously by LAN Manager. + /// The NetWkstaSetInfo function does not change the values in the LanMan.ini file. When the workstation service is stopped + /// and restarted, workstation parameters are reset to the default values specified in the registry (unless they are overwritten by + /// command-line parameters). Values set by previous calls to NetWkstaSetInfo can be overwritten when workstation parameters + /// are reset. + /// + /// Examples + /// + /// The following code sample demonstrates how to set the session time-out value associated with a workstation using a call to the + /// NetServerSetInfo function. (The session time-out is the number of seconds the server waits before disconnecting an + /// inactive session.) The code specifies information level 502 (WKSTA_INFO_502). + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmwksta/nf-lmwksta-netwkstasetinfo NET_API_STATUS NET_API_FUNCTION + // NetWkstaSetInfo( LMSTR servername, DWORD level, LPBYTE buffer, OUT LPDWORD parm_err ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("lmwksta.h", MSDNShortId = "d746b6c9-5ef1-4174-a84f-44e4e50200cd")] + public static extern Win32Error NetWkstaSetInfo([Optional] string servername, uint level, IntPtr buffer, out uint parm_err); + + /// + /// + /// [This function is obsolete. To change the default settings for transport protocols manually, use the Local Area Connection + /// Properties dialog box in the Network and Dial-Up Connections folder.] + /// + /// Not supported. + /// + /// The NetWkstaTransportAdd function binds (or connects) the redirector to the transport. The redirector is the software on + /// the client computer which generates file requests to the server computer. + /// + /// + /// + /// + /// Pointer to a string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this + /// parameter is NULL, the local computer is used. + /// + /// This string must begin with \. + /// + /// + /// Specifies the information level of the data. This parameter can be the following value. + /// + /// + /// Value + /// Meaning + /// + /// + /// 0 + /// Specifies workstation transport protocol information. The buf parameter points to a WKSTA_TRANSPORT_INFO_0 structure. + /// + /// + /// + /// + /// Pointer to the buffer that specifies the data. The format of this data depends on the value of the level parameter. For more + /// information, see Network Management Function Buffers. + /// + /// + /// Pointer to a value that receives the index of the first parameter that causes the ERROR_INVALID_PARAMETER error. If this + /// parameter is NULL, the index is not returned on error. + /// + /// + /// If the function succeeds, the return value is NERR_Success. + /// If the function fails, the return value can be one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_ACCESS_DENIED + /// The user does not have access to the requested information. + /// + /// + /// ERROR_INVALID_LEVEL + /// The level parameter, which indicates what level of data structure information is available, is invalid. + /// + /// + /// ERROR_INVALID_PARAMETER + /// One of the function parameters is invalid. + /// + /// + /// + /// + /// Only members of the Administrators local group can successfully execute the NetWkstaTransportAdd function. + /// + /// If the NetWkstaTransportAdd function returns ERROR_INVALID_PARAMETER, you can use the parm_err parameter to indicate the + /// member of the WKSTA_TRANSPORT_INFO_0 structure that is invalid. The following table lists the values that can be returned + /// in the parm_err parameter and the corresponding structure member that is in error. + /// + /// + /// + /// Value + /// Member + /// + /// + /// TRANSPORT_QUALITYOFSERVICE_PARMNUM + /// wkti0_quality_of_service + /// + /// + /// TRANSPORT_NAME_PARMNUM + /// wkti0_transport_name + /// + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmwksta/nf-lmwksta-netwkstatransportadd NET_API_STATUS NET_API_FUNCTION + // NetWkstaTransportAdd( LPTSTR servername, DWORD level, LPBYTE buf, LPDWORD parm_err ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("lmwksta.h", MSDNShortId = "016060ea-eae1-421f-b708-5c2ddd2000c1")] + public static extern Win32Error NetWkstaTransportAdd([Optional] string servername, uint level, IntPtr buf, out uint parm_err); + + /// + /// + /// [This function is obsolete. To change the default settings for transport protocols manually, use the Local Area Connection + /// Properties dialog box in the Network and Dial-Up Connections folder.] + /// + /// Not supported. + /// + /// The NetWkstaTransportDel function unbinds the transport protocol from the redirector. (The redirector is the software on + /// the client computer that generates file requests to the server computer.) + /// + /// + /// + /// + /// Pointer to a string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this + /// parameter is NULL, the local computer is used. + /// + /// This string must begin with \. + /// + /// Pointer to a string that specifies the name of the transport protocol to disconnect from the redirector. + /// + /// + /// Specifies the level of force to use when disconnecting the transport protocol from the redirector. This parameter can be one of + /// the following values. + /// + /// + /// + /// Value + /// Meaning + /// + /// + /// USE_NOFORCE + /// Fail the disconnection if open files exist on the connection. + /// + /// + /// USE_FORCE + /// Fail the disconnection if open files exist on the connection. + /// + /// + /// USE_LOTS_OF_FORCE + /// Close any open files and delete the connection. + /// + /// + /// + /// + /// If the function succeeds, the return value is NERR_Success. + /// If the function fails, the return value can be one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_ACCESS_DENIED + /// The user does not have access to the requested information. + /// + /// + /// ERROR_INVALID_PARAMETER + /// One of the function parameters is invalid. + /// + /// + /// NERR_UseNotFound + /// The network connection does not exist. + /// + /// + /// + /// Only members of the Administrators local group can successfully execute the NetWkstaTransportDel function. + // https://docs.microsoft.com/en-us/windows/desktop/api/lmwksta/nf-lmwksta-netwkstatransportdel NET_API_STATUS NET_API_FUNCTION + // NetWkstaTransportDel( IN LMSTR servername, IN LMSTR transportname, IN DWORD ucond ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("lmwksta.h", MSDNShortId = "6d0ec459-8d7b-41fe-96dd-203e6a42164f")] + public static extern Win32Error NetWkstaTransportDel([Optional] string servername, string transportname, uint ucond); + + /// + /// The NetWkstaTransportEnum function supplies information about transport protocols that are managed by the redirector, + /// which is the software on the client computer that generates file requests to the server computer. + /// + /// + /// A pointer to a string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this + /// parameter is NULL, the local computer is used. + /// + /// + /// The level of information requested for the data. This parameter can be the following value. + /// + /// + /// Value + /// Meaning + /// + /// + /// 0 + /// Return workstation transport protocol information. The bufptr parameter points to an array of WKSTA_TRANSPORT_INFO_0 structures. + /// + /// + /// + /// + /// A pointer to the buffer that receives the data. The format of this data depends on the value of the level parameter. This buffer + /// is allocated by the system and must be freed using the NetApiBufferFree function. Note that you must free the buffer even if the + /// function fails with ERROR_MORE_DATA or NERR_BufTooSmall. + /// + /// + /// The preferred maximum length of returned data, in bytes. If you specify MAX_PREFERRED_LENGTH, the function allocates the + /// amount of memory required for the data. If you specify another value in this parameter, it can restrict the number of bytes that + /// the function returns. If the buffer size is insufficient to hold all entries, the function returns ERROR_MORE_DATA or + /// NERR_BufTooSmall. For more information, see Network Management Function Buffers and Network Management Function Buffer Lengths. + /// + /// A pointer to a value that receives the count of elements actually enumerated. + /// + /// A pointer to a value that receives the total number of entries that could have been enumerated from the current resume position. + /// Note that applications should consider this value only as a hint. + /// + /// The resume handle. + /// + /// If the function succeeds, the return value is NERR_Success. + /// If the function fails, the return value can be one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_MORE_DATA + /// More entries are available. Specify a large enough buffer to receive all entries. + /// + /// + /// ERROR_INVALID_LEVEL + /// + /// The level parameter, which indicates what level of data structure information is available, is invalid. This error is returned if + /// the level parameter is specified as a value other than zero. + /// + /// + /// + /// ERROR_INVALID_PARAMETER + /// One or more parameters was invalid. This error is returned if the bufptr or the entriesread parameters are NULL pointers. + /// + /// + /// ERROR_NOT_ENOUGH_MEMORY + /// Insufficient memory was available to process the request. + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The request is not supported. This error is returned if a remote server was specified in servername parameter, and this request + /// is not supported on the remote server. + /// + /// + /// + /// NERR_BufTooSmall + /// + /// More entries are available. Specify a large enough buffer to receive all entries. This error code is defined in the Lmerr.h + /// header file. + /// + /// + /// + /// + /// No special group membership is required to successfully execute the NetWkstaTransportEnum function. + // https://docs.microsoft.com/en-us/windows/desktop/api/lmwksta/nf-lmwksta-netwkstatransportenum NET_API_STATUS NET_API_FUNCTION + // NetWkstaTransportEnum( LPTSTR servername, DWORD level, LPBYTE *bufptr, DWORD prefmaxlen, LPDWORD entriesread, LPDWORD + // totalentries, LPDWORD resume_handle ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("lmwksta.h", MSDNShortId = "08bd22a9-00a7-4563-9353-c070ca9b2500")] + public static extern Win32Error NetWkstaTransportEnum([Optional] string servername, uint level, out SafeNetApiBuffer bufptr, uint prefmaxlen, out uint entriesread, out uint totalentries, ref uint resume_handle); + + /// + /// The NetWkstaUserEnum function lists information about all users currently logged on to the workstation. This list includes + /// interactive, service and batch logons. + /// + /// + /// Pointer to a string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this + /// parameter is NULL, the local computer is used. + /// + /// + /// Specifies the information level of the data. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// 0 + /// + /// Return the names of users currently logged on to the workstation. The bufptr parameter points to an array of WKSTA_USER_INFO_0 structures. + /// + /// + /// + /// 1 + /// + /// Return the names of the current users and the domains accessed by the workstation. The bufptr parameter points to an array of + /// WKSTA_USER_INFO_1 structures. + /// + /// + /// + /// + /// + /// Pointer to the buffer that receives the data. The format of this data depends on the value of the level parameter. This buffer is + /// allocated by the system and must be freed using the NetApiBufferFree function. Note that you must free the buffer even if the + /// function fails with ERROR_MORE_DATA. + /// + /// + /// Specifies the preferred maximum length of returned data, in bytes. If you specify MAX_PREFERRED_LENGTH, the function allocates + /// the amount of memory required for the data. If you specify another value in this parameter, it can restrict the number of bytes + /// that the function returns. If the buffer size is insufficient to hold all entries, the function returns ERROR_MORE_DATA. For more + /// information, see Network Management Function Buffers and Network Management Function Buffer Lengths. + /// + /// Pointer to a value that receives the count of elements actually enumerated. + /// + /// Pointer to a value that receives the total number of entries that could have been enumerated from the current resume position. + /// Note that applications should consider this value only as a hint. + /// + /// + /// Pointer to a value that contains a resume handle which is used to continue an existing search. The handle should be zero on the + /// first call and left unchanged for subsequent calls. If this parameter is NULL, no resume handle is stored. + /// + /// + /// If the function succeeds, the return value is NERR_Success. + /// If the function fails, the return value can be one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_ACCESS_DENIED + /// The user does not have access to the requested information. + /// + /// + /// ERROR_MORE_DATA + /// More entries are available. Specify a large enough buffer to receive all entries. + /// + /// + /// ERROR_INVALID_LEVEL + /// The level parameter is invalid. + /// + /// + /// + /// + /// + /// Note that since the NetWkstaUserEnum function lists entries for service and batch logons, as well as for interactive + /// logons, the function can return entries for users who have logged off a workstation. This can occur, for example, when a user + /// calls a service that impersonates the user. In this instance, NetWkstaUserEnum returns an entry for the user until the + /// service stops impersonating the user. + /// + /// + /// Windows Server 2003 and Windows XP: If you call this function on a domain controller that is running Active Directory, + /// access is allowed or denied based on the ACL for the securable object. To enable anonymous access, the user Anonymous must be a + /// member of the "Pre-Windows 2000 compatible access" group. This is because anonymous tokens do not include the Everyone group SID + /// by default. If you call this function on a member server or workstation, all authenticated users can view the information. + /// Anonymous access is also permitted if the RestrictAnonymous policy setting permits anonymous access. If the RestrictAnonymous + /// policy setting does not permit anonymous access, only an administrator can successfully execute the function. Members of the + /// Administrators, and the Server, System and Print Operator local groups can also view information. For more information about + /// restricting anonymous access, see Security Requirements for the Network Management Functions. For more information on ACLs, ACEs, + /// and access tokens, see Access Control Model. + /// + /// + /// Windows 2000: If you call this function on a domain controller that is running Active Directory, access is allowed or + /// denied based on the access control list (ACL) for the securable object. The default ACL permits all authenticated users and + /// members of the " Pre-Windows 2000 compatible access" group to view the information. By default, the "Pre-Windows 2000 compatible + /// access" group includes Everyone as a member. This enables anonymous access to the information if the system allows anonymous + /// access. If you call this function on a member server or workstation, all authenticated users can view the information. Anonymous + /// access is also permitted if the RestrictAnonymous policy setting allows anonymous access. + /// + /// + /// To compile an application that uses this function, define the _WIN32_WINNT macro as 0x0400 or later. For more information,see + /// Using the Windows Headers. + /// + /// Examples + /// + /// The following code sample demonstrates how to list information about all users currently logged on to a workstation using a call + /// to the NetWkstaUserEnum function. The sample calls NetWkstaUserEnum, specifying information level 0 ( + /// WKSTA_USER_INFO_0). The sample loops through the entries and prints the names of the users logged on to a workstation. Finally, + /// the code sample frees the memory allocated for the information buffer, and prints the total number of users enumerated. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmwksta/nf-lmwksta-netwkstauserenum NET_API_STATUS NET_API_FUNCTION + // NetWkstaUserEnum( LMSTR servername, IN DWORD level, LPBYTE *bufptr, IN DWORD prefmaxlen, LPDWORD entriesread, LPDWORD + // totalentries, LPDWORD resumehandle ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("lmwksta.h", MSDNShortId = "42eaeb70-3ce8-4eae-b20b-4729db90a7ef")] + public static extern Win32Error NetWkstaUserEnum([Optional] string servername, uint level, out SafeNetApiBuffer bufptr, uint prefmaxlen, out uint entriesread, out uint totalentries, ref uint resumehandle); + + /// + /// The NetWkstaUserGetInfo function returns information about the currently logged-on user. This function must be called in + /// the context of the logged-on user. + /// + /// This parameter must be set to NULL. + /// + /// Specifies the information level of the data. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// 0 + /// + /// Return the name of the user currently logged on to the workstation. The bufptr parameter points to a WKSTA_USER_INFO_0 structure. + /// + /// + /// + /// 1 + /// + /// Return information about the workstation, including the name of the current user and the domains accessed by the workstation. The + /// bufptr parameter points to a WKSTA_USER_INFO_1 structure. + /// + /// + /// + /// 1101 + /// Return domains browsed by the workstation. The bufptr parameter points to a WKSTA_USER_INFO_1101 structure. + /// + /// + /// + /// + /// Pointer to the buffer that receives the data. The format of this data depends on the value of the bufptr parameter. This buffer + /// is allocated by the system and must be freed using the NetApiBufferFree function. For more information, see Network Management + /// Function Buffers and Network Management Function Buffer Lengths. + /// + /// + /// If the function succeeds, the return value is NERR_Success. + /// If the function fails, the return value can be one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_NOT_ENOUGH_MEMORY + /// + /// The system ran out of memory resources. Either the network manager configuration is incorrect, or the program is running on a + /// system with insufficient memory. + /// + /// + /// + /// ERROR_INVALID_LEVEL + /// The level parameter is invalid. + /// + /// + /// ERROR_INVALID_PARAMETER + /// One of the function parameters is invalid. + /// + /// + /// + /// + /// The NetWkstaUserGetInfo function only works locally. + /// Examples + /// + /// The following code sample demonstrates how to retrieve information about the currently logged-on user using a call to the + /// NetWkstaUserGetInfo function. The sample calls NetWkstaUserGetInfo, specifying information level 1 ( + /// WKSTA_USER_INFO_1). If the call succeeds, the sample prints information about the logged-on user. Finally, the sample frees the + /// memory allocated for the information buffer. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmwksta/nf-lmwksta-netwkstausergetinfo NET_API_STATUS NET_API_FUNCTION + // NetWkstaUserGetInfo( LMSTR reserved, DWORD level, OUT LPBYTE *bufptr ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("lmwksta.h", MSDNShortId = "25ec7a49-fd26-4105-823b-a257a57f724e")] + public static extern Win32Error NetWkstaUserGetInfo([Optional] string reserved, uint level, out SafeNetApiBuffer bufptr); + + /// + /// The NetWkstaUserSetInfo function sets the user-specific information about the configuration elements for a workstation. + /// + /// This parameter must be set to zero. + /// + /// Specifies the information level of the data. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// 1 + /// + /// Specifies information about the workstation, including the name of the current user and the domains accessed by the workstation. + /// The buf parameter points to a WKSTA_USER_INFO_1 structure. + /// + /// + /// + /// 1101 + /// Specifies domains browsed by the workstation. The buf parameter points to a WKSTA_USER_INFO_1101 structure. + /// + /// + /// + /// + /// Pointer to the buffer that specifies the data. The format of this data depends on the value of the level parameter. For more + /// information, see Network Management Function Buffers. + /// + /// + /// Pointer to a value that receives the index of the first parameter that causes the ERROR_INVALID_PARAMETER error. If this + /// parameter is NULL, the index is not returned on error. + /// + /// + /// If the function succeeds, the return value is NERR_Success. + /// If the function fails, the return value can be one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_INVALID_LEVEL + /// The level parameter is invalid. + /// + /// + /// ERROR_INVALID_PARAMETER + /// One of the function parameters is invalid. + /// + /// + /// + /// + /// The NetWkstaUserSetInfo function only works locally. Administrator group membership is required. + /// + /// Domain names in the wkui1101_oth_domains member of the WKSTA_USER_INFO_1101 structure are separated by spaces. An empty + /// list is valid. A NULL pointer means to leave the member unmodified. The wkui1101_oth_domains member cannot be set + /// with MS-DOS. When setting this element, NetWkstaUserSetInfo rejects the request if the name list was invalid or if a name + /// could not be added to one or more of the network adapters managed by the system. + /// + /// + /// If the NetWkstaUserSetInfo function returns ERROR_INVALID_PARAMETER, you can use the parm_err parameter to indicate the + /// member of the workstation user information structure that is invalid. (A workstation user information structure begins with + /// WKSTA_USER_INFO_ and its format is specified by the level parameter.) The following table lists the value that can be returned in + /// the parm_err parameter and the corresponding structure member that is in error. (The prefix wkui*_ indicates that the member can + /// begin with multiple prefixes, for example, wkui0_ or wkui1_.) + /// + /// + /// + /// Value + /// Member + /// + /// + /// WKSTA_OTH_DOMAINS_PARMNUM + /// wkui*_oth_domains + /// + /// + /// Examples + /// + /// The following code sample demonstrates how to set user-specific information for a workstation using a call to the + /// NetWkstaUserSetInfo function, specifying information level 1101 ( WKSTA_USER_INFO_1101). + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmwksta/nf-lmwksta-netwkstausersetinfo NET_API_STATUS NET_API_FUNCTION + // NetWkstaUserSetInfo( LMSTR reserved, DWORD level, LPBYTE buf, LPDWORD parm_err ); + [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("lmwksta.h", MSDNShortId = "d48667a3-5ae9-4a7d-9af6-14f08835940d")] + public static extern Win32Error NetWkstaUserSetInfo([Optional] string reserved, uint level, IntPtr buf, out uint parm_err); + + /// + /// The WKSTA_INFO_100 structure contains information about a workstation environment, including platform-specific + /// information, the names of the domain and the local computer, and information concerning the operating system. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmwksta/ns-lmwksta-_wksta_info_100 typedef struct _WKSTA_INFO_100 { DWORD + // wki100_platform_id; LMSTR wki100_computername; LMSTR wki100_langroup; DWORD wki100_ver_major; DWORD wki100_ver_minor; } + // WKSTA_INFO_100, *PWKSTA_INFO_100, *LPWKSTA_INFO_100; + [PInvokeData("lmwksta.h", MSDNShortId = "c705dadd-cf55-44d9-bf36-09e078112479")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public struct WKSTA_INFO_100 + { + /// + /// Type: DWORD + /// The information level to use to retrieve platform-specific information. + /// Possible values for this member are listed in the Lmcons.h header file. + /// + /// + /// Value + /// Meaning + /// + /// + /// PLATFORM_ID_DOS 300 + /// The MS-DOS platform. + /// + /// + /// PLATFORM_ID_OS2 400 + /// The OS/2 platform. + /// + /// + /// PLATFORM_ID_NT 500 + /// The Windows NT platform. + /// + /// + /// PLATFORM_ID_OSF 600 + /// The OSF platform. + /// + /// + /// PLATFORM_ID_VMS 700 + /// The VMS platform. + /// + /// + /// + public PLATFORM_ID wki100_platform_id; + + /// + /// Type: LMSTR + /// A pointer to a string specifying the name of the local computer. + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + public string wki100_computername; + + /// + /// Type: LMSTR + /// A pointer to a string specifying the name of the domain to which the computer belongs. + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + public string wki100_langroup; + + /// + /// Type: DWORD + /// The major version number of the operating system running on the computer. + /// + public uint wki100_ver_major; + + /// + /// Type: DWORD + /// The minor version number of the operating system running on the computer. + /// + public uint wki100_ver_minor; + } + + /// + /// The WKSTA_INFO_101 structure contains information about a workstation environment, including platform-specific + /// information, the name of the domain and the local computer, and information concerning the operating system. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmwksta/ns-lmwksta-_wksta_info_101 typedef struct _WKSTA_INFO_101 { DWORD + // wki101_platform_id; LMSTR wki101_computername; LMSTR wki101_langroup; DWORD wki101_ver_major; DWORD wki101_ver_minor; LMSTR + // wki101_lanroot; } WKSTA_INFO_101, *PWKSTA_INFO_101, *LPWKSTA_INFO_101; + [PInvokeData("lmwksta.h", MSDNShortId = "2b692d40-6229-45ef-9ec6-ee464bba0696")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public struct WKSTA_INFO_101 + { + /// + /// Type: DWORD + /// The information level to use to retrieve platform-specific information. + /// Possible values for this member are listed in the Lmcons.h header file. + /// + /// + /// Value + /// Meaning + /// + /// + /// PLATFORM_ID_DOS 300 + /// The MS-DOS platform. + /// + /// + /// PLATFORM_ID_OS2 400 + /// The OS/2 platform. + /// + /// + /// PLATFORM_ID_NT 500 + /// The Windows NT platform. + /// + /// + /// PLATFORM_ID_OSF 600 + /// The OSF platform. + /// + /// + /// PLATFORM_ID_VMS 700 + /// The VMS platform. + /// + /// + /// + public PLATFORM_ID wki101_platform_id; + + /// + /// Type: LMSTR + /// A pointer to a string specifying the name of the local computer. + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + public string wki101_computername; + + /// + /// Type: LMSTR + /// A pointer to a string specifying the name of the domain to which the computer belongs. + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + public string wki101_langroup; + + /// + /// Type: DWORD + /// The major version number of the operating system running on the computer. + /// + public uint wki101_ver_major; + + /// + /// Type: DWORD + /// The minor version number of the operating system running on the computer. + /// + public uint wki101_ver_minor; + + /// + /// Type: LMSTR + /// A pointer to a string that contains the path to the LANMAN directory. + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + public string wki101_lanroot; + } + + public struct WKSTA_INFO_1010 + { + public uint wki1010_char_wait; + } + + public struct WKSTA_INFO_1011 + { + public uint wki1011_collection_time; + } + + public struct WKSTA_INFO_1012 + { + public uint wki1012_maximum_collection_count; + } + + public struct WKSTA_INFO_1013 + { + public uint wki1013_keep_conn; + } + + public struct WKSTA_INFO_1018 + { + public uint wki1018_sess_timeout; + } + + /// + /// The WKSTA_INFO_102 structure contains information about a workstation environment, including platform-specific + /// information, the name of the domain and the local computer, and information concerning the operating system. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmwksta/ns-lmwksta-_wksta_info_102 typedef struct _WKSTA_INFO_102 { DWORD + // wki102_platform_id; LMSTR wki102_computername; LMSTR wki102_langroup; DWORD wki102_ver_major; DWORD wki102_ver_minor; LMSTR + // wki102_lanroot; DWORD wki102_logged_on_users; } WKSTA_INFO_102, *PWKSTA_INFO_102, *LPWKSTA_INFO_102; + [PInvokeData("lmwksta.h", MSDNShortId = "01607fb5-c433-439c-aaaa-3736697f7c07")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public struct WKSTA_INFO_102 + { + /// + /// Type: DWORD + /// The information level to use to retrieve platform-specific information. + /// Possible values for this member are listed in the Lmcons.h header file. + /// + /// + /// Value + /// Meaning + /// + /// + /// PLATFORM_ID_DOS 300 + /// The MS-DOS platform. + /// + /// + /// PLATFORM_ID_OS2 400 + /// The OS/2 platform. + /// + /// + /// PLATFORM_ID_NT 500 + /// The Windows NT platform. + /// + /// + /// PLATFORM_ID_OSF 600 + /// The OSF platform. + /// + /// + /// PLATFORM_ID_VMS 700 + /// The VMS platform. + /// + /// + /// + public PLATFORM_ID wki102_platform_id; + + /// + /// Type: LMSTR + /// A pointer to a string specifying the name of the local computer. + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + public string wki102_computername; + + /// + /// Type: LMSTR + /// A pointer to a string specifying the name of the domain to which the computer belongs. + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + public string wki102_langroup; + + /// + /// Type: DWORD + /// The major version number of the operating system running on the computer. + /// + public uint wki102_ver_major; + + /// + /// Type: DWORD + /// The minor version number of the operating system running on the computer. + /// + public uint wki102_ver_minor; + + /// + /// Type: LMSTR + /// A pointer to a string that contains the path to the LANMAN directory. + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + public string wki102_lanroot; + + /// + /// Type: DWORD + /// The number of users who are logged on to the local computer. + /// + public uint wki102_logged_on_users; + } + + public struct WKSTA_INFO_1023 + { + public uint wki1023_siz_char_buf; + } + + public struct WKSTA_INFO_1027 + { + public uint wki1027_errlog_sz; + } + + public struct WKSTA_INFO_1028 + { + public uint wki1028_print_buf_time; + } + + public struct WKSTA_INFO_1032 + { + public uint wki1032_wrk_heuristics; + } + + public struct WKSTA_INFO_1033 + { + public uint wki1033_max_threads; + } + + public struct WKSTA_INFO_1041 + { + public uint wki1041_lock_quota; + } + + public struct WKSTA_INFO_1042 + { + public uint wki1042_lock_increment; + } + + public struct WKSTA_INFO_1043 + { + public uint wki1043_lock_maximum; + } + + public struct WKSTA_INFO_1044 + { + public uint wki1044_pipe_increment; + } + + public struct WKSTA_INFO_1045 + { + public uint wki1045_pipe_maximum; + } + + public struct WKSTA_INFO_1046 + { + public uint wki1046_dormant_file_limit; + } + + public struct WKSTA_INFO_1047 + { + public uint wki1047_cache_file_timeout; + } + + public struct WKSTA_INFO_1048 + { + [MarshalAs(UnmanagedType.Bool)] public bool wki1048_use_opportunistic_locking; + } + + public struct WKSTA_INFO_1049 + { + [MarshalAs(UnmanagedType.Bool)] public bool wki1049_use_unlock_behind; + } + + public struct WKSTA_INFO_1050 + { + [MarshalAs(UnmanagedType.Bool)] public bool wki1050_use_close_behind; + } + + public struct WKSTA_INFO_1051 + { + [MarshalAs(UnmanagedType.Bool)] public bool wki1051_buf_named_pipes; + } + + public struct WKSTA_INFO_1052 + { + [MarshalAs(UnmanagedType.Bool)] public bool wki1052_use_lock_read_unlock; + } + + public struct WKSTA_INFO_1053 + { + [MarshalAs(UnmanagedType.Bool)] public bool wki1053_utilize_nt_caching; + } + + public struct WKSTA_INFO_1054 + { + [MarshalAs(UnmanagedType.Bool)] public bool wki1054_use_raw_read; + } + + public struct WKSTA_INFO_1055 + { + [MarshalAs(UnmanagedType.Bool)] public bool wki1055_use_raw_write; + } + + public struct WKSTA_INFO_1056 + { + [MarshalAs(UnmanagedType.Bool)] public bool wki1056_use_write_raw_data; + } + + public struct WKSTA_INFO_1057 + { + [MarshalAs(UnmanagedType.Bool)] public bool wki1057_use_encryption; + } + + public struct WKSTA_INFO_1058 + { + [MarshalAs(UnmanagedType.Bool)] public bool wki1058_buf_files_deny_write; + } + + public struct WKSTA_INFO_1059 + { + [MarshalAs(UnmanagedType.Bool)] public bool wki1059_buf_read_only_files; + } + + public struct WKSTA_INFO_1060 + { + [MarshalAs(UnmanagedType.Bool)] public bool wki1060_force_core_create_mode; + } + + public struct WKSTA_INFO_1061 + { + [MarshalAs(UnmanagedType.Bool)] public bool wki1061_use_512_byte_max_transfer; + } + + public struct WKSTA_INFO_1062 + { + public uint wki1062_read_ahead_throughput; + } + + /// + /// Down-level NetWkstaGetInfo and NetWkstaSetInfo. DOS specific workstation information - admin or domain operator access + /// + [PInvokeData("lmwksta.h")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public struct WKSTA_INFO_302 + { + public uint wki302_char_wait; + public uint wki302_collection_time; + public uint wki302_maximum_collection_count; + public uint wki302_keep_conn; + public uint wki302_keep_search; + public uint wki302_max_cmds; + public uint wki302_num_work_buf; + public uint wki302_siz_work_buf; + public uint wki302_max_wrk_cache; + public uint wki302_sess_timeout; + public uint wki302_siz_error; + public uint wki302_num_alerts; + public uint wki302_num_services; + public uint wki302_errlog_sz; + public uint wki302_print_buf_time; + public uint wki302_num_char_buf; + public uint wki302_siz_char_buf; + public string wki302_wrk_heuristics; + public uint wki302_mailslots; + public uint wki302_num_dgram_buf; + } + + /// + /// Down-level NetWkstaGetInfo and NetWkstaSetInfo. OS/2 specific workstation information - admin or domain operator access + /// + [PInvokeData("lmwksta.h")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public struct WKSTA_INFO_402 + { + public uint wki402_char_wait; + public uint wki402_collection_time; + public uint wki402_maximum_collection_count; + public uint wki402_keep_conn; + public uint wki402_keep_search; + public uint wki402_max_cmds; + public uint wki402_num_work_buf; + public uint wki402_siz_work_buf; + public uint wki402_max_wrk_cache; + public uint wki402_sess_timeout; + public uint wki402_siz_error; + public uint wki402_num_alerts; + public uint wki402_num_services; + public uint wki402_errlog_sz; + public uint wki402_print_buf_time; + public uint wki402_num_char_buf; + public uint wki402_siz_char_buf; + public string wki402_wrk_heuristics; + public uint wki402_mailslots; + public uint wki402_num_dgram_buf; + public uint wki402_max_threads; + } + + /// The WKSTA_INFO_502 structure is obsolete. The structure contains information about a workstation environment. + // https://docs.microsoft.com/en-us/windows/desktop/api/lmwksta/ns-lmwksta-_wksta_info_502 typedef struct _WKSTA_INFO_502 { DWORD + // wki502_char_wait; DWORD wki502_collection_time; DWORD wki502_maximum_collection_count; DWORD wki502_keep_conn; DWORD + // wki502_max_cmds; DWORD wki502_sess_timeout; DWORD wki502_siz_char_buf; DWORD wki502_max_threads; DWORD wki502_lock_quota; DWORD + // wki502_lock_increment; DWORD wki502_lock_maximum; DWORD wki502_pipe_increment; DWORD wki502_pipe_maximum; DWORD + // wki502_cache_file_timeout; DWORD wki502_dormant_file_limit; DWORD wki502_read_ahead_throughput; DWORD wki502_num_mailslot_buffers; + // DWORD wki502_num_srv_announce_buffers; DWORD wki502_max_illegal_datagram_events; DWORD + // wki502_illegal_datagram_event_reset_frequency; BOOL wki502_log_election_packets; BOOL wki502_use_opportunistic_locking; BOOL + // wki502_use_unlock_behind; BOOL wki502_use_close_behind; BOOL wki502_buf_named_pipes; BOOL wki502_use_lock_read_unlock; BOOL + // wki502_utilize_nt_caching; BOOL wki502_use_raw_read; BOOL wki502_use_raw_write; BOOL wki502_use_write_raw_data; BOOL + // wki502_use_encryption; BOOL wki502_buf_files_deny_write; BOOL wki502_buf_read_only_files; BOOL wki502_force_core_create_mode; BOOL + // wki502_use_512_byte_max_transfer; } WKSTA_INFO_502, *PWKSTA_INFO_502, *LPWKSTA_INFO_502; + [PInvokeData("lmwksta.h", MSDNShortId = "716e700a-e464-47ec-a2df-74c03597ac6d")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public struct WKSTA_INFO_502 + { + /// + /// Type: DWORD + /// The number of seconds the computer waits for a remote resource to become available. + /// + public uint wki502_char_wait; + + /// + /// Type: DWORD + /// + /// The number of milliseconds the computer collects data before sending the data to a character device resource. The workstation + /// waits the specified time or collects the number of characters specified by the wki502_maximum_collection_count member, + /// whichever comes first. + /// + /// + public uint wki502_collection_time; + + /// + /// Type: DWORD + /// + /// The number of bytes of information the computer collects before sending the data to a character device resource. The + /// workstation collects the specified number of bytes or waits the period of time specified by the wki502_collection_time + /// member, whichever comes first. + /// + /// + public uint wki502_maximum_collection_count; + + /// + /// Type: DWORD + /// The number of seconds the server maintains an inactive connection to a server's resource. + /// + public uint wki502_keep_conn; + + /// + /// Type: DWORD + /// The number of simultaneous network device driver commands that can be sent to the network. + /// + public uint wki502_max_cmds; + + /// + /// Type: DWORD + /// The number of seconds the server waits before disconnecting an inactive session. + /// + public uint wki502_sess_timeout; + + /// + /// Type: DWORD + /// The maximum size, in bytes, of a character pipe buffer and device buffer. + /// + public uint wki502_siz_char_buf; + + /// + /// Type: DWORD + /// The number of threads the computer can dedicate to the network. + /// + public uint wki502_max_threads; + + /// + /// Type: DWORD + /// Reserved. + /// + public uint wki502_lock_quota; + + /// + /// Type: DWORD + /// Reserved. + /// + public uint wki502_lock_increment; + + /// + /// Type: DWORD + /// Reserved. + /// + public uint wki502_lock_maximum; + + /// + /// Type: DWORD + /// Reserved. + /// + public uint wki502_pipe_increment; + + /// + /// Type: DWORD + /// Reserved. + /// + public uint wki502_pipe_maximum; + + /// + /// Type: DWORD + /// Reserved. + /// + public uint wki502_cache_file_timeout; + + /// + /// Type: DWORD + /// Reserved. + /// + public uint wki502_dormant_file_limit; + + /// + /// Type: DWORD + /// Reserved. + /// + public uint wki502_read_ahead_throughput; + + /// + /// Type: DWORD + /// Reserved. + /// + public uint wki502_num_mailslot_buffers; + + /// + /// Type: DWORD + /// Reserved. + /// + public uint wki502_num_srv_announce_buffers; + + /// + /// Type: DWORD + /// Reserved. + /// + public uint wki502_max_illegal_datagram_events; + + /// + /// Type: DWORD + /// Reserved. + /// + public uint wki502_illegal_datagram_event_reset_frequency; + + /// + /// Type: BOOL + /// Reserved. + /// + [MarshalAs(UnmanagedType.Bool)] public bool wki502_log_election_packets; + + /// + /// Type: BOOL + /// Reserved. + /// + [MarshalAs(UnmanagedType.Bool)] public bool wki502_use_opportunistic_locking; + + /// + /// Type: BOOL + /// Reserved. + /// + [MarshalAs(UnmanagedType.Bool)] public bool wki502_use_unlock_behind; + + /// + /// Type: BOOL + /// Reserved. + /// + [MarshalAs(UnmanagedType.Bool)] public bool wki502_use_close_behind; + + /// + /// Type: BOOL + /// Reserved. + /// + [MarshalAs(UnmanagedType.Bool)] public bool wki502_buf_named_pipes; + + /// + /// Type: BOOL + /// Reserved. + /// + [MarshalAs(UnmanagedType.Bool)] public bool wki502_use_lock_read_unlock; + + /// + /// Type: BOOL + /// Reserved. + /// + [MarshalAs(UnmanagedType.Bool)] public bool wki502_utilize_nt_caching; + + /// + /// Type: BOOL + /// Reserved. + /// + [MarshalAs(UnmanagedType.Bool)] public bool wki502_use_raw_read; + + /// + /// Type: BOOL + /// Reserved. + /// + [MarshalAs(UnmanagedType.Bool)] public bool wki502_use_raw_write; + + /// + /// Type: BOOL + /// Reserved. + /// + [MarshalAs(UnmanagedType.Bool)] public bool wki502_use_write_raw_data; + + /// + /// Type: BOOL + /// Reserved. + /// + [MarshalAs(UnmanagedType.Bool)] public bool wki502_use_encryption; + + /// + /// Type: BOOL + /// Reserved. + /// + [MarshalAs(UnmanagedType.Bool)] public bool wki502_buf_files_deny_write; + + /// + /// Type: BOOL + /// Reserved. + /// + [MarshalAs(UnmanagedType.Bool)] public bool wki502_buf_read_only_files; + + /// + /// Type: BOOL + /// Reserved. + /// + [MarshalAs(UnmanagedType.Bool)] public bool wki502_force_core_create_mode; + + /// + /// Type: BOOL + /// Reserved. + /// + [MarshalAs(UnmanagedType.Bool)] public bool wki502_use_512_byte_max_transfer; + } + + /// + /// The WKSTA_TRANSPORT_INFO_0 structure contains information about the workstation transport protocol, such as Wide Area + /// Network (WAN) or NetBIOS. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmwksta/ns-lmwksta-_wksta_transport_info_0 typedef struct + // _WKSTA_TRANSPORT_INFO_0 { DWORD wkti0_quality_of_service; DWORD wkti0_number_of_vcs; LMSTR wkti0_transport_name; LMSTR + // wkti0_transport_address; BOOL wkti0_wan_ish; } WKSTA_TRANSPORT_INFO_0, *PWKSTA_TRANSPORT_INFO_0, *LPWKSTA_TRANSPORT_INFO_0; + [PInvokeData("lmwksta.h", MSDNShortId = "e7afe2a3-f729-4fd5-afc3-d3ffbd09e884")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public struct WKSTA_TRANSPORT_INFO_0 + { + /// + /// Specifies a value that determines the search order of the transport protocol with respect to other transport protocols. The + /// highest value is searched first. + /// + public uint wkti0_quality_of_service; + + /// Specifies the number of clients communicating with the server using this transport protocol. + public uint wkti0_number_of_vcs; + + /// Specifies the device name of the transport protocol. + public string wkti0_transport_name; + + /// + /// Specifies the address of the server on this transport protocol. + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + public string wkti0_transport_address; + + /// + /// + /// This member is ignored by the NetWkstaTransportAdd function. For the NetWkstaTransportEnum function, this member indicates + /// whether the transport protocol is a WAN transport protocol. This member is set to TRUE for NetBIOS/TCIP; it is set to + /// FALSE for NetBEUI and NetBIOS/IPX. + /// + /// + /// Certain legacy networking protocols, including NetBEUI, will no longer be supported. For more information, see Network + /// Protocol Support in Windows. + /// + /// + [MarshalAs(UnmanagedType.Bool)] public bool wkti0_wan_ish; + } + + /// The WKSTA_USER_INFO_0 structure contains the name of the user on a specified workstation. + // https://docs.microsoft.com/en-us/windows/desktop/api/lmwksta/ns-lmwksta-_wksta_user_info_0 typedef struct _WKSTA_USER_INFO_0 { + // LMSTR wkui0_username; } WKSTA_USER_INFO_0, *PWKSTA_USER_INFO_0, *LPWKSTA_USER_INFO_0; + [PInvokeData("lmwksta.h", MSDNShortId = "8bd8d8c7-4558-46cb-ab46-a2197d53e9f7")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public struct WKSTA_USER_INFO_0 + { + /// + /// Specifies the name of the user currently logged on to the workstation. + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + public string wkui0_username; + } + + /// + /// The WKSTA_USER_INFO_1 structure contains user information as it pertains to a specific workstation. The information + /// includes the name of the current user and the domains accessed by the workstation. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/lmwksta/ns-lmwksta-_wksta_user_info_1 typedef struct _WKSTA_USER_INFO_1 { + // LMSTR wkui1_username; LMSTR wkui1_logon_domain; LMSTR wkui1_oth_domains; LMSTR wkui1_logon_server; } WKSTA_USER_INFO_1, + // *PWKSTA_USER_INFO_1, *LPWKSTA_USER_INFO_1; + [PInvokeData("lmwksta.h", MSDNShortId = "a30747de-6cb0-41dc-95a7-be3d471056d5")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public struct WKSTA_USER_INFO_1 + { + /// + /// Specifies the name of the user currently logged on to the workstation. + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + public string wkui1_username; + + /// + /// Specifies the name of the domain in which the user is currently logged on. + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + public string wkui1_logon_domain; + + /// + /// Specifies the list of operating system domains browsed by the workstation. The domain names are separated by blanks. + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + public string wkui1_oth_domains; + + /// + /// Specifies the name of the server that authenticated the user. + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + public string wkui1_logon_server; + } + + /// The WKSTA_USER_INFO_1101 structure contains information about the domains accessed by a workstation. + // https://docs.microsoft.com/en-us/windows/desktop/api/lmwksta/ns-lmwksta-_wksta_user_info_1101 typedef struct _WKSTA_USER_INFO_1101 + // { LMSTR wkui1101_oth_domains; } WKSTA_USER_INFO_1101, *PWKSTA_USER_INFO_1101, *LPWKSTA_USER_INFO_1101; + [PInvokeData("lmwksta.h", MSDNShortId = "88772ba2-046b-4b03-ae02-d851075e4363")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public struct WKSTA_USER_INFO_1101 + { + /// + /// Specifies the list of operating system domains browsed by the workstation. The domain names are separated by blanks. + /// This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined. + /// + public string wkui1101_oth_domains; + } + } +} \ No newline at end of file diff --git a/PInvoke/NetApi32/Vanara.PInvoke.NetApi32.csproj b/PInvoke/NetApi32/Vanara.PInvoke.NetApi32.csproj index 3f9fd68c..80e86a77 100644 --- a/PInvoke/NetApi32/Vanara.PInvoke.NetApi32.csproj +++ b/PInvoke/NetApi32/Vanara.PInvoke.NetApi32.csproj @@ -25,10 +25,10 @@ Currently implements: Functions -DsAddressToSiteNamesA, DsAddressToSiteNamesExA, DsAddressToSiteNamesExW, DsAddressToSiteNamesW, DsDeregisterDnsHostRecordsA, DsDeregisterDnsHostRecordsW, DsEnumerateDomainTrustsA, DsEnumerateDomainTrustsW, DsGetDcCloseW, DsGetDcNameA, DsGetDcNameW, DsGetDcNextA, DsGetDcNextW, DsGetDcOpenA, DsGetDcOpenW, DsGetDcSiteCoverageA, DsGetDcSiteCoverageW, DsGetForestTrustInformationW, DsGetSiteNameA, DsGetSiteNameW, DsMergeForestTrustInformationW, DsRoleFreeMemory, DsRoleGetPrimaryDomainInformation, DsValidateSubnetNameA, DsValidateSubnetNameW, NetApiBufferFree, NetServerComputerNameAdd, NetServerComputerNameDel, NetServerDiskEnum, NetServerEnum, NetServerGetInfo, NetServerSetInfo, NetServerTransportAdd, NetServerTransportAddEx, NetServerTransportDel, NetServerTransportEnum +DavAddConnection, DavCancelConnectionsToServer, DavDeleteConnection, DavFlushFile, DavGetExtendedError, DavGetHTTPFromUNCPath, DavGetTheLockOwnerOfTheFile, DavGetUNCFromHTTPPath, DavInvalidateCache, DavRegisterAuthCallback, DavUnregisterAuthCallback, DsAddressToSiteNamesA, DsAddressToSiteNamesExA, DsAddressToSiteNamesExW, DsAddressToSiteNamesW, DsDeregisterDnsHostRecordsA, DsDeregisterDnsHostRecordsW, DsEnumerateDomainTrustsA, DsEnumerateDomainTrustsW, DsGetDcCloseW, DsGetDcNameA, DsGetDcNameW, DsGetDcNextA, DsGetDcNextW, DsGetDcOpenA, DsGetDcOpenW, DsGetDcSiteCoverageA, DsGetDcSiteCoverageW, DsGetForestTrustInformationW, DsGetSiteNameA, DsGetSiteNameW, DsMergeForestTrustInformationW, DsRoleFreeMemory, DsRoleGetPrimaryDomainInformation, DsValidateSubnetNameA, DsValidateSubnetNameW, NetAddAlternateComputerName, NetAlertRaise, NetAlertRaiseEx, NetApiBufferAllocate, NetApiBufferFree, NetApiBufferReallocate, NetApiBufferSize, NetConnectionEnum, NetCreateProvisioningPackage, NetEnumerateComputerNames, NetFileClose, NetFileEnum, NetFileGetInfo, NetFreeAadJoinInformation, NetGetAadJoinInformation, NetGetJoinableOUs, NetGetJoinInformation, NetJoinDomain, NetProvisionComputerAccount, NetRemoteComputerSupports, NetRemoteTOD, NetRemoveAlternateComputerName, NetRenameMachineInDomain, NetRequestOfflineDomainJoin, NetRequestProvisioningPackageInstall, NetServerComputerNameAdd, NetServerComputerNameDel, NetServerDiskEnum, NetServerEnum, NetServerGetInfo, NetServerSetInfo, NetServerTransportAdd, NetServerTransportAddEx, NetServerTransportDel, NetServerTransportEnum, NetSessionDel, NetSessionEnum, NetSessionGetInfo, NetSetPrimaryComputerName, NetShareAdd, NetShareCheck, NetShareDel, NetShareDelEx, NetShareEnum, NetShareGetInfo, NetShareSetInfo, NetUnjoinDomain, NetUseAdd, NetUseDel, NetUseEnum, NetUseGetInfo, NetValidateName, NetWkstaGetInfo, NetWkstaSetInfo, NetWkstaTransportAdd, NetWkstaTransportDel, NetWkstaTransportEnum, NetWkstaUserEnum, NetWkstaUserGetInfo, NetWkstaUserSetInfo Structures -DOMAIN_CONTROLLER_INFO, DS_DOMAIN_TRUSTS, DSROLE_OPERATION_STATE_INFO, DSROLE_PRIMARY_DOMAIN_INFO_BASIC, DSROLE_UPGRADE_STATUS_INFO, SERVER_INFO_100, SERVER_INFO_101, SERVER_INFO_102, SERVER_INFO_402, SERVER_INFO_403, SERVER_TRANSPORT_INFO_0, SERVER_TRANSPORT_INFO_1, SERVER_TRANSPORT_INFO_2, SERVER_TRANSPORT_INFO_3 +DAV_CALLBACK_AUTH_BLOB, DAV_CALLBACK_AUTH_UNP, DAV_CALLBACK_CRED, DOMAIN_CONTROLLER_INFO, DS_DOMAIN_TRUSTS, DSROLE_OPERATION_STATE_INFO, DSROLE_PRIMARY_DOMAIN_INFO_BASIC, DSROLE_UPGRADE_STATUS_INFO, ADMIN_OTHER_INFO, ERRLOG_OTHER_INFO, PRINT_OTHER_INFO, STD_ALERT, USER_OTHER_INFO, DSREG_USER_INFO, NETSETUP_PROVISIONING_PARAMS, TIME_OF_DAY_INFO, SERVER_INFO_100, SERVER_INFO_101, SERVER_INFO_102, SERVER_INFO_402, SERVER_INFO_403, SERVER_TRANSPORT_INFO_0, SERVER_TRANSPORT_INFO_1, SERVER_TRANSPORT_INFO_2, SERVER_TRANSPORT_INFO_3, CONNECTION_INFO_0, CONNECTION_INFO_1, FILE_INFO_2, FILE_INFO_3, SESSION_INFO_0, SESSION_INFO_1, SESSION_INFO_10, SESSION_INFO_2, SESSION_INFO_502, SHARE_INFO_0, SHARE_INFO_1, SHARE_INFO_1004, SHARE_INFO_1005, SHARE_INFO_1006, SHARE_INFO_1501, SHARE_INFO_2, SHARE_INFO_502, SHARE_INFO_503, USE_INFO_0, USE_INFO_1, USE_INFO_2, USE_INFO_3, USE_INFO_4, USE_INFO_5, WKSTA_INFO_100, WKSTA_INFO_101, WKSTA_INFO_1010, WKSTA_INFO_1011, WKSTA_INFO_1012, WKSTA_INFO_1013, WKSTA_INFO_1018, WKSTA_INFO_102, WKSTA_INFO_1023, WKSTA_INFO_1027, WKSTA_INFO_1028, WKSTA_INFO_1032, WKSTA_INFO_1033, WKSTA_INFO_1041, WKSTA_INFO_1042, WKSTA_INFO_1043, WKSTA_INFO_1044, WKSTA_INFO_1045, WKSTA_INFO_1046, WKSTA_INFO_1047, WKSTA_INFO_1048, WKSTA_INFO_1049, WKSTA_INFO_1050, WKSTA_INFO_1051, WKSTA_INFO_1052, WKSTA_INFO_1053, WKSTA_INFO_1054, WKSTA_INFO_1055, WKSTA_INFO_1056, WKSTA_INFO_1057, WKSTA_INFO_1058, WKSTA_INFO_1059, WKSTA_INFO_1060, WKSTA_INFO_1061, WKSTA_INFO_1062, WKSTA_INFO_302, WKSTA_INFO_402, WKSTA_INFO_502, WKSTA_TRANSPORT_INFO_0, WKSTA_USER_INFO_0, WKSTA_USER_INFO_1, WKSTA_USER_INFO_1101 latest @@ -47,9 +47,30 @@ DOMAIN_CONTROLLER_INFO, DS_DOMAIN_TRUSTS, DSROLE_OPERATION_STATE_INFO, DSROLE_PR + + 4.5.0 + + + 4.5.0 + + + + + 4.5.0 + + + + + 4.5.0 + + + + + 4.5.0 +