JwaDSRole.pas
上传用户:davidchvip
上传日期:2009-07-28
资源大小:1749k
文件大小:8k
源码类别:

Windows编程

开发平台:

Delphi

  1. {******************************************************************************}
  2. {                                                                       }
  3. { Directory Services 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: dsrole.h, released June 2000. The original Pascal      }
  9. { code is: DsRole.pas, released December 2000. The initial developer of the    }
  10. { Pascal code is Marcel van Brakel (brakelm@chello.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 home    }
  18. { page, located at http://delphi-jedi.org or my personal homepage located at   }
  19. { http://members.chello.nl/m.vanbrakel2                                        }
  20. {                }
  21. { The contents of this file are used with permission, subject to the Mozilla   }
  22. { Public License Version 1.1 (the "License"); you may not use this file except }
  23. { in compliance with the License. You may obtain a copy of the License at      }
  24. { http://www.mozilla.org/MPL/MPL-1.1.html                                      }
  25. {                                                                              }
  26. { Software distributed under the License is distributed on an "AS IS" basis,   }
  27. { WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
  28. { the specific language governing rights and limitations under the License.    }
  29. {                                                                              }
  30. { Alternatively, the contents of this file may be used under the terms of the  }
  31. { GNU Lesser General Public License (the  "LGPL License"), in which case the   }
  32. { provisions of the LGPL License are applicable instead of those above.        }
  33. { If you wish to allow use of your version of this file only under the terms   }
  34. { of the LGPL License and not to allow others to use your version of this file }
  35. { under the MPL, indicate your decision by deleting  the provisions above and  }
  36. { replace  them with the notice and other provisions required by the LGPL      }
  37. { License.  If you do not delete the provisions above, a recipient may use     }
  38. { your version of this file under either the MPL or the LGPL License.          }
  39. {                 }
  40. { For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
  41. {                 }
  42. {******************************************************************************}
  43. unit JwaDSRole;
  44. {$WEAKPACKAGEUNIT}
  45. {$HPPEMIT ''}
  46. {$HPPEMIT '#include "dsrole.h"'}
  47. {$HPPEMIT ''}
  48. {$I WINDEFINES.INC}
  49. interface
  50. uses
  51.   JwaWinType;
  52. //
  53. // Domain information
  54. //
  55. type
  56.   _DSROLE_MACHINE_ROLE = (
  57.     DsRole_RoleStandaloneWorkstation,
  58.     DsRole_RoleMemberWorkstation,
  59.     DsRole_RoleStandaloneServer,
  60.     DsRole_RoleMemberServer,
  61.     DsRole_RoleBackupDomainController,
  62.     DsRole_RolePrimaryDomainController);
  63.   {$EXTERNALSYM _DSROLE_MACHINE_ROLE}
  64.   DSROLE_MACHINE_ROLE = _DSROLE_MACHINE_ROLE;
  65.   {$EXTERNALSYM DSROLE_MACHINE_ROLE}
  66.   TDsRoleMachineRole = DSROLE_MACHINE_ROLE;
  67. //
  68. // Previous server state
  69. //
  70.   _DSROLE_SERVER_STATE = (
  71.     DsRoleServerUnknown,
  72.     DsRoleServerPrimary,
  73.     DsRoleServerBackup);
  74.   {$EXTERNALSYM DSROLE_SERVER_STATE}
  75.   DSROLE_SERVER_STATE = _DSROLE_SERVER_STATE;
  76.   {$EXTERNALSYM DSROLE_SERVER_STATE}
  77.   PDSROLE_SERVER_STATE = ^DSROLE_SERVER_STATE;
  78.   {$EXTERNALSYM PDSROLE_SERVER_STATE}
  79.   TDsRoleServerState = DSROLE_SERVER_STATE;
  80.   _DSROLE_PRIMARY_DOMAIN_INFO_LEVEL = (
  81.     DsRoleFiller0,
  82.     DsRolePrimaryDomainInfoBasic,
  83.     DsRoleUpgradeStatus,
  84.     DsRoleOperationState);
  85.   {$EXTERNALSYM _DSROLE_PRIMARY_DOMAIN_INFO_LEVEL}
  86.   DSROLE_PRIMARY_DOMAIN_INFO_LEVEL = _DSROLE_PRIMARY_DOMAIN_INFO_LEVEL;
  87.   {$EXTERNALSYM DSROLE_PRIMARY_DOMAIN_INFO_LEVEL}
  88.   TDsRolePrimaryDomainInfoLevel = DSROLE_PRIMARY_DOMAIN_INFO_LEVEL;
  89. //
  90. // Flags to be used with the PRIMARY_DOMAIN_INFO_LEVEL structures below
  91. //
  92. const
  93.   DSROLE_PRIMARY_DS_RUNNING          = $00000001;
  94.   {$EXTERNALSYM DSROLE_PRIMARY_DS_RUNNING}
  95.   DSROLE_PRIMARY_DS_MIXED_MODE       = $00000002;
  96.   {$EXTERNALSYM DSROLE_PRIMARY_DS_MIXED_MODE}
  97.   DSROLE_UPGRADE_IN_PROGRESS         = $00000004;
  98.   {$EXTERNALSYM DSROLE_UPGRADE_IN_PROGRESS}
  99.   DSROLE_PRIMARY_DOMAIN_GUID_PRESENT = $01000000;
  100.   {$EXTERNALSYM DSROLE_PRIMARY_DOMAIN_GUID_PRESENT}
  101. //
  102. // Structure that correspond to the DSROLE_PRIMARY_DOMAIN_INFO_LEVEL
  103. //
  104. type
  105.   PDSROLE_PRIMARY_DOMAIN_INFO_BASIC = ^DSROLE_PRIMARY_DOMAIN_INFO_BASIC;
  106.   {$EXTERNALSYM PDSROLE_PRIMARY_DOMAIN_INFO_BASIC}
  107.   _DSROLE_PRIMARY_DOMAIN_INFO_BASIC = record
  108.     MachineRole: DSROLE_MACHINE_ROLE;
  109.     Flags: ULONG;
  110.     DomainNameFlat: LPWSTR;
  111.     DomainNameDns: LPWSTR;
  112.     DomainForestName: LPWSTR;
  113.     DomainGuid: GUID;
  114.   end;
  115.   {$EXTERNALSYM _DSROLE_PRIMARY_DOMAIN_INFO_BASIC}
  116.   DSROLE_PRIMARY_DOMAIN_INFO_BASIC = _DSROLE_PRIMARY_DOMAIN_INFO_BASIC;
  117.   {$EXTERNALSYM DSROLE_PRIMARY_DOMAIN_INFO_BASIC}
  118.   TDsRolePrimaryDomainInfoBasic = DSROLE_PRIMARY_DOMAIN_INFO_BASIC;
  119.   PDsRolePrimaryDomainInfoBasic = PDSROLE_PRIMARY_DOMAIN_INFO_BASIC;
  120.   PDSROLE_UPGRADE_STATUS_INFO = ^DSROLE_UPGRADE_STATUS_INFO;
  121.   {$EXTERNALSYM PDSROLE_UPGRADE_STATUS_INFO}
  122.   _DSROLE_UPGRADE_STATUS_INFO = record
  123.     OperationState: ULONG;
  124.     PreviousServerState: DSROLE_SERVER_STATE;
  125.   end;
  126.   {$EXTERNALSYM _DSROLE_UPGRADE_STATUS_INFO}
  127.   DSROLE_UPGRADE_STATUS_INFO = _DSROLE_UPGRADE_STATUS_INFO;
  128.   {$EXTERNALSYM DSROLE_UPGRADE_STATUS_INFO}
  129.   TDsRoleUpgradeStatusInfo = DSROLE_UPGRADE_STATUS_INFO;
  130.   PDsRoleUpgradeStatusInfo = PDSROLE_UPGRADE_STATUS_INFO;
  131.   _DSROLE_OPERATION_STATE = (
  132.     DsRoleOperationIdle,
  133.     DsRoleOperationActive,
  134.     DsRoleOperationNeedReboot);
  135.   {$EXTERNALSYM _DSROLE_OPERATION_STATE}
  136.   DSROLE_OPERATION_STATE = _DSROLE_OPERATION_STATE;
  137.   {$EXTERNALSYM DSROLE_OPERATION_STATE}
  138.   TDsRoleOperationState = DSROLE_OPERATION_STATE;
  139.   PDSROLE_OPERATION_STATE_INFO = ^DSROLE_OPERATION_STATE_INFO;
  140.   {$EXTERNALSYM PDSROLE_OPERATION_STATE_INFO}
  141.   _DSROLE_OPERATION_STATE_INFO = record
  142.     OperationState: DSROLE_OPERATION_STATE;
  143.   end;
  144.   {$EXTERNALSYM _DSROLE_OPERATION_STATE_INFO}
  145.   DSROLE_OPERATION_STATE_INFO = _DSROLE_OPERATION_STATE_INFO;
  146.   {$EXTERNALSYM DSROLE_OPERATION_STATE_INFO}
  147.   TDsRoleOperationStateInfo = DSROLE_OPERATION_STATE_INFO;
  148.   PDsRoleOperationStateInfo = PDSROLE_OPERATION_STATE_INFO;
  149. function DsRoleGetPrimaryDomainInformation(lpServer: LPCWSTR;
  150.   InfoLevel: DSROLE_PRIMARY_DOMAIN_INFO_LEVEL; var Buffer: PVOID): DWORD; stdcall;
  151. {$EXTERNALSYM DsRoleGetPrimaryDomainInformation}
  152. procedure DsRoleFreeMemory(Buffer: PVOID); stdcall;
  153. {$EXTERNALSYM DsRoleFreeMemory}
  154. implementation
  155. const
  156.   netapi32 = 'netapi32.dll';
  157. {$IFDEF DYNAMIC_LINK}
  158. var
  159.   _DsRoleGetPrimaryDomainInfo: Pointer;
  160. function DsRoleGetPrimaryDomainInformation;
  161. begin
  162.   GetProcedureAddress(_DsRoleGetPrimaryDomainInfo, netapi32, 'DsRoleGetPrimaryDomainInformation');
  163.   asm
  164.     mov esp, ebp
  165.     pop ebp
  166.     jmp [_DsRoleGetPrimaryDomainInfo]
  167.   end;
  168. end;
  169. {$ELSE}
  170. function DsRoleGetPrimaryDomainInformation; external netapi32 name 'DsRoleGetPrimaryDomainInformation';
  171. {$ENDIF DYNAMIC_LINK}
  172. {$IFDEF DYNAMIC_LINK}
  173. var
  174.   _DsRoleFreeMemory: Pointer;
  175. procedure DsRoleFreeMemory;
  176. begin
  177.   GetProcedureAddress(_DsRoleFreeMemory, netapi32, 'DsRoleFreeMemory');
  178.   asm
  179.     mov esp, ebp
  180.     pop ebp
  181.     jmp [_DsRoleFreeMemory]
  182.   end;
  183. end;
  184. {$ELSE}
  185. procedure DsRoleFreeMemory; external netapi32 name 'DsRoleFreeMemory';
  186. {$ENDIF DYNAMIC_LINK}
  187. end.