jwalmjoin.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. {******************************************************************************}
  2. { }
  3. { Lan Manager Join API interface Unit for Object Pascal }
  4. { }
  5. { Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft }
  6. { Corporation. All Rights Reserved. }
  7. { }
  8. { The original file is: lmjoin.h, released November 2001. The original Pascal }
  9. { code is: LmJoin.pas, released Februari 2002. The initial developer of the }
  10. { Pascal code is Marcel van Brakel (brakelm att chello dott nl). }
  11. { }
  12. { Portions created by Marcel van Brakel are Copyright (C) 1999-2001 }
  13. { Marcel van Brakel. All Rights Reserved. }
  14. { }
  15. { Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI) }
  16. { }
  17. { You may retrieve the latest version of this file at the Project JEDI }
  18. { APILIB home page, located at http://jedi-apilib.sourceforge.net }
  19. { }
  20. { The contents of this file are used with permission, subject to the Mozilla }
  21. { Public License Version 1.1 (the "License"); you may not use this file except }
  22. { in compliance with the License. You may obtain a copy of the License at }
  23. { http://www.mozilla.org/MPL/MPL-1.1.html }
  24. { }
  25. { Software distributed under the License is distributed on an "AS IS" basis, }
  26. { WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
  27. { the specific language governing rights and limitations under the License. }
  28. { }
  29. { Alternatively, the contents of this file may be used under the terms of the }
  30. { GNU Lesser General Public License (the "LGPL License"), in which case the }
  31. { provisions of the LGPL License are applicable instead of those above. }
  32. { If you wish to allow use of your version of this file only under the terms }
  33. { of the LGPL License and not to allow others to use your version of this file }
  34. { under the MPL, indicate your decision by deleting the provisions above and }
  35. { replace them with the notice and other provisions required by the LGPL }
  36. { License. If you do not delete the provisions above, a recipient may use }
  37. { your version of this file under either the MPL or the LGPL License. }
  38. { }
  39. { For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
  40. { }
  41. {******************************************************************************}
  42. // $Id: JwaLmJoin.pas,v 1.11 2005/09/07 09:54:54 marquardt Exp $
  43. {$IFNDEF JWA_INCLUDEMODE}
  44. unit JwaLmJoin;
  45. {$WEAKPACKAGEUNIT}
  46. {$I jediapilib.inc}
  47. interface
  48. uses
  49. JwaWindows, JwaLmCons;
  50. {$ENDIF !JWA_INCLUDEMODE}
  51. {$IFDEF JWA_INTERFACESECTION}
  52. {$HPPEMIT ''}
  53. {$HPPEMIT '#include "lmjoin.h"'}
  54. {$HPPEMIT ''}
  55. //
  56. // Types of name that can be validated
  57. //
  58. type
  59. _NETSETUP_NAME_TYPE = (
  60. NetSetupUnknown,
  61. NetSetupMachine,
  62. NetSetupWorkgroup,
  63. NetSetupDomain,
  64. NetSetupNonExistentDomain
  65. {$IFDEF WIN2000_UP}
  66. , NetSetupDnsMachine
  67. {$ENDIF WIN2000_UP}
  68. );
  69. {$EXTERNALSYM _NETSETUP_NAME_TYPE}
  70. NETSETUP_NAME_TYPE = _NETSETUP_NAME_TYPE;
  71. {$EXTERNALSYM NETSETUP_NAME_TYPE}
  72. PNETSETUP_NAME_TYPE = ^NETSETUP_NAME_TYPE;
  73. {$EXTERNALSYM PNETSETUP_NAME_TYPE}
  74. TNetSetupNameType = NETSETUP_NAME_TYPE;
  75. PNetSetupNameType = PNETSETUP_NAME_TYPE;
  76. //
  77. // Status of a workstation
  78. //
  79. _NETSETUP_JOIN_STATUS = (
  80. NetSetupUnknownStatus,
  81. NetSetupUnjoined,
  82. NetSetupWorkgroupName,
  83. NetSetupDomainName);
  84. {$EXTERNALSYM _NETSETUP_JOIN_STATUS}
  85. NETSETUP_JOIN_STATUS = _NETSETUP_JOIN_STATUS;
  86. {$EXTERNALSYM NETSETUP_JOIN_STATUS}
  87. PNETSETUP_JOIN_STATUS = ^NETSETUP_JOIN_STATUS;
  88. {$EXTERNALSYM PNETSETUP_JOIN_STATUS}
  89. TNetSetupJoinStatus = NETSETUP_JOIN_STATUS;
  90. PNetSetupJoinStatus = PNETSETUP_JOIN_STATUS;
  91. //
  92. // Flags to determine the behavior of the join/unjoin APIs
  93. //
  94. const
  95. NETSETUP_JOIN_DOMAIN = $00000001; // If not present, workgroup is joined
  96. {$EXTERNALSYM NETSETUP_JOIN_DOMAIN}
  97. NETSETUP_ACCT_CREATE = $00000002; // Do the server side account creation/rename
  98. {$EXTERNALSYM NETSETUP_ACCT_CREATE}
  99. NETSETUP_ACCT_DELETE = $00000004; // Delete the account when a domain is left
  100. {$EXTERNALSYM NETSETUP_ACCT_DELETE}
  101. NETSETUP_WIN9X_UPGRADE = $00000010; // Invoked during upgrade of Windows 9x to
  102. {$EXTERNALSYM NETSETUP_WIN9X_UPGRADE}
  103. // Windows NT
  104. NETSETUP_DOMAIN_JOIN_IF_JOINED = $00000020; // Allow the client to join a new domain
  105. {$EXTERNALSYM NETSETUP_DOMAIN_JOIN_IF_JOINED}
  106. // even if it is already joined to a domain
  107. NETSETUP_JOIN_UNSECURE = $00000040; // Performs an unsecure join
  108. {$EXTERNALSYM NETSETUP_JOIN_UNSECURE}
  109. NETSETUP_MACHINE_PWD_PASSED = $00000080; // Indicates that the machine (not user) password
  110. {$EXTERNALSYM NETSETUP_MACHINE_PWD_PASSED}
  111. // is passed. Valid only for unsecure joins
  112. NETSETUP_DEFER_SPN_SET = $00000100; // Specifies that writting SPN and DnsHostName
  113. {$EXTERNALSYM NETSETUP_DEFER_SPN_SET}
  114. // attributes on the computer object should be
  115. // defered until rename that will follow join
  116. NETSETUP_INSTALL_INVOCATION = $00040000; // The APIs were invoked during install
  117. {$EXTERNALSYM NETSETUP_INSTALL_INVOCATION}
  118. NETSETUP_IGNORE_UNSUPPORTED_FLAGS = $10000000; // If this bit is set, unrecognized flags
  119. // will be ignored by the NetJoin API and
  120. // the API will behave as if the flags
  121. // were not set.
  122. {$EXTERNALSYM NETSETUP_IGNORE_UNSUPPORTED_FLAGS}
  123. NETSETUP_VALID_UNJOIN_FLAGS = NETSETUP_ACCT_DELETE or NETSETUP_IGNORE_UNSUPPORTED_FLAGS;
  124. {$EXTERNALSYM NETSETUP_VALID_UNJOIN_FLAGS}
  125. //
  126. // 0x80000000 is reserved for internal use only
  127. //
  128. //
  129. // Joins a machine to the domain.
  130. //
  131. function NetJoinDomain(lpServer, lpDomain, lpAccountOU, lpAccount, lpPassword: LPCWSTR; fJoinOptions: DWORD): NET_API_STATUS; stdcall;
  132. {$EXTERNALSYM NetJoinDomain}
  133. function NetUnjoinDomain(lpServer, lpAccount, lpPassword: LPCWSTR; fUnjoinOptions: DWORD): NET_API_STATUS; stdcall;
  134. {$EXTERNALSYM NetUnjoinDomain}
  135. function NetRenameMachineInDomain(lpServer, lpNewMachineName, lpAccount, lpPassword: LPCWSTR; fRenameOptions: DWORD): NET_API_STATUS; stdcall;
  136. {$EXTERNALSYM NetRenameMachineInDomain}
  137. //
  138. // Determine the validity of a name
  139. //
  140. function NetValidateName(lpServer, lpName, lpAccount, lpPassword: LPCWSTR; NameType: NETSETUP_NAME_TYPE): NET_API_STATUS; stdcall;
  141. {$EXTERNALSYM NetValidateName}
  142. //
  143. // Determines whether a workstation is joined to a domain or not
  144. //
  145. function NetGetJoinInformation(lpServer: LPCWSTR; var lpNameBuffer: LPWSTR; BufferType: PNETSETUP_JOIN_STATUS): NET_API_STATUS; stdcall;
  146. {$EXTERNALSYM NetGetJoinInformation}
  147. //
  148. // Determines the list of OUs that the client can create a machine account in
  149. //
  150. function NetGetJoinableOUs(lpServer, lpDomain, lpAccount, lpPassword: LPCWSTR; OUCount: LPDWORD; var OUs: LPLPWSTR): NET_API_STATUS; stdcall;
  151. {$EXTERNALSYM NetGetJoinableOUs}
  152. //
  153. // Computer rename preparation APIs
  154. //
  155. const
  156. NET_IGNORE_UNSUPPORTED_FLAGS = $01;
  157. {$EXTERNALSYM NET_IGNORE_UNSUPPORTED_FLAGS}
  158. function NetAddAlternateComputerName(Server, AlternateName, DomainAccount, DomainAccountPassword: LPCWSTR; Reserved: ULONG): NET_API_STATUS; stdcall;
  159. {$EXTERNALSYM NetAddAlternateComputerName}
  160. function NetRemoveAlternateComputerName(Server, AlternateName, DomainAccount, DomainAccountPassword: LPCWSTR; Reserved: ULONG): NET_API_STATUS; stdcall;
  161. {$EXTERNALSYM NetRemoveAlternateComputerName}
  162. function NetSetPrimaryComputerName(Server, PrimaryName, DomainAccount, DomainAccountPassword: LPCWSTR; Reserved: ULONG): NET_API_STATUS; stdcall;
  163. {$EXTERNALSYM NetSetPrimaryComputerName}
  164. //
  165. // The following enumeration must be kept
  166. // in sync with COMPUTER_NAME_TYPE defined
  167. // in winbase.h
  168. //
  169. type
  170. _NET_COMPUTER_NAME_TYPE = (
  171. NetPrimaryComputerName,
  172. NetAlternateComputerNames,
  173. NetAllComputerNames,
  174. NetComputerNameTypeMax);
  175. {$EXTERNALSYM _NET_COMPUTER_NAME_TYPE}
  176. NET_COMPUTER_NAME_TYPE = _NET_COMPUTER_NAME_TYPE;
  177. {$EXTERNALSYM NET_COMPUTER_NAME_TYPE}
  178. PNET_COMPUTER_NAME_TYPE = ^NET_COMPUTER_NAME_TYPE;
  179. {$EXTERNALSYM PNET_COMPUTER_NAME_TYPE}
  180. TNetComputerNameType = NET_COMPUTER_NAME_TYPE;
  181. PNetComputerNameType = PNET_COMPUTER_NAME_TYPE;
  182. function NetEnumerateComputerNames(Server: LPCWSTR; NameType: NET_COMPUTER_NAME_TYPE; Reserved: ULONG; EntryCount: PDWORD; var ComputerNames: LPLPWSTR): NET_API_STATUS; stdcall;
  183. {$EXTERNALSYM NetEnumerateComputerNames}
  184. {$ENDIF JWA_INTERFACESECTION}
  185. {$IFNDEF JWA_INCLUDEMODE}
  186. implementation
  187. uses
  188. JwaWinDLLNames;
  189. {$ENDIF !JWA_INCLUDEMODE}
  190. {$IFDEF JWA_IMPLEMENTATIONSECTION}
  191. {$IFDEF DYNAMIC_LINK}
  192. var
  193. _NetJoinDomain: Pointer;
  194. function NetJoinDomain;
  195. begin
  196. GetProcedureAddress(_NetJoinDomain, netapi32, 'NetJoinDomain');
  197. asm
  198. MOV ESP, EBP
  199. POP EBP
  200. JMP [_NetJoinDomain]
  201. end;
  202. end;
  203. var
  204. _NetUnjoinDomain: Pointer;
  205. function NetUnjoinDomain;
  206. begin
  207. GetProcedureAddress(_NetUnjoinDomain, netapi32, 'NetUnjoinDomain');
  208. asm
  209. MOV ESP, EBP
  210. POP EBP
  211. JMP [_NetUnjoinDomain]
  212. end;
  213. end;
  214. var
  215. _NetRenameMachineInDomain: Pointer;
  216. function NetRenameMachineInDomain;
  217. begin
  218. GetProcedureAddress(_NetRenameMachineInDomain, netapi32, 'NetRenameMachineInDomain');
  219. asm
  220. MOV ESP, EBP
  221. POP EBP
  222. JMP [_NetRenameMachineInDomain]
  223. end;
  224. end;
  225. var
  226. _NetValidateName: Pointer;
  227. function NetValidateName;
  228. begin
  229. GetProcedureAddress(_NetValidateName, netapi32, 'NetValidateName');
  230. asm
  231. MOV ESP, EBP
  232. POP EBP
  233. JMP [_NetValidateName]
  234. end;
  235. end;
  236. var
  237. _NetGetJoinInformation: Pointer;
  238. function NetGetJoinInformation;
  239. begin
  240. GetProcedureAddress(_NetGetJoinInformation, netapi32, 'NetGetJoinInformation');
  241. asm
  242. MOV ESP, EBP
  243. POP EBP
  244. JMP [_NetGetJoinInformation]
  245. end;
  246. end;
  247. var
  248. _NetGetJoinableOUs: Pointer;
  249. function NetGetJoinableOUs;
  250. begin
  251. GetProcedureAddress(_NetGetJoinableOUs, netapi32, 'NetGetJoinableOUs');
  252. asm
  253. MOV ESP, EBP
  254. POP EBP
  255. JMP [_NetGetJoinableOUs]
  256. end;
  257. end;
  258. var
  259. _NetAddAlternateComputerName: Pointer;
  260. function NetAddAlternateComputerName;
  261. begin
  262. GetProcedureAddress(_NetAddAlternateComputerName, netapi32, 'NetAddAlternateComputerName');
  263. asm
  264. MOV ESP, EBP
  265. POP EBP
  266. JMP [_NetAddAlternateComputerName]
  267. end;
  268. end;
  269. var
  270. _NetRemoveAlternateComputerName: Pointer;
  271. function NetRemoveAlternateComputerName;
  272. begin
  273. GetProcedureAddress(_NetRemoveAlternateComputerName, netapi32, 'NetRemoveAlternateComputerName');
  274. asm
  275. MOV ESP, EBP
  276. POP EBP
  277. JMP [_NetRemoveAlternateComputerName]
  278. end;
  279. end;
  280. var
  281. _NetSetPrimaryComputerName: Pointer;
  282. function NetSetPrimaryComputerName;
  283. begin
  284. GetProcedureAddress(_NetSetPrimaryComputerName, netapi32, 'NetSetPrimaryComputerName');
  285. asm
  286. MOV ESP, EBP
  287. POP EBP
  288. JMP [_NetSetPrimaryComputerName]
  289. end;
  290. end;
  291. var
  292. _NetEnumerateComputerNames: Pointer;
  293. function NetEnumerateComputerNames;
  294. begin
  295. GetProcedureAddress(_NetEnumerateComputerNames, netapi32, 'NetEnumerateComputerNames');
  296. asm
  297. MOV ESP, EBP
  298. POP EBP
  299. JMP [_NetEnumerateComputerNames]
  300. end;
  301. end;
  302. {$ELSE}
  303. function NetJoinDomain; external netapi32 name 'NetJoinDomain';
  304. function NetUnjoinDomain; external netapi32 name 'NetUnjoinDomain';
  305. function NetRenameMachineInDomain; external netapi32 name 'NetRenameMachineInDomain';
  306. function NetValidateName; external netapi32 name 'NetValidateName';
  307. function NetGetJoinInformation; external netapi32 name 'NetGetJoinInformation';
  308. function NetGetJoinableOUs; external netapi32 name 'NetGetJoinableOUs';
  309. function NetAddAlternateComputerName; external netapi32 name 'NetAddAlternateComputerName';
  310. function NetRemoveAlternateComputerName; external netapi32 name 'NetRemoveAlternateComputerName';
  311. function NetSetPrimaryComputerName; external netapi32 name 'NetSetPrimaryComputerName';
  312. function NetEnumerateComputerNames; external netapi32 name 'NetEnumerateComputerNames';
  313. {$ENDIF DYNAMIC_LINK}
  314. {$ENDIF JWA_IMPLEMENTATIONSECTION}
  315. {$IFNDEF JWA_INCLUDEMODE}
  316. end.
  317. {$ENDIF !JWA_INCLUDEMODE}