jwagpedit.pas 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  1. {******************************************************************************}
  2. { }
  3. { Group Policy 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: gpedit.h, released June 2000. The original Pascal }
  9. { code is: GPEdit.pas, released December 2000. 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. unit JwaGPEdit;
  43. {$WEAKPACKAGEUNIT}
  44. {$HPPEMIT ''}
  45. {$HPPEMIT '#include "GPEdit.h"'}
  46. {$HPPEMIT ''}
  47. {$I jediapilib.inc}
  48. interface
  49. uses
  50. ActiveX {TODO}, JwaPrSht, JwaWinType;
  51. type
  52. LPOLESTR = POleStr;
  53. {$NODEFINE LPOLESTR}
  54. //-----------------------------------------------------------------------------
  55. //
  56. // GPEDIT.H - Definitions and prototypes for Group Policy
  57. //
  58. // Copyright 1997-1999, Microsoft Corporation
  59. //
  60. //-----------------------------------------------------------------------------
  61. //
  62. // Terminology
  63. //
  64. // Group Policy Editor - The tool to view a Group Policy Object.
  65. //
  66. // Group Policy Object - A collection of administrator defined policies.
  67. // Each Group Policy Object (GPO) has both file system
  68. // and Active Directory storage available to it.
  69. //
  70. // IGPEInformation - The interface MMC Snapin Extensions use to
  71. // talk to the Group Policy Editor.
  72. //
  73. // IGroupPolicyObject - The interface used to create/edit a GPO directly
  74. // without going through the Group Policy Editor
  75. //
  76. //
  77. // Group Policy Editor MMC SnapIn GUID
  78. //
  79. // {8FC0B734-A0E1-11d1-A7D3-0000F87571E3}
  80. const
  81. CLSID_GPESnapIn: TGUID = (
  82. D1:$8fc0b734; D2:$a0e1; D3:$11d1; D4:($a7, $d3, $0, $0, $f8, $75, $71, $e3));
  83. {$EXTERNALSYM CLSID_GPESnapIn}
  84. //
  85. // Group Policy Editor node ids
  86. //
  87. //
  88. // Computer Configuration\Windows Settings
  89. // {8FC0B737-A0E1-11d1-A7D3-0000F87571E3}
  90. //
  91. NODEID_Machine: TGUID = (
  92. D1:$8fc0b737; D2:$a0e1; D3:$11d1; D4:($a7, $d3, $0, $0, $f8, $75, $71, $e3));
  93. {$EXTERNALSYM NODEID_Machine}
  94. //
  95. // Computer Configuration\Software Settings
  96. // {8FC0B73A-A0E1-11d1-A7D3-0000F87571E3}
  97. //
  98. NODEID_MachineSWSettings: TGUID = (
  99. D1:$8fc0b73a; D2:$a0e1; D3:$11d1; D4:($a7, $d3, $0, $0, $f8, $75, $71, $e3));
  100. {$EXTERNALSYM NODEID_MachineSWSettings}
  101. //
  102. // User Configuration\Windows Settings
  103. // {8FC0B738-A0E1-11d1-A7D3-0000F87571E3}
  104. //
  105. NODEID_User: TGUID = (
  106. D1:$8fc0b738; D2:$a0e1; D3:$11d1; D4:($a7, $d3, $0, $0, $f8, $75, $71, $e3));
  107. {$EXTERNALSYM NODEID_User}
  108. //
  109. // User Configuration\Software Settings
  110. // {8FC0B73C-A0E1-11d1-A7D3-0000F87571E3}
  111. //
  112. NODEID_UserSWSettings: TGUID = (
  113. D1:$8fc0b73c; D2:$a0e1; D3:$11d1; D4:($a7, $d3, $0, $0, $f8, $75, $71, $e3));
  114. {$EXTERNALSYM NODEID_UserSWSettings}
  115. //
  116. // IGPEInformation interface id
  117. //
  118. // {8FC0B735-A0E1-11d1-A7D3-0000F87571E3}
  119. IID_IGPEInformation: TGUID = (
  120. D1:$8fc0b735; D2:$a0e1; D3:$11d1; D4:($a7, $d3, $0, $0, $f8, $75, $71, $e3));
  121. {$EXTERNALSYM IID_IGPEInformation}
  122. //
  123. // Group Policy Object class id
  124. //
  125. // {EA502722-A23D-11d1-A7D3-0000F87571E3}
  126. CLSID_GroupPolicyObject: TGUID = (
  127. D1:$ea502722; D2:$a23d; D3:$11d1; D4:($a7, $d3, $0, $0, $f8, $75, $71, $e3));
  128. {$EXTERNALSYM CLSID_GroupPolicyObject}
  129. //
  130. // Group Policy Object interface id
  131. //
  132. // {EA502723-A23D-11d1-A7D3-0000F87571E3}
  133. IID_IGroupPolicyObject: TGUID = (
  134. D1:$ea502723; D2:$a23d; D3:$11d1; D4:($a7, $d3, $0, $0, $f8, $75, $71, $e3));
  135. {$EXTERNALSYM IID_IGroupPolicyObject}
  136. //
  137. // GUID that identifies the registry extension
  138. //
  139. REGISTRY_EXTENSION_GUID: TGUID = (
  140. D1:$35378EAC; D2:$683F; D3:$11D2; D4:($A8, $9A, $00, $C0, $4F, $BB, $CF, $A2));
  141. {$EXTERNALSYM IID_IGroupPolicyObject}
  142. //========================================================================================
  143. //
  144. // Resultant Set of Policy node ids
  145. //
  146. //========================================================================================
  147. //
  148. // Resultant Set of Policy MMC SnapIn GUID
  149. //
  150. // {6DC3804B-7212-458D-ADB0-9A07E2AE1FA2}
  151. CLSID_RSOPSnapIn: TGUID = (
  152. D1:$6dc3804b; D2:$7212; D3:$458d; D4:($ad, $b0, $9a, $07, $e2, $ae, $1f, $a2));
  153. {$EXTERNALSYM CLSID_RSOPSnapIn}
  154. //
  155. // Computer Configuration\Windows Settings
  156. // {BD4C1A2E-0B7A-4A62-A6B0-C0577539C97E}
  157. //
  158. NODEID_RSOPMachine: TGUID = (
  159. D1:$bd4c1a2e; D2:$0b7a; D3:$4a62; D4:($a6, $b0, $c0, $57, $75, $39, $c9, $7e));
  160. {$EXTERNALSYM NODEID_RSOPMachine}
  161. //
  162. // Computer Configuration\Software Settings
  163. // {6A76273E-EB8E-45DB-94C5-25663A5f2C1A}
  164. //
  165. NODEID_RSOPMachineSWSettings: TGUID = (
  166. D1:$6a76273e; D2:$eb8e; D3:$45db; D4:($94, $c5, $25, $66, $3a, $5f, $2c, $1a));
  167. {$EXTERNALSYM NODEID_RSOPMachineSWSettings}
  168. //
  169. // User Configuration\Windows Settings
  170. // {AB87364F-0CEC-4CD8-9BF8-898F34628FB8}
  171. //
  172. NODEID_RSOPUser: TGUID = (
  173. D1:$ab87364f; D2:$0cec; D3:$4cd8; D4:($9b, $f8, $89, $8f, $34, $62, $8f, $b8));
  174. {$EXTERNALSYM NODEID_RSOPUser}
  175. //
  176. // User Configuration\Software Settings
  177. // {E52C5CE3-FD27-4402-84DE-D9A5F2858910}
  178. //
  179. NODEID_RSOPUserSWSettings: TGUID = (
  180. D1:$e52c5ce3; D2:$fd27; D3:$4402; D4:($84, $de, $d9, $a5, $f2, $85, $89, $10));
  181. {$EXTERNALSYM NODEID_RSOPUserSWSettings}
  182. //
  183. // IRSOPInformation interface id
  184. //
  185. // {9A5A81B5-D9C7-49EF-9D11-DDF50968C48D}
  186. IID_IRSOPInformation: TGUID = (
  187. D1:$9a5a81b5; D2:$d9c7; D3:$49ef; D4:($9d, $11, $dd, $f5, $09, $68, $c4, $8d));
  188. {$EXTERNALSYM IID_IRSOPInformation}
  189. // #include <objbase.h>
  190. //
  191. // Group Policy Object Section flags
  192. //
  193. const
  194. GPO_SECTION_ROOT = 0; // Root
  195. {$EXTERNALSYM GPO_SECTION_ROOT}
  196. GPO_SECTION_USER = 1; // User
  197. {$EXTERNALSYM GPO_SECTION_USER}
  198. GPO_SECTION_MACHINE = 2; // Machine
  199. {$EXTERNALSYM GPO_SECTION_MACHINE}
  200. //
  201. // Group Policy Object types
  202. //
  203. type
  204. _GROUP_POLICY_OBJECT_TYPE = (
  205. GPOTypeLocal, // GPO on the local machine
  206. GPOTypeRemote, // GPO on a remote machine
  207. GPOTypeDS); // GPO in the Active Directory
  208. {$EXTERNALSYM _GROUP_POLICY_OBJECT_TYPE}
  209. GROUP_POLICY_OBJECT_TYPE = _GROUP_POLICY_OBJECT_TYPE;
  210. {$EXTERNALSYM GROUP_POLICY_OBJECT_TYPE}
  211. PGROUP_POLICY_OBJECT_TYPE = ^GROUP_POLICY_OBJECT_TYPE;
  212. {$EXTERNALSYM PGROUP_POLICY_OBJECT_TYPE}
  213. TGroupPolicyObjectType = GROUP_POLICY_OBJECT_TYPE;
  214. PGroupPolicyObjectType = PGROUP_POLICY_OBJECT_TYPE;
  215. //
  216. // Group Policy Hint types
  217. //
  218. _GROUP_POLICY_HINT_TYPE = (
  219. GPHintUnknown, // No link information available
  220. GPHintMachine, // GPO linked to a machine (local or remote)
  221. GPHintSite, // GPO linked to a site
  222. GPHintDomain, // GPO linked to a domain
  223. GPHintOrganizationalUnit); // GPO linked to a organizational unit
  224. {$EXTERNALSYM _GROUP_POLICY_HINT_TYPE}
  225. GROUP_POLICY_HINT_TYPE = _GROUP_POLICY_HINT_TYPE;
  226. {$EXTERNALSYM GROUP_POLICY_HINT_TYPE}
  227. PGROUP_POLICY_HINT_TYPE = ^GROUP_POLICY_HINT_TYPE;
  228. {$EXTERNALSYM PGROUP_POLICY_HINT_TYPE}
  229. TGroupPolicyHintType = GROUP_POLICY_HINT_TYPE;
  230. PGroupPolicyHintType = PGROUP_POLICY_HINT_TYPE;
  231. IGPEInformation = interface (IUnknown)
  232. ['{8FC0B735-A0E1-11d1-A7D3-0000F87571E3}']
  233. // *** IGPEInformation methods ***
  234. //
  235. // Returns the unique Group Policy Object name (a GUID)
  236. //
  237. // pszName contains the name on return
  238. // cchMaxLength is the max number of characters that can be stored in pszName
  239. //
  240. function GetName(pszName: LPOLESTR; cchMaxLength: Integer): HRESULT; stdcall;
  241. //
  242. // Returns the friendly display name for this Group Policy Object
  243. //
  244. // pszName contains the name on return
  245. // cchMaxLength is the max number of characters that can be stored in pszName
  246. //
  247. function GetDisplayName(pszName: LPOLESTR; cchMaxLength: Integer): HRESULT; stdcall;
  248. //
  249. // Returns a registry key handle for the requested section. The returned
  250. // key is the root of the registry, not the Policies subkey. To set / read
  251. // a value in the Policies subkey, you will need to call RegOpenKeyEx to
  252. // open Software\Policies subkey first.
  253. //
  254. // The handle has been opened with ALL ACCESS rights. Call RegCloseKey
  255. // on the handle when finished.
  256. //
  257. // dwSection is either GPO_SECTION_USER or GPO_SECTION_MACHINE
  258. // hKey contains the registry key on return
  259. //
  260. function GetRegistryKey(dwSection: DWORD; var hKey: HKEY): HRESULT; stdcall;
  261. //
  262. // Returns the Active Directory path to the root of the request section.
  263. // The path is in ADSI name format.
  264. //
  265. // dwSection is one of the GPO_SECTION_* flags
  266. // pszPath contains the path on return
  267. // cchMaxPath is the max number of characters that can be stored in pszPath
  268. //
  269. function GetDSPath(dwSection: DWORD; pszPath: LPOLESTR; cchMaxPath: Integer): HRESULT; stdcall;
  270. //
  271. // Returns the UNC path to the root of the requested section.
  272. //
  273. // dwSection is one of the GPO_SECTION_* flags
  274. // pszPath contains the path on return
  275. // cchMaxPath is the number of characters that can be stored in pszPath.
  276. //
  277. function GetFileSysPath(dwSection: DWORD; pszPath: LPOLESTR; cchMaxPath: Integer): HRESULT; stdcall;
  278. //
  279. // Returns the user preferences (options)
  280. //
  281. // Currently, there are no options defined. This is reserved for future use.
  282. //
  283. // dwOptions receives a bitmask value
  284. //
  285. function GetOptions(var dwOptions: DWORD): HRESULT; stdcall;
  286. //
  287. // Returns the type of GPO being edited.
  288. //
  289. // The three types are: a GPO in the Active Directory, the GPO on the local machine,
  290. // and the GPO on a remote machine.
  291. //
  292. // Machine GPOs only have file system storage (no Active Directory storage available).
  293. // If GetDSPath is called for a machine GPO, the function will succeed
  294. // and the returned buffer will be the empty string ""
  295. //
  296. // Active Directory GPOs have both file system and Active Directory storage available to them.
  297. //
  298. // gpoType receives one of the type flags listed above.
  299. //
  300. function GetType(var gpoType: GROUP_POLICY_OBJECT_TYPE): HRESULT; stdcall;
  301. //
  302. // Returns the type of Active Directory object (or machine) that could be linked to
  303. // this GPO
  304. //
  305. // This is a hint api only. The GPE does not know which Active Directory objects are
  306. // linked to a particular GPO, but it can offer a hint based upon how the
  307. // user started the GPE.
  308. //
  309. // Use this method with great caution. Some extensions might want to
  310. // customize their user interface based upon the scoping for this GPO,
  311. // but it is easy to offer the wrong namespace. Best advice is to
  312. // always offer your full user interface, but if you choose to use this
  313. // method, always offer your full user interface if you recieve the
  314. // unknown hint back.
  315. //
  316. // gpHint receives one of the hint flags listed above.
  317. //
  318. function GetHint(var gpHint: GROUP_POLICY_HINT_TYPE): HRESULT; stdcall;
  319. //
  320. // Informs the Group Policy Editor that policy settings have changed.
  321. // Extensions MUST call this methold every time a change is made
  322. // to a Group Policy Object.
  323. //
  324. // bMachine specifies if machine or user policy has changed.
  325. // bAdd specifies whether this is an add or delete.
  326. // pGuidExtension is the guid or unique name of extension that
  327. // will process this GPO.
  328. // pGuidSnapin is the guid or unique name of snapin that is making
  329. // this call
  330. //
  331. function PolicyChanged(bMachine, bAdd: BOOL; const pGuidExtension, pGuidSnapin: GUID): HRESULT; stdcall;
  332. end;
  333. {$EXTERNALSYM IGPEInformation}
  334. LPGPEINFORMATION = ^IGPEInformation;
  335. {$EXTERNALSYM LPGPEINFORMATION}
  336. //
  337. // Group Policy Object open / creation flags
  338. //
  339. const
  340. GPO_OPEN_LOAD_REGISTRY = $00000001; // Load the registry files
  341. {$EXTERNALSYM GPO_OPEN_LOAD_REGISTRY}
  342. GPO_OPEN_READ_ONLY = $00000002; // Open the GPO as read only
  343. {$EXTERNALSYM GPO_OPEN_READ_ONLY}
  344. //
  345. // Group Policy Object option flags
  346. //
  347. const
  348. GPO_OPTION_DISABLE_USER = $00000001; // The user portion of this GPO is disabled
  349. {$EXTERNALSYM GPO_OPTION_DISABLE_USER}
  350. GPO_OPTION_DISABLE_MACHINE = $00000002; // The machine portion of this GPO is disabled
  351. {$EXTERNALSYM GPO_OPTION_DISABLE_MACHINE}
  352. type
  353. IGroupPolicyObject = interface (IUnknown)
  354. ['{EA502723-A23D-11d1-A7D3-0000F87571E3}']
  355. // *** IGroupPolicyObject methods ***
  356. //
  357. // Creates a new GPO in the Active Directory with the given friendly name
  358. // and opens it via OpenDSGPO(). If pszDomainName contains a domain
  359. // controller name, the GPO will be created on that DC. If it does not
  360. // specify a domain controller name, the method will select a DC on
  361. // the callers behalf.
  362. //
  363. // pszDomainName contains the ADSI path of the domain root
  364. // pszDisplayName contains the friendly display name
  365. // dwFlags is a bitmask of GPO open / creation flags listed above
  366. //
  367. function New(pszDomainName, pszDisplayName: LPOLESTR; dwFlags: DWORD): HRESULT; stdcall;
  368. //
  369. // Opens the specified Group Policy Object in the Active Directory
  370. // based upon the passed in flags. If pszPath contains a domain
  371. // controller name, the GPO will be opened on that DC. If it does
  372. // not contain a domain controller name, the method will select a
  373. // DC on the callers behalf. If the registry is not loaded,
  374. // GetRegistryKey() will return E_FAIL.
  375. //
  376. // pszPath contains the ADSI path to the GPO to open
  377. // dwFlags is a bitmask of GPO open / creation flags listed above
  378. //
  379. function OpenDSGPO(pszPath: LPOLESTR; dwFlags: DWORD): HRESULT; stdcall;
  380. //
  381. // Opens the default Group Policy Object on this machine with the
  382. // dwFlags options listed above. If the registry is not loaded,
  383. // GetRegistryKey() will return E_FAIL.
  384. //
  385. // dwFlags is a bitmask of GPO open / creation flags listed above
  386. //
  387. function OpenLocalMachineGPO(dwFlags: DWORD): HRESULT; stdcall;
  388. //
  389. // Opens the default Group Policy Object on a remote machine with the
  390. // dwFlags options listed above. If the registry is not loaded,
  391. // GetRegistryKey() will return E_FAIL.
  392. //
  393. // pszComputerName contains the machine name in \\machine format
  394. // dwFlags is a bitmask of GPO open / creation flags listed above
  395. //
  396. function OpenRemoteMachineGPO(pszComputerName: LPOLESTR; dwFlags: DWORD): HRESULT; stdcall;
  397. //
  398. // Flushes the registry settings to disk and updates the revision
  399. // number of the GPO.
  400. //
  401. // bMachine specifies if machine or user should be saved.
  402. // bAdd specifies whether this is an add or delete.
  403. // pGuidExtension is the guid or unique name of extension that
  404. // will process this GPO.
  405. // pGuid is a guid
  406. //
  407. function Save(bMachine, bAdd: BOOL; const pGuidExtension, pGuid: GUID): HRESULT; stdcall;
  408. //
  409. // Deletes this Group Policy Object.
  410. //
  411. // After calling this method, no other methods are valid to call
  412. // since the data will have been deleted.
  413. //
  414. function Delete: HRESULT; stdcall;
  415. //
  416. // Returns the unique Group Policy Object name
  417. //
  418. // For Active Directory policy objects, this is a GUID
  419. // For the local policy object, it is the string "Local"
  420. // For remote policy objects, it is the computername
  421. //
  422. // pszName contains the name on return
  423. // cchMaxLength is the max number of characters that can be stored in pszName
  424. //
  425. function GetName(pszName: LPOLESTR; cchMaxLength: Integer): HRESULT; stdcall;
  426. //
  427. // Returns the friendly display name for this Group Policy Object
  428. //
  429. // pszName contains the name on return
  430. // cchMaxLength is the max number of characters that can be stored in pszName
  431. //
  432. function GetDisplayName(pszName: LPOLESTR; cchMaxLength: Integer): HRESULT; stdcall;
  433. //
  434. // Sets the friendly display name for this Group Policy Object
  435. //
  436. // pszName is the new display name
  437. //
  438. function SetDisplayName(pszName: LPOLESTR): HRESULT; stdcall;
  439. //
  440. // Returns the path to the Group Policy Object
  441. //
  442. //
  443. // If the GPO is an Active Directory object, the path is in ADSI name format.
  444. // If the GPO is a machine object, it is a file system path
  445. //
  446. // pszPath contains the path on return
  447. // cchMaxPath is the max number of characters that can be stored in pszPath
  448. //
  449. function GetPath(pszPath: LPOLESTR; cchMaxPath: Integer): HRESULT; stdcall;
  450. //
  451. // Returns the Active Directory path to the root of the request section.
  452. // The path is in DN name format.
  453. //
  454. // dwSection is one of the GPO_SECTION_* flags
  455. // pszPath contains the path on return
  456. // cchMaxPath is the max number of characters that can be stored in pszPath
  457. //
  458. function GetDSPath(dwSection: DWORD; pszPath: LPOLESTR; cchMaxPath: Integer): HRESULT; stdcall;
  459. //
  460. // Returns the UNC path to the root of the requested section.
  461. //
  462. // dwSection is one of the GPO_SECTION_* flags
  463. // pszPath contains the path on return
  464. // cchMaxPath is the number of characters that can be stored in pszPath.
  465. //
  466. function GetFileSysPath(dwSection: DWORD; pszPath: LPOLESTR; cchMaxPath: Integer): HRESULT; stdcall;
  467. //
  468. // Returns a registry key handle for the requested section. The returned
  469. // key is the root of the registry, not the Policies subkey. To set / read
  470. // a value in the Policies subkey, you will need to call RegOpenKeyEx to
  471. // open Software\Policies subkey first.
  472. //
  473. // The handle has been opened with ALL ACCESS rights. Call RegCloseKey
  474. // on the handle when finished.
  475. //
  476. // If the GPO was loaded / created without the registry being loaded
  477. // this method will return E_FAIL.
  478. //
  479. // dwSection is either GPO_SECTION_USER or GPO_SECTION_MACHINE
  480. // hKey contains the registry key on return
  481. //
  482. function GetRegistryKey(dwSection: DWORD; var hKey: HKEY): HRESULT; stdcall;
  483. //
  484. // Returns any options for this Group Policy Object
  485. //
  486. // dwOptions receives the GPO_OPTION_* flags
  487. //
  488. function GetOptions(var dwOptions: DWORD): HRESULT; stdcall;
  489. //
  490. // Sets any options for this Group Policy Object
  491. //
  492. // This method sets any options for this GPO. To change
  493. // an option, that flag must be set in the mask field.
  494. // If the flag is in the mask field, then the dwOptions
  495. // field is read for the current state.
  496. //
  497. // For example: to disable the GPO, make this call
  498. //
  499. // SetOptions (GPO_OPTION_DISABLED, GPO_OPTION_DISABLED);
  500. //
  501. // dwOptions specifies one or more GPO_OPTION_* flags
  502. // dwMask specificies which of the dwOptions to change
  503. //
  504. function SetOptions(dwOptions, dwMask: DWORD): HRESULT; stdcall;
  505. //
  506. // Returns the type of GPO being edited.
  507. //
  508. // The three types are: a GPO in the Active Directory, the GPO on the local machine,
  509. // and the GPO on a remote machine.
  510. //
  511. // Machine GPOs only have file system storage (no Active Directory storage available).
  512. // If GetDSPath is called for a machine GPO, the function will succeed
  513. // and the returned buffer will be the empty string ""
  514. //
  515. // Active Directory GPOs have both file system and Active Directory storage available to them.
  516. //
  517. // gpoType receives one of the type flags
  518. //
  519. function GetType(var gpoType: GROUP_POLICY_OBJECT_TYPE): HRESULT; stdcall;
  520. //
  521. // Returns the machine name of the remote GPO
  522. //
  523. // This method returns the name passed to OpenRemoteMachineGPO.
  524. //
  525. // pszName contains the name on return
  526. // cchMaxLength is the max number of characters that can be stored in pszName
  527. //
  528. function GetMachineName(pszName: LPOLESTR; cchMaxLength: Integer): HRESULT; stdcall;
  529. //
  530. // Returns an array of property sheet pages and the number of pages
  531. // in the array
  532. //
  533. // Note, this method will allocate memory for the array with
  534. // LocalAlloc. When finished, the caller should free the array
  535. // with LocalFree
  536. //
  537. // hPages address of the pointer for the array of property sheet pages
  538. // uPageCount receives the number of pages in the array
  539. //
  540. function GetPropertySheetPages(var hPages: PHPROPSHEETPAGE; var uPageCount: UINT): HRESULT; stdcall;
  541. end;
  542. {$EXTERNALSYM IGroupPolicyObject}
  543. LPGROUPPOLICYOBJECT = ^IGroupPolicyObject;
  544. {$EXTERNALSYM LPGROUPPOLICYOBJECT}
  545. //
  546. // RSOP flags
  547. //
  548. const
  549. RSOP_INFO_FLAG_DIAGNOSTIC_MODE = $00000001; // Running in diagnostic mode vs planning mode
  550. {$EXTERNALSYM RSOP_INFO_FLAG_DIAGNOSTIC_MODE}
  551. type
  552. IRSOPInformation = interface (IUnknown)
  553. ['{9A5A81B5-D9C7-49EF-9D11-DDF50968C48D}']
  554. // *** IRSOPInformation methods ***
  555. //
  556. // Returns the namespace for the RSOP data
  557. //
  558. // dwSection is either GPO_SECTION_USER or GPO_SECTION_MACHINE
  559. // pszName contains the namespace on return
  560. // cchMaxLength is the max number of characters that can be stored in pszName
  561. //
  562. function GetNamespace(dwSection: DWORD; pszName: LPOLESTR; cchMaxLength: Integer): HRESULT; stdcall;
  563. //
  564. // Returns information about the RSOP session
  565. //
  566. // pdwFlags points to a DWORD which contains the flags on return
  567. //
  568. function GetFlags(var pdwFlags: DWORD): HRESULT; stdcall;
  569. //
  570. // Returns the event log text for a specific entry
  571. //
  572. // lpEventSource - event log source name
  573. // lpEventLogName - event log name
  574. // lpEventTime - event log time in WMI datetime format
  575. // dwEventID - event ID
  576. // lpText - Receives a pointer to a buffer containing the text.
  577. // The caller should free this buffer with CoTaskMemFree.
  578. //
  579. function GetEventLogEntryText(pszEventSource, pszEventLogName, pszEventTime: LPOLESTR;
  580. dwEventID: DWORD; out ppszText: LPOLESTR): HRESULT; stdcall;
  581. end;
  582. {$EXTERNALSYM IRSOPInformation}
  583. LPRSOPINFORMATION = IRSOPInformation;
  584. {$EXTERNALSYM LPRSOPINFORMATION}
  585. //=============================================================================
  586. //
  587. // CreateGPOLink
  588. //
  589. // Creates a link to a GPO for the specified Site, Domain, or Organizational Unit
  590. //
  591. // lpGPO - ADSI path to the GPO
  592. // lpContainer - ADSI path to the Site, Domain, or Organizational Unit
  593. // fHighPriority - Create the link as the highest or lowest priority
  594. //
  595. // Returns: S_OK if successful
  596. //
  597. //=============================================================================
  598. function CreateGPOLink(lpGPO, lpContainer: LPOLESTR; fHighPriority: BOOL): HRESULT; stdcall;
  599. {$EXTERNALSYM CreateGPOLink}
  600. //=============================================================================
  601. //
  602. // DeleteGPOLink
  603. //
  604. // Deletes a link to a GPO for the specified Site, Domain, or Organizational Unit
  605. //
  606. // lpGPO - ADSI path to the GPO
  607. // lpContainer - ADSI path to the Site, Domain, or Organizational Unit
  608. //
  609. // Returns: S_OK if successful
  610. //
  611. //=============================================================================
  612. function DeleteGPOLink(lpGPO, lpContainer: LPOLESTR): HRESULT; stdcall;
  613. {$EXTERNALSYM DeleteGPOLink}
  614. //=============================================================================
  615. //
  616. // DeleteAllGPOLinks
  617. //
  618. // Deletes all GPO links for the specified Site, Domain, or Organizational Unit
  619. //
  620. // lpContainer - ADSI path to the Site, Domain, or Organizational Unit
  621. //
  622. // Returns: S_OK if successful
  623. //
  624. //=============================================================================
  625. function DeleteAllGPOLinks(lpContainer: LPOLESTR): HRESULT; stdcall;
  626. {$EXTERNALSYM DeleteAllGPOLinks}
  627. //=============================================================================
  628. //
  629. // BrowseForGPO
  630. //
  631. // Displays the GPO browser dialog
  632. //
  633. // lpBrowseInfo - Address of a GPOBROWSEINFO structure
  634. //
  635. // Returns: S_OK if successful
  636. //
  637. //=============================================================================
  638. //
  639. // Flags passed in the dwFlags field of the GPOBROWSEINFO structure
  640. //
  641. const
  642. GPO_BROWSE_DISABLENEW = $00000001; // Disables the New GPO functionality on all pages except "All"
  643. {$EXTERNALSYM GPO_BROWSE_DISABLENEW}
  644. GPO_BROWSE_NOCOMPUTERS = $00000002; // Removes the Computers tab
  645. {$EXTERNALSYM GPO_BROWSE_NOCOMPUTERS}
  646. GPO_BROWSE_NODSGPOS = $00000004; // Removes the Domain/OU and Sites tabs
  647. {$EXTERNALSYM GPO_BROWSE_NODSGPOS}
  648. GPO_BROWSE_OPENBUTTON = $00000008; // Change the Ok button to say Open
  649. {$EXTERNALSYM GPO_BROWSE_OPENBUTTON}
  650. GPO_BROWSE_INITTOALL = $00000010; // Initialize the dialog focused on the All pane
  651. {$EXTERNALSYM GPO_BROWSE_INITTOALL}
  652. type
  653. tag_GPOBROWSEINFO = record
  654. dwSize: DWORD; // [in] Initialized to the size of this structure
  655. dwFlags: DWORD; // [in] Flags defined above
  656. hwndOwner: HWND; // [in] Parent window handle (can be NULL)
  657. lpTitle: LPOLESTR; // [in] Title bar text. If NULL, "Browse for a Group Policy Object" will be the default text
  658. lpInitialOU: LPOLESTR; // [in] Initial Domain/Organizational Unit to open focus on
  659. lpDSPath: LPOLESTR; // [in/out] Pointer to the buffer that receives the Active Directory GPO path
  660. dwDSPathSize: DWORD; // [in] Size in characters of buffer given in lpDSPath
  661. lpName: LPOLESTR; // [in/out] Pointer to a buffer that receives either the computer name or
  662. // the friendly name of the GPO (can be NULL)
  663. dwNameSize: DWORD; // [in] Size in characters of buffer given in lpName
  664. gpoType: GROUP_POLICY_OBJECT_TYPE; // [out] Specifies the type of GPO
  665. gpoHint: GROUP_POLICY_HINT_TYPE; // [out] Specifies a hint of the GPO association
  666. end;
  667. {$EXTERNALSYM tag_GPOBROWSEINFO}
  668. GPOBROWSEINFO = tag_GPOBROWSEINFO;
  669. {$EXTERNALSYM GPOBROWSEINFO}
  670. LPGPOBROWSEINFO = ^GPOBROWSEINFO;
  671. TGpoBrowseInfo = GPOBROWSEINFO;
  672. PGpoBrowseInfo = LPGPOBROWSEINFO;
  673. function BrowseForGPO(var lpBrowseInfo: GPOBROWSEINFO): HRESULT; stdcall;
  674. {$EXTERNALSYM BrowseForGPO}
  675. //=============================================================================
  676. //
  677. // ImportRSoPData
  678. //
  679. // Imports a data file generated by ExportRSoPData
  680. //
  681. // lpNameSpace - Namespace to place the data in
  682. // lpFileName - Filename containing the data
  683. //
  684. // Returns: S_OK if successful
  685. //
  686. // Notes: The namespace specified in lpNameSpace must exist prior to calling
  687. // this function.
  688. //
  689. //=============================================================================
  690. function ImportRSoPData(lpNameSpace, lpFileName: LPOLESTR): HRESULT; stdcall;
  691. {$EXTERNALSYM ImportRSoPData}
  692. //=============================================================================
  693. //
  694. // ExportRSoPData
  695. //
  696. // Exports a WBEM namespace containing RSoP information to a data file.
  697. // This data file can be imported to a WBEM namespace using ImportRSoPData.
  698. //
  699. // lpNameSpace - Namespace to read the data from
  700. // lpFileName - Filename to receive the data
  701. //
  702. // Returns: S_OK if successful
  703. //
  704. // Notes: This function should be called twice. Once for the user data
  705. // and once for the computer data.
  706. //
  707. //=============================================================================
  708. function ExportRSoPData(lpNameSpace, lpFileName: LPOLESTR): HRESULT; stdcall;
  709. {$EXTERNALSYM ExportRSoPData}
  710. implementation
  711. const
  712. gpeditlib = 'gpedit.dll';
  713. {$IFDEF DYNAMIC_LINK}
  714. var
  715. _CreateGPOLink: Pointer;
  716. function CreateGPOLink;
  717. begin
  718. GetProcedureAddress(_CreateGPOLink, gpeditlib, 'CreateGPOLink');
  719. asm
  720. MOV ESP, EBP
  721. POP EBP
  722. JMP [_CreateGPOLink]
  723. end;
  724. end;
  725. var
  726. _DeleteGPOLink: Pointer;
  727. function DeleteGPOLink;
  728. begin
  729. GetProcedureAddress(_DeleteGPOLink, gpeditlib, 'DeleteGPOLink');
  730. asm
  731. MOV ESP, EBP
  732. POP EBP
  733. JMP [_DeleteGPOLink]
  734. end;
  735. end;
  736. var
  737. _DeleteAllGPOLinks: Pointer;
  738. function DeleteAllGPOLinks;
  739. begin
  740. GetProcedureAddress(_DeleteAllGPOLinks, gpeditlib, 'DeleteAllGPOLinks');
  741. asm
  742. MOV ESP, EBP
  743. POP EBP
  744. JMP [_DeleteAllGPOLinks]
  745. end;
  746. end;
  747. var
  748. _BrowseForGPO: Pointer;
  749. function BrowseForGPO;
  750. begin
  751. GetProcedureAddress(_BrowseForGPO, gpeditlib, 'BrowseForGPO');
  752. asm
  753. MOV ESP, EBP
  754. POP EBP
  755. JMP [_BrowseForGPO]
  756. end;
  757. end;
  758. var
  759. _ImportRSoPData: Pointer;
  760. function ImportRSoPData;
  761. begin
  762. GetProcedureAddress(_ImportRSoPData, gpeditlib, 'ImportRSoPData');
  763. asm
  764. MOV ESP, EBP
  765. POP EBP
  766. JMP [_ImportRSoPData]
  767. end;
  768. end;
  769. var
  770. _ExportRSoPData: Pointer;
  771. function ExportRSoPData;
  772. begin
  773. GetProcedureAddress(_ExportRSoPData, gpeditlib, 'ExportRSoPData');
  774. asm
  775. MOV ESP, EBP
  776. POP EBP
  777. JMP [_ExportRSoPData]
  778. end;
  779. end;
  780. {$ELSE}
  781. function CreateGPOLink; external gpeditlib name 'CreateGPOLink';
  782. function DeleteGPOLink; external gpeditlib name 'DeleteGPOLink';
  783. function DeleteAllGPOLinks; external gpeditlib name 'DeleteAllGPOLinks';
  784. function BrowseForGPO; external gpeditlib name 'BrowseForGPO';
  785. function ImportRSoPData; external gpeditlib name 'ImportRSoPData';
  786. function ExportRSoPData; external gpeditlib name 'ExportRSoPData';
  787. {$ENDIF DYNAMIC_LINK}
  788. end.