jwauserenv.pas 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860
  1. {******************************************************************************}
  2. { }
  3. { User Profile 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: userenv.h, released June 2000. The original Pascal }
  9. { code is: UserEnv.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. // $Id: JwaUserEnv.pas,v 1.10 2005/09/06 16:36:50 marquardt Exp $
  43. unit JwaUserEnv;
  44. {$WEAKPACKAGEUNIT}
  45. {$I jediapilib.inc}
  46. interface
  47. uses
  48. JwaActiveX, JwaProfInfo, JwaWbemCli, JwaWindows;
  49. {$HPPEMIT ''}
  50. {$HPPEMIT '#include "userenv.h"'}
  51. {$HPPEMIT ''}
  52. {$HPPEMIT 'typedef PGROUP_POLICY_OBJECTA *PPGROUP_POLICY_OBJECTA'}
  53. {$HPPEMIT 'typedef PGROUP_POLICY_OBJECTW *PPGROUP_POLICY_OBJECTW'}
  54. {$HPPEMIT ''}
  55. {$HPPEMIT 'typedef #ifdef UNICODE'}
  56. {$HPPEMIT 'typedef PPGROUP_POLICY_OBJECTW PPGROUP_POLICY_OBJECT'}
  57. {$HPPEMIT 'typedef #else'}
  58. {$HPPEMIT 'typedef PPGROUP_POLICY_OBJECTA PPGROUP_POLICY_OBJECT'}
  59. {$HPPEMIT 'typedef #endif'}
  60. {$HPPEMIT ''}
  61. //=============================================================================
  62. //
  63. // LoadUserProfile
  64. //
  65. // Loads the specified user's profile.
  66. //
  67. // Most applications should not need to use this function. It's used
  68. // when a user has logged onto the system or a service starts in a named
  69. // user account.
  70. //
  71. // hToken - Token for the user, returned from LogonUser()
  72. // lpProfileInfo - Address of a PROFILEINFO structure
  73. //
  74. // Returns: TRUE if successful
  75. // FALSE if not. Call GetLastError() for more details
  76. //
  77. // Note: The caller of this function must have admin privileges on the machine.
  78. //
  79. // Upon successful return, the hProfile member of the PROFILEINFO
  80. // structure is a registry key handle opened to the root
  81. // of the user's hive. It has been opened with full access. If
  82. // you need to read or write to the user's registry file, use
  83. // this key instead of HKEY_CURRENT_USER. Do not close this
  84. // handle. Instead pass it to UnloadUserProfile to close
  85. // the handle.
  86. //
  87. //=============================================================================
  88. //
  89. // Flags that can be set in the dwFlags field
  90. //
  91. const
  92. PI_NOUI = $00000001; // Prevents displaying of messages
  93. {$EXTERNALSYM PI_NOUI}
  94. PI_APPLYPOLICY = $00000002; // Apply NT4 style policy
  95. {$EXTERNALSYM PI_APPLYPOLICY}
  96. function LoadUserProfileA(hToken: HANDLE; var lpProfileInfo: PROFILEINFOA): BOOL; stdcall;
  97. {$EXTERNALSYM LoadUserProfileA}
  98. function LoadUserProfileW(hToken: HANDLE; var lpProfileInfo: PROFILEINFOW): BOOL; stdcall;
  99. {$EXTERNALSYM LoadUserProfileW}
  100. function LoadUserProfile(hToken: HANDLE; var lpProfileInfo: PROFILEINFO): BOOL; stdcall;
  101. {$EXTERNALSYM LoadUserProfile}
  102. //=============================================================================
  103. //
  104. // UnloadUserProfile
  105. //
  106. // Unloads a user's profile that was loaded by LoadUserProfile()
  107. //
  108. // hToken - Token for the user, returned from LogonUser()
  109. // hProfile - hProfile member of the PROFILEINFO structure
  110. //
  111. // Returns: TRUE if successful
  112. // FALSE if not. Call GetLastError() for more details
  113. //
  114. // Note: The caller of this function must have admin privileges on the machine.
  115. //
  116. //=============================================================================
  117. function UnloadUserProfile(hToken: HANDLE; hProfile: HANDLE): BOOL; stdcall;
  118. {$EXTERNALSYM UnloadUserProfile}
  119. //=============================================================================
  120. //
  121. // GetProfilesDirectory
  122. //
  123. // Returns the path to the root of where all user profiles are stored.
  124. //
  125. // lpProfilesDir - Receives the path
  126. // lpcchSize - Size of lpProfilesDir
  127. //
  128. // Returns: TRUE if successful
  129. // FALSE if not. Call GetLastError() for more details
  130. //
  131. // Note: If lpProfilesDir is not large enough, the function will fail,
  132. // and lpcchSize will contain the necessary buffer size.
  133. //
  134. // Example return value: C:\Documents and Settings
  135. //
  136. //=============================================================================
  137. function GetProfilesDirectoryA(lpProfilesDir: LPSTR; var lpcchSize: DWORD): BOOL; stdcall;
  138. {$EXTERNALSYM GetProfilesDirectoryA}
  139. function GetProfilesDirectoryW(lpProfilesDir: LPWSTR; var lpcchSize: DWORD): BOOL; stdcall;
  140. {$EXTERNALSYM GetProfilesDirectoryW}
  141. function GetProfilesDirectory(lpProfilesDir: LPTSTR; var lpcchSize: DWORD): BOOL; stdcall;
  142. {$EXTERNALSYM GetProfilesDirectory}
  143. //=============================================================================
  144. //
  145. // GetProfileType()
  146. //
  147. // Returns the type of the profile that is loaded for a user.
  148. //
  149. // dwFlags - Returns the profile flags
  150. //
  151. // Return: TRUE if successful
  152. // FALSE if an error occurs. Call GetLastError for more details
  153. //
  154. // Comments: if profile is not already loaded the function will return an error.
  155. // The caller needs to have access to HKLM part of the registry.
  156. // (exists by default)
  157. //
  158. //=============================================================================
  159. //
  160. // Flags that can be set in the dwFlags field
  161. //
  162. const
  163. PT_TEMPORARY = $00000001; // A profile has been allocated that will be deleted at logoff.
  164. {$EXTERNALSYM PT_TEMPORARY}
  165. PT_ROAMING = $00000002; // The loaded profile is a roaming profile.
  166. {$EXTERNALSYM PT_ROAMING}
  167. PT_MANDATORY = $00000004; // The loaded profile is mandatory.
  168. {$EXTERNALSYM PT_MANDATORY}
  169. function GetProfileType(var dwFlags: DWORD): BOOL; stdcall;
  170. {$EXTERNALSYM GetProfileType}
  171. //=============================================================================
  172. //
  173. // DeleteProfile()
  174. //
  175. // Deletes the profile and all other user related settings from the machine
  176. //
  177. // lpSidString - String form of the user sid.
  178. // lpProfilePath - ProfilePath (if Null, lookup in the registry)
  179. // lpComputerName - Computer Name from which profile has to be deleted
  180. //
  181. // Return: TRUE if successful
  182. // FALSE if an error occurs. Call GetLastError for more details
  183. //
  184. // Comments: Deletes the profile directory, registry and appmgmt stuff
  185. //=============================================================================
  186. function DeleteProfileA(lpSidString: LPCSTR; lpProfilePath: LPCSTR;
  187. lpComputerName: LPCSTR): BOOL; stdcall;
  188. {$EXTERNALSYM DeleteProfileA}
  189. function DeleteProfileW(lpSidString: LPCWSTR; lpProfilePath: LPCWSTR;
  190. lpComputerName: LPCWSTR): BOOL; stdcall;
  191. {$EXTERNALSYM DeleteProfileW}
  192. function DeleteProfile(lpSidString: LPCTSTR; lpProfilePath: LPCTSTR;
  193. lpComputerName: LPCTSTR): BOOL; stdcall;
  194. {$EXTERNALSYM DeleteProfile}
  195. //=============================================================================
  196. //
  197. // GetDefaultUserProfilesDirectory
  198. //
  199. // Returns the path to the root of the default user profile
  200. //
  201. // lpProfileDir - Receives the path
  202. // lpcchSize - Size of lpProfileDir
  203. //
  204. // Returns: TRUE if successful
  205. // FALSE if not. Call GetLastError() for more details
  206. //
  207. // Note: If lpProfileDir is not large enough, the function will fail,
  208. // and lpcchSize will contain the necessary buffer size.
  209. //
  210. // Example return value: C:\Documents and Settings\Default User
  211. //
  212. //=============================================================================
  213. function GetDefaultUserProfileDirectoryA(lpProfileDir: LPSTR; var lpcchSize: DWORD): BOOL; stdcall;
  214. {$EXTERNALSYM GetDefaultUserProfileDirectoryA}
  215. function GetDefaultUserProfileDirectoryW(lpProfileDir: LPWSTR; var lpcchSize: DWORD): BOOL; stdcall;
  216. {$EXTERNALSYM GetDefaultUserProfileDirectoryW}
  217. function GetDefaultUserProfileDirectory(lpProfileDir: LPTSTR; var lpcchSize: DWORD): BOOL; stdcall;
  218. {$EXTERNALSYM GetDefaultUserProfileDirectory}
  219. //=============================================================================
  220. //
  221. // GetAllUsersProfilesDirectory
  222. //
  223. // Returns the path to the root of the All Users profile
  224. //
  225. // lpProfileDir - Receives the path
  226. // lpcchSize - Size of lpProfileDir
  227. //
  228. // Returns: TRUE if successful
  229. // FALSE if not. Call GetLastError() for more details
  230. //
  231. // Note: If lpProfileDir is not large enough, the function will fail,
  232. // and lpcchSize will contain the necessary buffer size.
  233. //
  234. // Example return value: C:\Documents and Settings\All Users
  235. //
  236. //=============================================================================
  237. function GetAllUsersProfileDirectoryA(lpProfileDir: LPSTR; var lpcchSize: DWORD): BOOL; stdcall;
  238. {$EXTERNALSYM GetAllUsersProfileDirectoryA}
  239. function GetAllUsersProfileDirectoryW(lpProfileDir: LPWSTR; var lpcchSize: DWORD): BOOL; stdcall;
  240. {$EXTERNALSYM GetAllUsersProfileDirectoryW}
  241. function GetAllUsersProfileDirectory(lpProfileDir: LPTSTR; var lpcchSize: DWORD): BOOL; stdcall;
  242. {$EXTERNALSYM GetAllUsersProfileDirectory}
  243. //=============================================================================
  244. //
  245. // GetUserProfileDirectory
  246. //
  247. // Returns the path to the root of the requested user's profile
  248. //
  249. // hToken - User's token returned from LogonUser()
  250. // lpProfileDir - Receives the path
  251. // lpcchSize - Size of lpProfileDir
  252. //
  253. // Returns: TRUE if successful
  254. // FALSE if not. Call GetLastError() for more details
  255. //
  256. // Note: If lpProfileDir is not large enough, the function will fail,
  257. // and lpcchSize will contain the necessary buffer size.
  258. //
  259. // Example return value: C:\Documents and Settings\Joe
  260. //
  261. //=============================================================================
  262. function GetUserProfileDirectoryA(hToken: HANDLE; lpProfileDir: LPSTR;
  263. var lpcchSize: DWORD): BOOL; stdcall;
  264. {$EXTERNALSYM GetUserProfileDirectoryA}
  265. function GetUserProfileDirectoryW(hToken: HANDLE; lpProfileDir: LPWSTR;
  266. var lpcchSize: DWORD): BOOL; stdcall;
  267. {$EXTERNALSYM GetUserProfileDirectoryW}
  268. function GetUserProfileDirectory(hToken: HANDLE; lpProfileDir: LPTSTR;
  269. var lpcchSize: DWORD): BOOL; stdcall;
  270. {$EXTERNALSYM GetUserProfileDirectory}
  271. //=============================================================================
  272. //
  273. // CreateEnvironmentBlock
  274. //
  275. // Returns the environment variables for the specified user. This block
  276. // can then be passed to CreateProcessAsUser().
  277. //
  278. // lpEnvironment - Receives a pointer to the new environment block
  279. // hToken - User's token returned from LogonUser() (optional, can be NULL)
  280. // bInherit - Inherit from the current process's environment block
  281. // or start from a clean state.
  282. //
  283. // Returns: TRUE if successful
  284. // FALSE if not. Call GetLastError() for more details
  285. //
  286. // Note: If hToken is NULL, the returned environment block will contain
  287. // system variables only.
  288. //
  289. // Call DestroyEnvironmentBlock to free the buffer when finished.
  290. //
  291. // If this block is passed to CreateProcessAsUser, the
  292. // CREATE_UNICODE_ENVIRONMENT flag must also be set.
  293. //
  294. //=============================================================================
  295. function CreateEnvironmentBlock(lpEnvironment: LPLPVOID; hToken: HANDLE;
  296. bInherit: BOOL): BOOL; stdcall;
  297. {$EXTERNALSYM CreateEnvironmentBlock}
  298. //=============================================================================
  299. //
  300. // DestroyEnvironmentBlock
  301. //
  302. // Frees environment variables created by CreateEnvironmentBlock
  303. //
  304. // lpEnvironment - A pointer to the environment block
  305. //
  306. // Returns: TRUE if successful
  307. // FALSE if not. Call GetLastError() for more details
  308. //
  309. //=============================================================================
  310. function DestroyEnvironmentBlock(lpEnvironment: LPVOID): BOOL; stdcall;
  311. {$EXTERNALSYM DestroyEnvironmentBlock}
  312. //=============================================================================
  313. //
  314. // ExpandEnvironmentStringsForUser
  315. //
  316. // Expands the source string using the environment block for the
  317. // specified user. If hToken is null, the system environment block
  318. // will be used (no user environment variables).
  319. //
  320. // hToken - User's token returned from LogonUser() (optional, can be NULL)
  321. // lpSrc - Pointer to the string with environment variables
  322. // lpDest - Buffer that receives the expanded string
  323. // dwSize - Size of lpDest in characters (max chars)
  324. //
  325. // Returns: TRUE if successful
  326. // FALSE if not. Call GetLastError() for more details
  327. //
  328. // Note: If the user profile for hToken is not loaded, this api will fail.
  329. //
  330. //=============================================================================
  331. function ExpandEnvironmentStringsForUserA(hToken: HANDLE; lpSrc: LPCSTR;
  332. lpDest: LPSTR; dwSize: DWORD): BOOL; stdcall;
  333. {$EXTERNALSYM ExpandEnvironmentStringsForUserA}
  334. function ExpandEnvironmentStringsForUserW(hToken: HANDLE; lpSrc: LPCWSTR;
  335. lpDest: LPWSTR; dwSize: DWORD): BOOL; stdcall;
  336. {$EXTERNALSYM ExpandEnvironmentStringsForUserW}
  337. function ExpandEnvironmentStringsForUser(hToken: HANDLE; lpSrc: LPCTSTR;
  338. lpDest: LPTSTR; dwSize: DWORD): BOOL; stdcall;
  339. {$EXTERNALSYM ExpandEnvironmentStringsForUser}
  340. //=============================================================================
  341. //
  342. // RefreshPolicy()
  343. //
  344. // Causes group policy to be applied immediately on the client machine
  345. //
  346. // bMachine - Refresh machine or user policy
  347. //
  348. // Returns: TRUE if successful
  349. // FALSE if not. Call GetLastError() for more details
  350. //
  351. //=============================================================================
  352. function RefreshPolicy(bMachine: BOOL): BOOL; stdcall;
  353. {$EXTERNALSYM RefreshPolicy}
  354. //=============================================================================
  355. //
  356. // RefreshPolicyEx()
  357. //
  358. // Causes group policy to be applied immediately on the client machine.
  359. //
  360. // bMachine - Refresh machine or user policy
  361. // dwOptions - Option specifying the kind of refresh that needs to be done.
  362. //
  363. // Returns: TRUE if successful
  364. // FALSE if not. Call GetLastError() for more details
  365. //
  366. //=============================================================================
  367. const
  368. RP_FORCE = 1; // Refresh policies without any optimisations.
  369. {$EXTERNALSYM RP_FORCE}
  370. function RefreshPolicyEx(bMachine: BOOL; dwOptions: DWORD): BOOL; stdcall;
  371. {$EXTERNALSYM RefreshPolicyEx}
  372. //=============================================================================
  373. //
  374. // EnterCriticalPolicySection
  375. //
  376. // Pauses the background application of group policy to allow safe
  377. // reading of the registry. Applications that need to read multiple
  378. // policy entries and ensure that the values are not changed while reading
  379. // them should use this function.
  380. //
  381. // The maximum amount of time an application can hold a critical section
  382. // is 10 minutes. After 10 minutes, policy can be applied again.
  383. //
  384. // bMachine - Pause machine or user policy
  385. //
  386. // Returns: Handle if successful
  387. // NULL if not. Call GetLastError() for more details
  388. //
  389. // Note 1: The handle returned should be passed to LeaveCriticalPolicySection
  390. // when finished. Do not close this handle, LeaveCriticalPolicySection
  391. // will do that.
  392. //
  393. // Note 2: If both user and machine critical sections need to be acquired then
  394. // they should be done in this order: first acquire user critical section and
  395. // then acquire machine critical section.
  396. //
  397. //=============================================================================
  398. function EnterCriticalPolicySection(bMachine: BOOL): HANDLE; stdcall;
  399. {$EXTERNALSYM EnterCriticalPolicySection}
  400. //=============================================================================
  401. //
  402. // LeaveCriticalPolicySection
  403. //
  404. // Resumes the background application of group policy. See
  405. // EnterCriticalPolicySection for more details.
  406. //
  407. // hSection - Handle returned from EnterCriticalPolicySection
  408. //
  409. // Returns: TRUE if successful
  410. // FALSE if not. Call GetLastError() for more details
  411. //
  412. // Note: This function will close the handle.
  413. //
  414. //=============================================================================
  415. function LeaveCriticalPolicySection(hSection: HANDLE): BOOL; stdcall;
  416. {$EXTERNALSYM LeaveCriticalPolicySection}
  417. //=============================================================================
  418. //
  419. // RegisterGPNotification
  420. //
  421. // Entry point for registering for Group Policy change notification.
  422. //
  423. // Parameters: hEvent - Event to be notified, by calling SetEvent(hEvent)
  424. // bMachine - If true, then register machine policy notification
  425. // else register user policy notification
  426. //
  427. // Returns: True if successful
  428. // False if error occurs
  429. //
  430. // Notes: Group Policy Notifications. There are 2 ways an application can
  431. // be notify when Group Policy is finished being applied.
  432. //
  433. // 1) Using the RegisterGPNotifcation function and waiting for the
  434. // event to be signalled.
  435. //
  436. // 2) A WM_SETTINGCHANGE message is broadcast to all desktops.
  437. // wParam - 1 if machine policy was applied, 0 if user policy was applied.
  438. // lParam - Points to the string "Policy"
  439. //
  440. //=============================================================================
  441. function RegisterGPNotification(hEvent: HANDLE; bMachine: BOOL): BOOL; stdcall;
  442. {$EXTERNALSYM RegisterGPNotification}
  443. //=============================================================================
  444. //
  445. // UnregisterGPNotification
  446. //
  447. // Removes registration for a Group Policy change notification.
  448. //
  449. // Parameters: hEvent - Event to be removed
  450. //
  451. // Returns: True if successful
  452. // False if error occurs
  453. //
  454. //=============================================================================
  455. function UnregisterGPNotification(hEvent: HANDLE): BOOL; stdcall;
  456. {$EXTERNALSYM UnregisterGPNotification}
  457. //=============================================================================
  458. //
  459. // GPOptions flags
  460. //
  461. // These are the flags found in the GPOptions property of a DS object
  462. //
  463. // For a given DS object (Site, Domain, OU), the GPOptions property
  464. // contains options that effect all the GPOs link to this SDOU.
  465. //
  466. // This is a DWORD type
  467. //
  468. //=============================================================================
  469. const
  470. GPC_BLOCK_POLICY = $00000001; // Block all non-forced policy from above
  471. {$EXTERNALSYM GPC_BLOCK_POLICY}
  472. //=============================================================================
  473. //
  474. // GPLink flags
  475. //
  476. // These are the flags found on the GPLink property of a DS object after
  477. // the GPO path.
  478. //
  479. // For a given DS object (Site, Domain, OU), the GPLink property will
  480. // be in this text format
  481. //
  482. // [LDAP://CN={E615A0E3-C4F1-11D1-A3A7-00AA00615092},CN=Policies,CN=System,DC=mydomain,DC=Microsoft,DC=Com;1]
  483. //
  484. // The GUID is the GPO name, and the number following the LDAP path are the options
  485. // for that link from this DS object. Note, there can be multiple GPOs
  486. // each in their own square brackets in a prioritized list.
  487. //
  488. //=============================================================================
  489. //
  490. // Options for a GPO link
  491. //
  492. const
  493. GPO_FLAG_DISABLE = $00000001; // This GPO is disabled
  494. {$EXTERNALSYM GPO_FLAG_DISABLE}
  495. GPO_FLAG_FORCE = $00000002; // Don't override the settings in
  496. {$EXTERNALSYM GPO_FLAG_FORCE} // this GPO with settings from a GPO below it.
  497. //=============================================================================
  498. //
  499. // GetGPOList
  500. //
  501. //
  502. // Queries for the list of Group Policy Objects for the specified
  503. // user or machine. This function will return a link list
  504. // of Group Policy Objects. Call FreeGPOList to free the list.
  505. //
  506. // Note, most applications will not need to call this function.
  507. // This will primarily be used by services acting on behalf of
  508. // another user or machine. The caller of this function will
  509. // need to look in each GPO for their specific policy
  510. //
  511. // This function can be called in two different ways. Either the hToken for
  512. // a user or machine can be supplied and the correct name and domain
  513. // controller name will be generated, or hToken is NULL and the caller
  514. // must supply the name and the domain controller name.
  515. //
  516. // Calling this function with an hToken ensures the list of Group Policy
  517. // Objects is correct for the user or machine since security access checking
  518. // can be perfomed. If hToken is not supplied, the security of the caller
  519. // is used instead which means that list may or may not be 100% correct
  520. // for the intended user / machine. However, this is the fastest way
  521. // to call this function.
  522. //
  523. // hToken - User or machine token, if NULL, lpName and lpHostName must be supplied
  524. // lpName - User or machine name in DN format, if hToken is supplied, this must be NULL
  525. // lpHostName - Domain DN name or domain controller name. If hToken is supplied, this must be NULL
  526. // lpComputerName - Computer name to use to determine site location. If NULL,
  527. // the local computer is used as the reference. Format: \\machinename
  528. // dwFlags - Flags field. See flags definition below
  529. // pGPOList - Address of a pointer which receives the link list of GPOs
  530. //
  531. //
  532. // Returns: TRUE if successful
  533. // FALSE if not. Use GetLastError() for more details.
  534. //
  535. // Examples:
  536. //
  537. // Here's how this function will typically be called for
  538. // looking up the list of GPOs for a user:
  539. //
  540. // LPGROUP_POLICY_OBJECT pGPOList;
  541. //
  542. // if (GetGPOList (hToken, NULL, NULL, NULL, 0, &pGPOList))
  543. // {
  544. // // do processing here...
  545. // FreeGPOList (pGPOList);
  546. // }
  547. //
  548. //
  549. // Here's how this function will typically be called for
  550. // looking up the list of GPOs for a machine:
  551. //
  552. // LPGROUP_POLICY_OBJECT pGPOList;
  553. //
  554. // if (GetGPOList (NULL, lpMachineName, lpHostName, lpMachineName,
  555. // GPO_LIST_FLAG_MACHINE, &pGPOList))
  556. // {
  557. // // do processing here...
  558. // FreeGPOList (pGPOList);
  559. // }
  560. //
  561. //=============================================================================
  562. //
  563. // Each Group Policy Object is associated (linked) with a site, domain,
  564. // organizational unit, or machine.
  565. //
  566. type
  567. _GPO_LINK = (
  568. GPLinkUnknown, // No link information available
  569. GPLinkMachine, // GPO linked to a machine (local or remote)
  570. GPLinkSite, // GPO linked to a site
  571. GPLinkDomain, // GPO linked to a domain
  572. GPLinkOrganizationalUnit); // GPO linked to a organizational unit
  573. {$EXTERNALSYM _GPO_LINK}
  574. GPO_LINK = _GPO_LINK;
  575. {$EXTERNALSYM GPO_LINK}
  576. PGPO_LINK = ^GPO_LINK;
  577. {$EXTERNALSYM PGPO_LINK}
  578. TGpoLink = GPO_LINK;
  579. PGpoLink = PGPO_LINK;
  580. PGROUP_POLICY_OBJECTA = ^GROUP_POLICY_OBJECTA;
  581. {$EXTERNALSYM PGROUP_POLICY_OBJECTA}
  582. _GROUP_POLICY_OBJECTA = record
  583. dwOptions: DWORD; // See GPLink option flags above
  584. dwVersion: DWORD; // Revision number of the GPO
  585. lpDSPath: LPSTR; // Path to the Active Directory portion of the GPO
  586. lpFileSysPath: LPSTR; // Path to the file system portion of the GPO
  587. lpDisplayName: LPSTR; // Friendly display name
  588. szGPOName: array [0..49] of CHAR; // Unique name
  589. GPOLink: GPO_LINK; // Link information
  590. lParam: LPARAM; // Free space for the caller to store GPO specific information
  591. pNext: PGROUP_POLICY_OBJECTA; // Next GPO in the list
  592. pPrev: PGROUP_POLICY_OBJECTA; // Previous GPO in the list
  593. lpExtensions: LPSTR; // Extensions that are relevant for this GPO
  594. lParam2: LPARAM; // Free space for the caller to store GPO specific information
  595. lpLink: LPSTR; // Path to the Active Directory site, domain, or organizational unit this GPO is linked to
  596. // If this is the local GPO, this points to the word "Local"
  597. end;
  598. {$EXTERNALSYM _GROUP_POLICY_OBJECTA}
  599. GROUP_POLICY_OBJECTA = _GROUP_POLICY_OBJECTA;
  600. {$EXTERNALSYM GROUP_POLICY_OBJECTA}
  601. TGroupPolicyObjectA = GROUP_POLICY_OBJECTA;
  602. PGroupPolicyObjectA = PGROUP_POLICY_OBJECTA;
  603. PGROUP_POLICY_OBJECTW = ^GROUP_POLICY_OBJECTW;
  604. {$EXTERNALSYM PGROUP_POLICY_OBJECTW}
  605. _GROUP_POLICY_OBJECTW = record
  606. dwOptions: DWORD; // See GPLink option flags above
  607. dwVersion: DWORD; // Revision number of the GPO
  608. lpDSPath: LPWSTR; // Path to the Active Directory portion of the GPO
  609. lpFileSysPath: LPWSTR; // Path to the file system portion of the GPO
  610. lpDisplayName: LPWSTR; // Friendly display name
  611. szGPOName: array [0..49] of WCHAR; // Unique name
  612. GPOLink: GPO_LINK; // Link information
  613. lParam: LPARAM; // Free space for the caller to store GPO specific information
  614. pNext: PGROUP_POLICY_OBJECTW; // Next GPO in the list
  615. pPrev: PGROUP_POLICY_OBJECTW; // Previous GPO in the list
  616. lpExtensions: LPWSTR; // Extensions that are relevant for this GPO
  617. lParam2: LPARAM; // Free space for the caller to store GPO specific information
  618. lpLink: LPWSTR; // Path to the Active Directory site, domain, or organizational unit this GPO is linked to
  619. // If this is the local GPO, this points to the word "Local"
  620. end;
  621. {$EXTERNALSYM _GROUP_POLICY_OBJECTW}
  622. GROUP_POLICY_OBJECTW = _GROUP_POLICY_OBJECTW;
  623. {$EXTERNALSYM GROUP_POLICY_OBJECTW}
  624. TGroupPolicyObjectW = GROUP_POLICY_OBJECTW;
  625. PGroupPolicyObjectW = PGROUP_POLICY_OBJECTW;
  626. PPGROUP_POLICY_OBJECTA = ^PGROUP_POLICY_OBJECTA;
  627. {$NODEFINE PPGROUP_POLICY_OBJECTA}
  628. PPGROUP_POLICY_OBJECTW = ^PGROUP_POLICY_OBJECTW;
  629. {$NODEFINE PPGROUP_POLICY_OBJECTW}
  630. {$IFDEF UNICODE}
  631. GROUP_POLICY_OBJECT = GROUP_POLICY_OBJECTW;
  632. {$EXTERNALSYM GROUP_POLICY_OBJECT}
  633. PGROUP_POLICY_OBJECT = PGROUP_POLICY_OBJECTW;
  634. {$EXTERNALSYM PGROUP_POLICY_OBJECT}
  635. PPGROUP_POLICY_OBJECT = PPGROUP_POLICY_OBJECTW;
  636. {$NODEFINE PPGROUP_POLICY_OBJECT}
  637. TGroupPolicyObject = TGroupPolicyObjectW;
  638. PGroupPolicyObject = PGroupPolicyObjectW;
  639. {$ELSE}
  640. GROUP_POLICY_OBJECT = GROUP_POLICY_OBJECTA;
  641. {$EXTERNALSYM GROUP_POLICY_OBJECT}
  642. PGROUP_POLICY_OBJECT = PGROUP_POLICY_OBJECTA;
  643. {$EXTERNALSYM PGROUP_POLICY_OBJECT}
  644. PPGROUP_POLICY_OBJECT = PPGROUP_POLICY_OBJECTA;
  645. {$NODEFINE PPGROUP_POLICY_OBJECT}
  646. TGroupPolicyObject = TGroupPolicyObjectA;
  647. PGroupPolicyObject = PGroupPolicyObjectA;
  648. {$ENDIF UNICODE}
  649. //
  650. // dwFlags for GetGPOList()
  651. //
  652. const
  653. GPO_LIST_FLAG_MACHINE = $00000001; // Return machine policy information
  654. {$EXTERNALSYM GPO_LIST_FLAG_MACHINE}
  655. GPO_LIST_FLAG_SITEONLY = $00000002; // Return site policy information only
  656. {$EXTERNALSYM GPO_LIST_FLAG_SITEONLY}
  657. function GetGPOListA(hToken: HANDLE; lpName: LPCSTR; lpHostName: LPCSTR;
  658. lpComputerName: LPCSTR; dwFlags: DWORD; pGPOList: PPGROUP_POLICY_OBJECTA): BOOL; stdcall;
  659. {$EXTERNALSYM GetGPOListA}
  660. function GetGPOListW(hToken: HANDLE; lpName: LPCWSTR; lpHostName: LPCWSTR;
  661. lpComputerName: LPCWSTR; dwFlags: DWORD; pGPOList: PPGROUP_POLICY_OBJECTW): BOOL; stdcall;
  662. {$EXTERNALSYM GetGPOListW}
  663. function GetGPOList(hToken: HANDLE; lpName: LPCTSTR; lpHostName: LPCTSTR;
  664. lpComputerName: LPCTSTR; dwFlags: DWORD; pGPOList: PPGROUP_POLICY_OBJECT): BOOL; stdcall;
  665. {$EXTERNALSYM GetGPOList}
  666. //=============================================================================
  667. //
  668. // FreeGPOList
  669. //
  670. //
  671. // Frees the linked list returned from GetGPOList
  672. //
  673. // pGPOList - Pointer to the linked list of GPOs
  674. //
  675. //
  676. // Returns: TRUE if successful
  677. // FALSE if not
  678. //
  679. //=============================================================================
  680. function FreeGPOListA(pGPOList: PGROUP_POLICY_OBJECTA): BOOL; stdcall;
  681. {$EXTERNALSYM FreeGPOListA}
  682. function FreeGPOListW(pGPOList: PGROUP_POLICY_OBJECTW): BOOL; stdcall;
  683. {$EXTERNALSYM FreeGPOListW}
  684. function FreeGPOList(pGPOList: PGROUP_POLICY_OBJECT): BOOL; stdcall;
  685. {$EXTERNALSYM FreeGPOList}
  686. //=============================================================================
  687. //
  688. // GetAppliedGPOList
  689. //
  690. // Queries for the list of applied Group Policy Objects for the specified
  691. // user or machine and specified client side extension. This function will return
  692. // a linked listof Group Policy Objects. Call FreeGPOList to free the list.
  693. //
  694. // dwFlags - User or machine policy, if it is GPO_LIST_FLAG_MACHINE then
  695. // return machine policy information
  696. // pMachineName - Name of remote computer in the form \\computername. If null
  697. // then local computer is used.
  698. // pSidUser - Security id of user (relevant for user policy). If pMachineName is
  699. // null and pSidUser is null then it means current logged on user.
  700. // If pMachine is null and pSidUser is non-null then it means user
  701. // represented by pSidUser on local machine. If pMachineName is non-null
  702. // then and if dwFlags specifies user policy, then pSidUser must be
  703. // non-null.
  704. // pGuidExtension - Guid of the specified extension
  705. // ppGPOList - Address of a pointer which receives the link list of GPOs
  706. //
  707. // The return value is a Win32 error code. ERROR_SUCCESS means the GetAppliedGPOList
  708. // function completed successfully. Otherwise it indicates that the function failed.
  709. //
  710. //=============================================================================
  711. function GetAppliedGPOListA(dwFlags: DWORD; pMachineName: LPCSTR; pSidUser: PSID;
  712. pGuidExtension: LPGUID; ppGPOList: PPGROUP_POLICY_OBJECTA): DWORD; stdcall;
  713. {$EXTERNALSYM GetAppliedGPOListA}
  714. function GetAppliedGPOListW(dwFlags: DWORD; pMachineName: LPCWSTR; pSidUser: PSID;
  715. pGuidExtension: LPGUID; ppGPOList: PPGROUP_POLICY_OBJECTW): DWORD; stdcall;
  716. {$EXTERNALSYM GetAppliedGPOListW}
  717. function GetAppliedGPOList(dwFlags: DWORD; pMachineName: LPCTSTR; pSidUser: PSID;
  718. pGuidExtension: LPGUID; ppGPOList: PPGROUP_POLICY_OBJECT): DWORD; stdcall;
  719. {$EXTERNALSYM GetAppliedGPOList}
  720. //=============================================================================
  721. //
  722. // Group Policy Object client side extension support
  723. //
  724. // Flags, data structures and function prototype
  725. //
  726. // To register your extension, create a subkey under this key
  727. //
  728. // Software\Microsoft\Windows NT\CurrentVersion\Winlogon\GPExtensions
  729. //
  730. // The subkey needs to be a guid so that it is unique. The noname value of the subkey
  731. // can be the friendly name of the extension. Then add these values:
  732. //
  733. // DllName REG_EXPAND_SZ Path to your DLL
  734. // ProcessGroupPolicy REG_SZ Function name (see PFNPROCESSGROUPPOLICY prototype). This
  735. // is obsolete, it has been superseded by ProcessGroupPolicyEx.
  736. // It's here for backward compatibility reasons only.
  737. // ProcessGroupPolicyEx REG_SZ Function name (see PFNPROCESSGROUPPOLICYEX prototype)
  738. // GenerateGroupPolicy REG_SZ Function name for Rsop (see PFNGENERATEGROUPPOLICY prototype)
  739. // NoMachinePolicy REG_DWORD True, if extension does not have to be called when
  740. // machine policies are being processed.
  741. // NoUserPolicy REG_DWORD True, if extension does not have to be called when
  742. // user policies are being processed.
  743. // NoSlowLink REG_DWORD True, if extension does not have to be called on a slow link
  744. // NoBackgroundPolicy REG_DWORD True, if extension does not have to be called
  745. // for background policy processing.
  746. // NoGPOListChanges REG_DWORD True, if extension does not have to be called when
  747. // there are no changes between cached and current GPO lists.
  748. // PerUserLocalSettings REG_DWORD True, if user policies have to be cached on a per user and
  749. // per machine basis.
  750. // RequiresSuccessfulRegistry REG_DWORD True, if extension should be called only if registry extension
  751. // was successfully processed.
  752. // EnableAsynchronousProcessing REG_DWORD True, if registry extension will complete its processing
  753. // asynchronously.
  754. // NotifyLinkTransition REG_DWORD True, if extension should be called when a change in link
  755. // speed is detected between previous policy application and
  756. // current policy application.
  757. //
  758. // The return value is a Win32 error code. ERROR_SUCCESS means the ProcessGroupPolicy
  759. // function completed successfully. If return value is ERROR_OVERRIDE_NOCHANGES then it
  760. // means that the extension will be called the next time even if NoGPOListChanges is set
  761. // and there are no changes to the GPO list. Any other return value indicates that the
  762. // ProcessGroupPolicy or ProcessGroupPolicyEx function failed.
  763. //
  764. //=============================================================================
  765. const
  766. GP_DLLNAME = 'DllName';
  767. {$EXTERNALSYM GP_DLLNAME}
  768. GP_ENABLEASYNCHRONOUSPROCESSING = 'EnableAsynchronousProcessing';
  769. {$EXTERNALSYM GP_ENABLEASYNCHRONOUSPROCESSING}
  770. GP_MAXNOGPOLISTCHANGESINTERVAL = 'MaxNoGPOListChangesInterval';
  771. {$EXTERNALSYM GP_MAXNOGPOLISTCHANGESINTERVAL}
  772. GP_NOBACKGROUNDPOLICY = 'NoBackgroundPolicy';
  773. {$EXTERNALSYM GP_NOBACKGROUNDPOLICY}
  774. GP_NOGPOLISTCHANGES = 'NoGPOListChanges';
  775. {$EXTERNALSYM GP_NOGPOLISTCHANGES}
  776. GP_NOMACHINEPOLICY = 'NoMachinePolicy';
  777. {$EXTERNALSYM GP_NOMACHINEPOLICY}
  778. GP_NOSLOWLINK = 'NoSlowLink';
  779. {$EXTERNALSYM GP_NOSLOWLINK}
  780. GP_NOTIFYLINKTRANSITION = 'NotifyLinkTransition';
  781. {$EXTERNALSYM GP_NOTIFYLINKTRANSITION}
  782. GP_NOUSERPOLICY = 'NoUserPolicy';
  783. {$EXTERNALSYM GP_NOUSERPOLICY}
  784. GP_PERUSERLOCALSETTINGS = 'PerUserLocalSettings';
  785. {$EXTERNALSYM GP_PERUSERLOCALSETTINGS}
  786. GP_PROCESSGROUPPOLICY = 'ProcessGroupPolicy';
  787. {$EXTERNALSYM GP_PROCESSGROUPPOLICY}
  788. GP_REQUIRESSUCCESSFULREGISTRY = 'RequiresSuccessfulRegistry';
  789. {$EXTERNALSYM GP_REQUIRESSUCCESSFULREGISTRY}
  790. GPO_INFO_FLAG_MACHINE = $00000001; // Apply machine policy rather than user policy
  791. {$EXTERNALSYM GPO_INFO_FLAG_MACHINE}
  792. GPO_INFO_FLAG_BACKGROUND = $00000010; // Background refresh of policy (ok to do slow stuff)
  793. {$EXTERNALSYM GPO_INFO_FLAG_BACKGROUND}
  794. GPO_INFO_FLAG_SLOWLINK = $00000020; // Policy is being applied across a slow link
  795. {$EXTERNALSYM GPO_INFO_FLAG_SLOWLINK}
  796. GPO_INFO_FLAG_VERBOSE = $00000040; // Verbose output to the eventlog
  797. {$EXTERNALSYM GPO_INFO_FLAG_VERBOSE}
  798. GPO_INFO_FLAG_NOCHANGES = $00000080; // No changes were detected to the Group Policy Objects
  799. {$EXTERNALSYM GPO_INFO_FLAG_NOCHANGES}
  800. GPO_INFO_FLAG_LINKTRANSITION = $00000100; // A change in link speed was detected between previous policy
  801. {$EXTERNALSYM GPO_INFO_FLAG_LINKTRANSITION} // application and current policy application
  802. GPO_INFO_FLAG_LOGRSOP_TRANSITION = $00000200; // A Change in Rsop Logging was detected between previous policy
  803. {$EXTERNALSYM GPO_INFO_FLAG_LOGRSOP_TRANSITION} // application and current policy application, (new intf only)
  804. GPO_INFO_FLAG_FORCED_REFRESH = $00000400; // Forced Refresh is being applied. redo policies.
  805. {$EXTERNALSYM GPO_INFO_FLAG_FORCED_REFRESH}
  806. GPO_INFO_FLAG_SAFEMODE_BOOT = $00000800; // windows safe mode boot flag
  807. {$EXTERNALSYM GPO_INFO_FLAG_SAFEMODE_BOOT}
  808. GPO_INFO_FLAG_ASYNC_FOREGROUND = $00001000; // Asynchronous foreground refresh of policy
  809. {$EXTERNALSYM GPO_INFO_FLAG_ASYNC_FOREGROUND}
  810. GPO_INFO_FLAG_REPORT = $00002000; // Report all settings for one GPO rather than the resultant settings across multiple GPOs
  811. {$EXTERNALSYM GPO_INFO_FLAG_REPORT}
  812. type
  813. ASYNCCOMPLETIONHANDLE = UINT_PTR;
  814. {$EXTERNALSYM ASYNCCOMPLETIONHANDLE}
  815. PFNSTATUSMESSAGECALLBACK = function(bVerbose: BOOL; lpMessage: LPWSTR): DWORD; stdcall;
  816. {$EXTERNALSYM PFNSTATUSMESSAGECALLBACK}
  817. PFNPROCESSGROUPPOLICY = function(
  818. dwFlags: DWORD; // GPO_INFO_FLAGS
  819. hToken: HANDLE; // User or machine token
  820. hKeyRoot: HKEY; // Root of registry
  821. pDeletedGPOList: PGROUP_POLICY_OBJECT; // Linked list of deleted GPOs
  822. pChangedGPOList: PGROUP_POLICY_OBJECT; // Linked list of changed GPOs
  823. pHandle: ASYNCCOMPLETIONHANDLE; // For asynchronous completion
  824. pbAbort: LPBOOL; // If true, then abort GPO processing
  825. pStatusCallback: PFNSTATUSMESSAGECALLBACK // Callback function for displaying status messages
  826. ): DWORD; stdcall; // Note, this can be NULL
  827. {$EXTERNALSYM PFNPROCESSGROUPPOLICY}
  828. PFNPROCESSGROUPPOLICYEX = function(
  829. dwFlags: DWORD; // GPO_INFO_FLAGS
  830. hToken: HANDLE; // User or machine token
  831. hKeyRoot: HKEY; // Root of registry
  832. pDeletedGPOList: PGROUP_POLICY_OBJECT; // Linked list of deleted GPOs
  833. pChangedGPOList: PGROUP_POLICY_OBJECT; // Linked list of changed GPOs
  834. pHandle: ASYNCCOMPLETIONHANDLE; // For asynchronous completion
  835. pbAbort: PBOOL; // If true, then abort GPO processing
  836. pStatusCallback: PFNSTATUSMESSAGECALLBACK; // Callback function for displaying status messages
  837. // Note, this can be NULL
  838. pWbemServices: IWbemServices; // Pointer to namespace to log diagnostic mode data
  839. // Note, this will be NULL when Rsop logging is disabled
  840. var pRsopStatus: HRESULT // RSOP Logging succeeded or not.
  841. ): DWORD; stdcall;
  842. {$EXTERNALSYM PFNPROCESSGROUPPOLICYEX}
  843. PRSOPTOKEN = PVOID;
  844. {$EXTERNALSYM PRSOPTOKEN}
  845. _RSOP_TARGET = record
  846. pwszAccountName: PWCHAR; // Account name
  847. pwszNewSOM: PWCHAR; // New domain or OU location for account
  848. psaSecurityGroups: PSafeArray; // New security groups
  849. pRsopToken: PRSOPTOKEN; // Rsop token for use with Rsop security Api's
  850. pGPOList: PGROUP_POLICY_OBJECT; // Linked list of GPOs
  851. pWbemServices: IWbemServices; // Pointer to namespace to log planning mode data
  852. end;
  853. {$EXTERNALSYM _RSOP_TARGET}
  854. RSOP_TARGET = _RSOP_TARGET;
  855. {$EXTERNALSYM RSOP_TARGET}
  856. PRSOP_TARGET = ^RSOP_TARGET;
  857. {$EXTERNALSYM PRSOP_TARGET}
  858. TRsopTarget = RSOP_TARGET;
  859. PRsopTarget = PRSOP_TARGET;
  860. PFNGENERATEGROUPPOLICY = function(
  861. dwFlags: DWORD; // GPO_INFO_FLAGS
  862. var pbAbort: BOOL; // If true, then abort GPO processing
  863. pwszSite: PWCHAR; // Site the target computer is in
  864. pComputerTarget: PRSOP_TARGET; // Computer target info, can be null
  865. pUserTarget: PRSOP_TARGET // User target info, can be null
  866. ): DWORD; stdcall;
  867. {$EXTERNALSYM PFNGENERATEGROUPPOLICY}
  868. //
  869. // GUID that identifies the registry extension
  870. //
  871. const
  872. REGISTRY_EXTENSION_GUID: GUID = (
  873. D1: $35378EAC; D2:$683F; D3:$11D2; D4:($A8, $9A, $00, $C0, $4F, $BB, $CF, $A2));
  874. {$EXTERNALSYM REGISTRY_EXTENSION_GUID}
  875. //=============================================================================
  876. //
  877. // Group Policy Object client side asynchronous extension processing
  878. //
  879. // extensionId - Unique guid identifying the extension
  880. // pAsyncHandle - Asynchronous completion handle that was passed to extension in
  881. // ProcessGroupPolicy call
  882. // dwStatus - Completion status of asynchronous processing
  883. //
  884. // The return value is a Win32 error code. ERROR_SUCCESS means the ProcessGroupPolicyCompleted
  885. // function completed successfully. Otherwise it indicates that the function failed.
  886. //
  887. //=============================================================================
  888. type
  889. REFGPEXTENSIONID = LPGUID;
  890. {$EXTERNALSYM REFGPEXTENSIONID}
  891. function ProcessGroupPolicyCompleted(extensionId: REFGPEXTENSIONID;
  892. pAsyncHandle: ASYNCCOMPLETIONHANDLE; dwStatus: DWORD): DWORD; stdcall;
  893. {$EXTERNALSYM ProcessGroupPolicyCompleted}
  894. //=============================================================================
  895. //
  896. // Group Policy Object client side asynchronous extension processing
  897. //
  898. // extensionId - Unique guid identifying the extension
  899. // pAsyncHandle - Asynchronous completion handle that was passed to extension in
  900. // ProcessGroupPolicy call
  901. // dwStatus - Completion status of asynchronous processing
  902. // RsopStatus - RSoP Logging status
  903. //
  904. // The return value is a Win32 error code. ERROR_SUCCESS means the ProcessGroupPolicyCompleted
  905. // function completed successfully. Otherwise it indicates that the function failed.
  906. //
  907. //=============================================================================
  908. function ProcessGroupPolicyCompletedEx(extensionId: REFGPEXTENSIONID; pAsyncHandle: ASYNCCOMPLETIONHANDLE;
  909. dwStatus: DWORD; RsopStatus: HRESULT): DWORD; stdcall;
  910. {$EXTERNALSYM ProcessGroupPolicyCompletedEx}
  911. //=============================================================================
  912. //
  913. // Function: RsopAccessCheckByType
  914. //
  915. // Description: Determines whether the security descriptor pointed to by pSecurityDescriptor
  916. // grants the set of access rights specified in dwDesiredAccessMask
  917. // to the client identified by the RSOPTOKEN pointed to by pRsopToken.
  918. //
  919. // pSecurityDescriptor - Security Descriptor on the object
  920. // pPrincipalSelfSid - Principal Sid
  921. // pRsopToken - Pointer to a valid RSOPTOKEN against which access needs to be checked
  922. // dwDesiredAccessMask - Mask of requested generic and/or standard and or specific access rights
  923. // pObjectTypeList - Object Type List
  924. // ObjectTypeListLength - Object Type List Length
  925. // pGenericMapping - Generic Mapping
  926. // pPrivilegeSet - privilege set
  927. // pdwPrivilegeSetLength- privilege set length
  928. // pdwGrantedAccessMask - On success, if pbAccessStatus is true, it contains
  929. // the mask of standard and specific rights granted.
  930. // If pbAccessStatus is false, it is set to 0.
  931. // On failure, it is not modified.
  932. // pbAccessStatus - On success, indicates wether the requested set
  933. // of access rights was granted.
  934. // On failure, it is not modified
  935. //
  936. // Returns S_OK on success or appropriate error code.
  937. // For additional details, look at the documentation of AccessCheckByType
  938. //=============================================================================
  939. function RsopAccessCheckByType(pSecurityDescriptor: PSECURITY_DESCRIPTOR; pPrincipalSelfSid: PSID;
  940. pRsopToken: PRSOPTOKEN; dwDesiredAccessMask: DWORD; pObjectTypeList: POBJECT_TYPE_LIST;
  941. ObjectTypeListLength: DWORD; pGenericMapping: PGENERIC_MAPPING; pPrivilegeSet: PPRIVILEGE_SET;
  942. pdwPrivilegeSetLength: LPDWORD; pdwGrantedAccessMask: LPDWORD; pbAccessStatus: LPBOOL): HRESULT; stdcall;
  943. {$EXTERNALSYM RsopAccessCheckByType}
  944. //=============================================================================
  945. //
  946. // Function: RsopFileAccessCheck
  947. //
  948. // Description: Determines whether the security descriptor on the file grants the set of file access
  949. // rights specified in dwDesiredAccessMask
  950. // to the client identified by the RSOPTOKEN pointed to by pRsopToken.
  951. //
  952. // pszFileName - Name of an existing filename
  953. // pRsopToken - Pointer to a valid RSOPTOKEN against which access needs to be checked
  954. // dwDesiredAccessMask - Mask of requested generic and/or standard and or specific access rights
  955. // pdwGrantedAccessMask - On success, if pbAccessStatus is true, it contains
  956. // the mask of standard and specific rights granted.
  957. // If pbAccessStatus is false, it is set to 0.
  958. // On failure, it is not modified.
  959. // pbAccessStatus - On success, indicates wether the requested set
  960. // of access rights was granted.
  961. // On failure, it is not modified
  962. //
  963. // Returns S_OK on success or appropriate error code
  964. //=============================================================================
  965. function RsopFileAccessCheck(pszFileName: LPWSTR; pRsopToken: PRSOPTOKEN; dwDesiredAccessMask: DWORD;
  966. pdwGrantedAccessMask: LPDWORD; pbAccessStatus: LPBOOL): HRESULT; stdcall;
  967. {$EXTERNALSYM RsopFileAccessCheck}
  968. type
  969. _SETTINGSTATUS = (
  970. RSOPUnspecified,
  971. RSOPApplied,
  972. RSOPIgnored,
  973. RSOPFailed,
  974. RSOPSubsettingFailed);
  975. {$EXTERNALSYM _SETTINGSTATUS}
  976. SETTINGSTATUS = _SETTINGSTATUS;
  977. {$EXTERNALSYM SETTINGSTATUS}
  978. TSettingStatus = SETTINGSTATUS;
  979. //=============================================================================
  980. //
  981. // POLICYSETTINGSTATUSINFO
  982. //
  983. // Describes the instance of RSOP_PolicySettingStatus
  984. //
  985. // szKey - OPTIONAL, if NULL, the key is generated on the fly
  986. // szEventSource - name of the source generation event log messages
  987. // szEventLogName - name of the event log database where the messages are logged
  988. // dwEventID - event log message ID
  989. // status - status of the policy setting
  990. // timeLogged - time at which the event log message was logged
  991. //
  992. //=============================================================================
  993. type
  994. _POLICYSETTINGSTATUSINFO = record
  995. szKey: LPWSTR;
  996. szEventSource: LPWSTR;
  997. szEventLogName: LPWSTR;
  998. dwEventID: DWORD;
  999. dwErrorCode: DWORD;
  1000. status: SETTINGSTATUS;
  1001. timeLogged: SYSTEMTIME;
  1002. end;
  1003. {$EXTERNALSYM _POLICYSETTINGSTATUSINFO}
  1004. POLICYSETTINGSTATUSINFO = _POLICYSETTINGSTATUSINFO;
  1005. {$EXTERNALSYM POLICYSETTINGSTATUSINFO}
  1006. LPPOLICYSETTINGSTATUSINFO = ^POLICYSETTINGSTATUSINFO;
  1007. {$EXTERNALSYM LPPOLICYSETTINGSTATUSINFO}
  1008. TPolicySettingStatusInfo = POLICYSETTINGSTATUSINFO;
  1009. PPolicySettingStatusInfo = LPPOLICYSETTINGSTATUSINFO;
  1010. //=============================================================================
  1011. //
  1012. // RsopSetPolicySettingStatus
  1013. //
  1014. // Creates an instance of RSOP_PolicySettingStatus and RSOP_PolicySettingLink
  1015. // and links RSOP_PolicySettingStatus to RSOP_PolicySetting
  1016. //
  1017. // dwFlags - flags
  1018. // pServices - RSOP namespace
  1019. // pSettingInstance - instance of RSOP_PolicySetting or its children
  1020. // nInfo - number of PolicySettingStatusInfo
  1021. // pStatus - array of PolicySettingStatusInfo
  1022. //
  1023. // Return: S_OK if successful, HRESULT otherwise
  1024. //
  1025. //=============================================================================
  1026. function RsopSetPolicySettingStatus(dwFlags: DWORD; pServices: IWbemServices;
  1027. pSettingInstance: IWbemClassObject; nInfo: DWORD;
  1028. pStatus: LPPOLICYSETTINGSTATUSINFO): HRESULT; stdcall;
  1029. {$EXTERNALSYM RsopSetPolicySettingStatus}
  1030. //=============================================================================
  1031. //
  1032. // RsopResetPolicySettingStatus
  1033. //
  1034. // Unlinks RSOP_PolicySettingStatus from RSOP_PolicySetting,
  1035. // deletes the instance of RSOP_PolicySettingStatus and RSOP_PolicySettingLink
  1036. // and optionally deletes the instance of RSOP_PolicySetting
  1037. //
  1038. // dwFlags - flags
  1039. // pServices - RSOP namespace
  1040. // pSettingInstance - instance of RSOP_PolicySetting or its children
  1041. //
  1042. // Return: S_OK if successful, HRESULT otherwise
  1043. //
  1044. //=============================================================================
  1045. function RsopResetPolicySettingStatus(dwFlags: DWORD; pServices: IWbemServices;
  1046. pSettingInstance: IWbemClassObject): HRESULT; stdcall;
  1047. {$EXTERNALSYM RsopResetPolicySettingStatus}
  1048. //=============================================================================
  1049. //
  1050. // Flags for RSoP WMI providers
  1051. //
  1052. //=============================================================================
  1053. // planning mode provider flags
  1054. const
  1055. FLAG_NO_GPO_FILTER = DWORD($80000000); // GPOs are not filtered, implies FLAG_NO_CSE_INVOKE
  1056. {$EXTERNALSYM FLAG_NO_GPO_FILTER}
  1057. FLAG_NO_CSE_INVOKE = $40000000; // only GP processing done for planning mode
  1058. {$EXTERNALSYM FLAG_NO_CSE_INVOKE}
  1059. FLAG_ASSUME_SLOW_LINK = $20000000; // planning mode RSoP assumes slow link
  1060. {$EXTERNALSYM FLAG_ASSUME_SLOW_LINK}
  1061. FLAG_LOOPBACK_MERGE = $10000000; // planning mode RSoP assumes merge loop back
  1062. {$EXTERNALSYM FLAG_LOOPBACK_MERGE}
  1063. FLAG_LOOPBACK_REPLACE = $08000000; // planning mode RSoP assumes replace loop back
  1064. {$EXTERNALSYM FLAG_LOOPBACK_REPLACE}
  1065. FLAG_ASSUME_USER_WQLFILTER_TRUE = $04000000; // planning mode RSoP assumes all comp filters to be true
  1066. {$EXTERNALSYM FLAG_ASSUME_USER_WQLFILTER_TRUE}
  1067. FLAG_ASSUME_COMP_WQLFILTER_TRUE = $02000000; // planning mode RSoP assumes all user filters to be true
  1068. {$EXTERNALSYM FLAG_ASSUME_COMP_WQLFILTER_TRUE}
  1069. FLAG_PLANNING_MODE = $01000000; // flag that indicates that a given namespace was created
  1070. {$EXTERNALSYM FLAG_PLANNING_MODE} // for planning mode. This flag cannot be passed in but the
  1071. // relevant subnamespace will be marked with this flag
  1072. // diagnostic mode provider flags
  1073. FLAG_NO_USER = $00000001; // Don't get any user data
  1074. {$EXTERNALSYM FLAG_NO_USER}
  1075. FLAG_NO_COMPUTER = $00000002; // Don't get any machine data
  1076. {$EXTERNALSYM FLAG_NO_COMPUTER}
  1077. FLAG_FORCE_CREATENAMESPACE = $00000004; // Delete and recreate the namespace for this snapshot.
  1078. {$EXTERNALSYM FLAG_FORCE_CREATENAMESPACE}
  1079. //=============================================================================
  1080. //
  1081. // Extended Errors returned by RSoP WMI Providers
  1082. //
  1083. //=============================================================================
  1084. // User accessing the rsop provider doesn't have access to user data.
  1085. RSOP_USER_ACCESS_DENIED = $00000001;
  1086. {$EXTERNALSYM RSOP_USER_ACCESS_DENIED}
  1087. // User accessing the rsop provider doesn't have access to computer data.
  1088. RSOP_COMPUTER_ACCESS_DENIED = $00000002;
  1089. {$EXTERNALSYM RSOP_COMPUTER_ACCESS_DENIED}
  1090. // This user is an interactive non admin user, the temp snapshot namespace already exists
  1091. // and the FLAG_FORCE_CREATENAMESPACE was not passed in
  1092. RSOP_TEMPNAMESPACE_EXISTS = $00000004;
  1093. {$EXTERNALSYM RSOP_TEMPNAMESPACE_EXISTS}
  1094. implementation
  1095. uses
  1096. JwaWinDLLNames;
  1097. {$IFDEF DYNAMIC_LINK}
  1098. var
  1099. _LoadUserProfileA: Pointer;
  1100. function LoadUserProfileA;
  1101. begin
  1102. GetProcedureAddress(_LoadUserProfileA, userenvlib, 'LoadUserProfileA');
  1103. asm
  1104. MOV ESP, EBP
  1105. POP EBP
  1106. JMP [_LoadUserProfileA]
  1107. end;
  1108. end;
  1109. var
  1110. _LoadUserProfileW: Pointer;
  1111. function LoadUserProfileW;
  1112. begin
  1113. GetProcedureAddress(_LoadUserProfileW, userenvlib, 'LoadUserProfileW');
  1114. asm
  1115. MOV ESP, EBP
  1116. POP EBP
  1117. JMP [_LoadUserProfileW]
  1118. end;
  1119. end;
  1120. var
  1121. _LoadUserProfile: Pointer;
  1122. function LoadUserProfile;
  1123. begin
  1124. GetProcedureAddress(_LoadUserProfile, userenvlib, 'LoadUserProfile' + AWSuffix);
  1125. asm
  1126. MOV ESP, EBP
  1127. POP EBP
  1128. JMP [_LoadUserProfile]
  1129. end;
  1130. end;
  1131. var
  1132. _UnloadUserProfile: Pointer;
  1133. function UnloadUserProfile;
  1134. begin
  1135. GetProcedureAddress(_UnloadUserProfile, userenvlib, 'UnloadUserProfile');
  1136. asm
  1137. MOV ESP, EBP
  1138. POP EBP
  1139. JMP [_UnloadUserProfile]
  1140. end;
  1141. end;
  1142. var
  1143. _GetProfilesDirectoryA: Pointer;
  1144. function GetProfilesDirectoryA;
  1145. begin
  1146. GetProcedureAddress(_GetProfilesDirectoryA, userenvlib, 'GetProfilesDirectoryA');
  1147. asm
  1148. MOV ESP, EBP
  1149. POP EBP
  1150. JMP [_GetProfilesDirectoryA]
  1151. end;
  1152. end;
  1153. var
  1154. _GetProfilesDirectoryW: Pointer;
  1155. function GetProfilesDirectoryW;
  1156. begin
  1157. GetProcedureAddress(_GetProfilesDirectoryW, userenvlib, 'GetProfilesDirectoryW');
  1158. asm
  1159. MOV ESP, EBP
  1160. POP EBP
  1161. JMP [_GetProfilesDirectoryW]
  1162. end;
  1163. end;
  1164. var
  1165. _GetProfilesDirectory: Pointer;
  1166. function GetProfilesDirectory;
  1167. begin
  1168. GetProcedureAddress(_GetProfilesDirectory, userenvlib, 'GetProfilesDirectory' + AWSuffix);
  1169. asm
  1170. MOV ESP, EBP
  1171. POP EBP
  1172. JMP [_GetProfilesDirectory]
  1173. end;
  1174. end;
  1175. var
  1176. _GetProfileType: Pointer;
  1177. function GetProfileType;
  1178. begin
  1179. GetProcedureAddress(_GetProfileType, userenvlib, 'GetProfileType');
  1180. asm
  1181. MOV ESP, EBP
  1182. POP EBP
  1183. JMP [_GetProfileType]
  1184. end;
  1185. end;
  1186. var
  1187. _DeleteProfileA: Pointer;
  1188. function DeleteProfileA;
  1189. begin
  1190. GetProcedureAddress(_DeleteProfileA, userenvlib, 'DeleteProfileA');
  1191. asm
  1192. MOV ESP, EBP
  1193. POP EBP
  1194. JMP [_DeleteProfileA]
  1195. end;
  1196. end;
  1197. var
  1198. _DeleteProfileW: Pointer;
  1199. function DeleteProfileW;
  1200. begin
  1201. GetProcedureAddress(_DeleteProfileW, userenvlib, 'DeleteProfileW');
  1202. asm
  1203. MOV ESP, EBP
  1204. POP EBP
  1205. JMP [_DeleteProfileW]
  1206. end;
  1207. end;
  1208. var
  1209. _DeleteProfile: Pointer;
  1210. function DeleteProfile;
  1211. begin
  1212. GetProcedureAddress(_DeleteProfile, userenvlib, 'DeleteProfile' + AWSuffix);
  1213. asm
  1214. MOV ESP, EBP
  1215. POP EBP
  1216. JMP [_DeleteProfile]
  1217. end;
  1218. end;
  1219. var
  1220. _GetDefaultUserProfileDirectoryA: Pointer;
  1221. function GetDefaultUserProfileDirectoryA;
  1222. begin
  1223. GetProcedureAddress(_GetDefaultUserProfileDirectoryA, userenvlib, 'GetDefaultUserProfileDirectoryA');
  1224. asm
  1225. MOV ESP, EBP
  1226. POP EBP
  1227. JMP [_GetDefaultUserProfileDirectoryA]
  1228. end;
  1229. end;
  1230. var
  1231. _GetDefaultUserProfileDirectoryW: Pointer;
  1232. function GetDefaultUserProfileDirectoryW;
  1233. begin
  1234. GetProcedureAddress(_GetDefaultUserProfileDirectoryW, userenvlib, 'GetDefaultUserProfileDirectoryW');
  1235. asm
  1236. MOV ESP, EBP
  1237. POP EBP
  1238. JMP [_GetDefaultUserProfileDirectoryW]
  1239. end;
  1240. end;
  1241. var
  1242. _GetDefaultUserProfileDirectory: Pointer;
  1243. function GetDefaultUserProfileDirectory;
  1244. begin
  1245. GetProcedureAddress(_GetDefaultUserProfileDirectory, userenvlib, 'GetDefaultUserProfileDirectory' + AWSuffix);
  1246. asm
  1247. MOV ESP, EBP
  1248. POP EBP
  1249. JMP [_GetDefaultUserProfileDirectory]
  1250. end;
  1251. end;
  1252. var
  1253. _GetAllUsersProfileDirectoryA: Pointer;
  1254. function GetAllUsersProfileDirectoryA;
  1255. begin
  1256. GetProcedureAddress(_GetAllUsersProfileDirectoryA, userenvlib, 'GetAllUsersProfileDirectoryA');
  1257. asm
  1258. MOV ESP, EBP
  1259. POP EBP
  1260. JMP [_GetAllUsersProfileDirectoryA]
  1261. end;
  1262. end;
  1263. var
  1264. _GetAllUsersProfileDirectoryW: Pointer;
  1265. function GetAllUsersProfileDirectoryW;
  1266. begin
  1267. GetProcedureAddress(_GetAllUsersProfileDirectoryW, userenvlib, 'GetAllUsersProfileDirectoryW');
  1268. asm
  1269. MOV ESP, EBP
  1270. POP EBP
  1271. JMP [_GetAllUsersProfileDirectoryW]
  1272. end;
  1273. end;
  1274. var
  1275. _GetAllUsersProfileDirectory: Pointer;
  1276. function GetAllUsersProfileDirectory;
  1277. begin
  1278. GetProcedureAddress(_GetAllUsersProfileDirectory, userenvlib, 'GetAllUsersProfileDirectory' + AWSuffix);
  1279. asm
  1280. MOV ESP, EBP
  1281. POP EBP
  1282. JMP [_GetAllUsersProfileDirectory]
  1283. end;
  1284. end;
  1285. var
  1286. _GetUserProfileDirectoryA: Pointer;
  1287. function GetUserProfileDirectoryA;
  1288. begin
  1289. GetProcedureAddress(_GetUserProfileDirectoryA, userenvlib, 'GetUserProfileDirectoryA');
  1290. asm
  1291. MOV ESP, EBP
  1292. POP EBP
  1293. JMP [_GetUserProfileDirectoryA]
  1294. end;
  1295. end;
  1296. var
  1297. _GetUserProfileDirectoryW: Pointer;
  1298. function GetUserProfileDirectoryW;
  1299. begin
  1300. GetProcedureAddress(_GetUserProfileDirectoryW, userenvlib, 'GetUserProfileDirectoryW');
  1301. asm
  1302. MOV ESP, EBP
  1303. POP EBP
  1304. JMP [_GetUserProfileDirectoryW]
  1305. end;
  1306. end;
  1307. var
  1308. _GetUserProfileDirectory: Pointer;
  1309. function GetUserProfileDirectory;
  1310. begin
  1311. GetProcedureAddress(_GetUserProfileDirectory, userenvlib, 'GetUserProfileDirectory' + AWSuffix);
  1312. asm
  1313. MOV ESP, EBP
  1314. POP EBP
  1315. JMP [_GetUserProfileDirectory]
  1316. end;
  1317. end;
  1318. var
  1319. _CreateEnvironmentBlock: Pointer;
  1320. function CreateEnvironmentBlock;
  1321. begin
  1322. GetProcedureAddress(_CreateEnvironmentBlock, userenvlib, 'CreateEnvironmentBlock');
  1323. asm
  1324. MOV ESP, EBP
  1325. POP EBP
  1326. JMP [_CreateEnvironmentBlock]
  1327. end;
  1328. end;
  1329. var
  1330. _DestroyEnvironmentBlock: Pointer;
  1331. function DestroyEnvironmentBlock;
  1332. begin
  1333. GetProcedureAddress(_DestroyEnvironmentBlock, userenvlib, 'DestroyEnvironmentBlock');
  1334. asm
  1335. MOV ESP, EBP
  1336. POP EBP
  1337. JMP [_DestroyEnvironmentBlock]
  1338. end;
  1339. end;
  1340. var
  1341. _ExpandEnvStringsForUserA: Pointer;
  1342. function ExpandEnvironmentStringsForUserA;
  1343. begin
  1344. GetProcedureAddress(_ExpandEnvStringsForUserA, userenvlib, 'ExpandEnvironmentStringsForUserA');
  1345. asm
  1346. MOV ESP, EBP
  1347. POP EBP
  1348. JMP [_ExpandEnvStringsForUserA]
  1349. end;
  1350. end;
  1351. var
  1352. _ExpandEnvStringsForUserW: Pointer;
  1353. function ExpandEnvironmentStringsForUserW;
  1354. begin
  1355. GetProcedureAddress(_ExpandEnvStringsForUserW, userenvlib, 'ExpandEnvironmentStringsForUserW');
  1356. asm
  1357. MOV ESP, EBP
  1358. POP EBP
  1359. JMP [_ExpandEnvStringsForUserW]
  1360. end;
  1361. end;
  1362. var
  1363. _ExpandEnvironmentStringsForUser: Pointer;
  1364. function ExpandEnvironmentStringsForUser;
  1365. begin
  1366. GetProcedureAddress(_ExpandEnvironmentStringsForUser, userenvlib, 'ExpandEnvironmentStringsForUser' + AWSuffix);
  1367. asm
  1368. MOV ESP, EBP
  1369. POP EBP
  1370. JMP [_ExpandEnvironmentStringsForUser]
  1371. end;
  1372. end;
  1373. var
  1374. _RefreshPolicy: Pointer;
  1375. function RefreshPolicy;
  1376. begin
  1377. GetProcedureAddress(_RefreshPolicy, userenvlib, 'RefreshPolicy');
  1378. asm
  1379. MOV ESP, EBP
  1380. POP EBP
  1381. JMP [_RefreshPolicy]
  1382. end;
  1383. end;
  1384. var
  1385. _RefreshPolicyEx: Pointer;
  1386. function RefreshPolicyEx;
  1387. begin
  1388. GetProcedureAddress(_RefreshPolicyEx, userenvlib, 'RefreshPolicyEx');
  1389. asm
  1390. MOV ESP, EBP
  1391. POP EBP
  1392. JMP [_RefreshPolicyEx]
  1393. end;
  1394. end;
  1395. var
  1396. _EnterCriticalPolicySection: Pointer;
  1397. function EnterCriticalPolicySection;
  1398. begin
  1399. GetProcedureAddress(_EnterCriticalPolicySection, userenvlib, 'EnterCriticalPolicySection');
  1400. asm
  1401. MOV ESP, EBP
  1402. POP EBP
  1403. JMP [_EnterCriticalPolicySection]
  1404. end;
  1405. end;
  1406. var
  1407. _LeaveCriticalPolicySection: Pointer;
  1408. function LeaveCriticalPolicySection;
  1409. begin
  1410. GetProcedureAddress(_LeaveCriticalPolicySection, userenvlib, 'LeaveCriticalPolicySection');
  1411. asm
  1412. MOV ESP, EBP
  1413. POP EBP
  1414. JMP [_LeaveCriticalPolicySection]
  1415. end;
  1416. end;
  1417. var
  1418. _RegisterGPNotification: Pointer;
  1419. function RegisterGPNotification;
  1420. begin
  1421. GetProcedureAddress(_RegisterGPNotification, userenvlib, 'RegisterGPNotification');
  1422. asm
  1423. MOV ESP, EBP
  1424. POP EBP
  1425. JMP [_RegisterGPNotification]
  1426. end;
  1427. end;
  1428. var
  1429. _UnregisterGPNotification: Pointer;
  1430. function UnregisterGPNotification;
  1431. begin
  1432. GetProcedureAddress(_UnregisterGPNotification, userenvlib, 'UnregisterGPNotification');
  1433. asm
  1434. MOV ESP, EBP
  1435. POP EBP
  1436. JMP [_UnregisterGPNotification]
  1437. end;
  1438. end;
  1439. var
  1440. _GetGPOListA: Pointer;
  1441. function GetGPOListA;
  1442. begin
  1443. GetProcedureAddress(_GetGPOListA, userenvlib, 'GetGPOListA');
  1444. asm
  1445. MOV ESP, EBP
  1446. POP EBP
  1447. JMP [_GetGPOListA]
  1448. end;
  1449. end;
  1450. var
  1451. _GetGPOListW: Pointer;
  1452. function GetGPOListW;
  1453. begin
  1454. GetProcedureAddress(_GetGPOListW, userenvlib, 'GetGPOListW');
  1455. asm
  1456. MOV ESP, EBP
  1457. POP EBP
  1458. JMP [_GetGPOListW]
  1459. end;
  1460. end;
  1461. var
  1462. _GetGPOList: Pointer;
  1463. function GetGPOList;
  1464. begin
  1465. GetProcedureAddress(_GetGPOList, userenvlib, 'GetGPOList' + AWSuffix);
  1466. asm
  1467. MOV ESP, EBP
  1468. POP EBP
  1469. JMP [_GetGPOList]
  1470. end;
  1471. end;
  1472. var
  1473. _FreeGPOListA: Pointer;
  1474. function FreeGPOListA;
  1475. begin
  1476. GetProcedureAddress(_FreeGPOListA, userenvlib, 'FreeGPOListA');
  1477. asm
  1478. MOV ESP, EBP
  1479. POP EBP
  1480. JMP [_FreeGPOListA]
  1481. end;
  1482. end;
  1483. var
  1484. _FreeGPOListW: Pointer;
  1485. function FreeGPOListW;
  1486. begin
  1487. GetProcedureAddress(_FreeGPOListW, userenvlib, 'FreeGPOListW');
  1488. asm
  1489. MOV ESP, EBP
  1490. POP EBP
  1491. JMP [_FreeGPOListW]
  1492. end;
  1493. end;
  1494. var
  1495. _FreeGPOList: Pointer;
  1496. function FreeGPOList;
  1497. begin
  1498. GetProcedureAddress(_FreeGPOList, userenvlib, 'FreeGPOList' + AWSuffix);
  1499. asm
  1500. MOV ESP, EBP
  1501. POP EBP
  1502. JMP [_FreeGPOList]
  1503. end;
  1504. end;
  1505. var
  1506. _GetAppliedGPOListA: Pointer;
  1507. function GetAppliedGPOListA;
  1508. begin
  1509. GetProcedureAddress(_GetAppliedGPOListA, userenvlib, 'GetAppliedGPOListA');
  1510. asm
  1511. MOV ESP, EBP
  1512. POP EBP
  1513. JMP [_GetAppliedGPOListA]
  1514. end;
  1515. end;
  1516. var
  1517. _GetAppliedGPOListW: Pointer;
  1518. function GetAppliedGPOListW;
  1519. begin
  1520. GetProcedureAddress(_GetAppliedGPOListW, userenvlib, 'GetAppliedGPOListW');
  1521. asm
  1522. MOV ESP, EBP
  1523. POP EBP
  1524. JMP [_GetAppliedGPOListW]
  1525. end;
  1526. end;
  1527. var
  1528. _GetAppliedGPOList: Pointer;
  1529. function GetAppliedGPOList;
  1530. begin
  1531. GetProcedureAddress(_GetAppliedGPOList, userenvlib, 'GetAppliedGPOList' + AWSuffix);
  1532. asm
  1533. MOV ESP, EBP
  1534. POP EBP
  1535. JMP [_GetAppliedGPOList]
  1536. end;
  1537. end;
  1538. var
  1539. _ProcessGroupPolicyCompleted: Pointer;
  1540. function ProcessGroupPolicyCompleted;
  1541. begin
  1542. GetProcedureAddress(_ProcessGroupPolicyCompleted, userenvlib, 'ProcessGroupPolicyCompleted');
  1543. asm
  1544. MOV ESP, EBP
  1545. POP EBP
  1546. JMP [_ProcessGroupPolicyCompleted]
  1547. end;
  1548. end;
  1549. var
  1550. _ProcessGroupPolicyCompletedEx: Pointer;
  1551. function ProcessGroupPolicyCompletedEx;
  1552. begin
  1553. GetProcedureAddress(_ProcessGroupPolicyCompletedEx, userenvlib, 'ProcessGroupPolicyCompletedEx');
  1554. asm
  1555. MOV ESP, EBP
  1556. POP EBP
  1557. JMP [_ProcessGroupPolicyCompletedEx]
  1558. end;
  1559. end;
  1560. var
  1561. _RsopAccessCheckByType: Pointer;
  1562. function RsopAccessCheckByType;
  1563. begin
  1564. GetProcedureAddress(_RsopAccessCheckByType, userenvlib, 'RsopAccessCheckByType');
  1565. asm
  1566. MOV ESP, EBP
  1567. POP EBP
  1568. JMP [_RsopAccessCheckByType]
  1569. end;
  1570. end;
  1571. var
  1572. _RsopFileAccessCheck: Pointer;
  1573. function RsopFileAccessCheck;
  1574. begin
  1575. GetProcedureAddress(_RsopFileAccessCheck, userenvlib, 'RsopFileAccessCheck');
  1576. asm
  1577. MOV ESP, EBP
  1578. POP EBP
  1579. JMP [_RsopFileAccessCheck]
  1580. end;
  1581. end;
  1582. var
  1583. _RsopSetPolicySettingStatus: Pointer;
  1584. function RsopSetPolicySettingStatus;
  1585. begin
  1586. GetProcedureAddress(_RsopSetPolicySettingStatus, userenvlib, 'RsopSetPolicySettingStatus');
  1587. asm
  1588. MOV ESP, EBP
  1589. POP EBP
  1590. JMP [_RsopSetPolicySettingStatus]
  1591. end;
  1592. end;
  1593. var
  1594. _RsopResetPolicySettingStatus: Pointer;
  1595. function RsopResetPolicySettingStatus;
  1596. begin
  1597. GetProcedureAddress(_RsopResetPolicySettingStatus, userenvlib, 'RsopResetPolicySettingStatus');
  1598. asm
  1599. MOV ESP, EBP
  1600. POP EBP
  1601. JMP [_RsopResetPolicySettingStatus]
  1602. end;
  1603. end;
  1604. {$ELSE}
  1605. function LoadUserProfileA; external userenvlib name 'LoadUserProfileA';
  1606. function LoadUserProfileW; external userenvlib name 'LoadUserProfileW';
  1607. function LoadUserProfile; external userenvlib name 'LoadUserProfile' + AWSuffix;
  1608. function UnloadUserProfile; external userenvlib name 'UnloadUserProfile';
  1609. function GetProfilesDirectoryA; external userenvlib name 'GetProfilesDirectoryA';
  1610. function GetProfilesDirectoryW; external userenvlib name 'GetProfilesDirectoryW';
  1611. function GetProfilesDirectory; external userenvlib name 'GetProfilesDirectory' + AWSuffix;
  1612. function GetProfileType; external userenvlib name 'GetProfileType';
  1613. function DeleteProfileA; external userenvlib name 'DeleteProfileA';
  1614. function DeleteProfileW; external userenvlib name 'DeleteProfileW';
  1615. function DeleteProfile; external userenvlib name 'DeleteProfile' + AWSuffix;
  1616. function GetDefaultUserProfileDirectoryA; external userenvlib name 'GetDefaultUserProfileDirectoryA';
  1617. function GetDefaultUserProfileDirectoryW; external userenvlib name 'GetDefaultUserProfileDirectoryW';
  1618. function GetDefaultUserProfileDirectory; external userenvlib name 'GetDefaultUserProfileDirectory' + AWSuffix;
  1619. function GetAllUsersProfileDirectoryA; external userenvlib name 'GetAllUsersProfileDirectoryA';
  1620. function GetAllUsersProfileDirectoryW; external userenvlib name 'GetAllUsersProfileDirectoryW';
  1621. function GetAllUsersProfileDirectory; external userenvlib name 'GetAllUsersProfileDirectory' + AWSuffix;
  1622. function GetUserProfileDirectoryA; external userenvlib name 'GetUserProfileDirectoryA';
  1623. function GetUserProfileDirectoryW; external userenvlib name 'GetUserProfileDirectoryW';
  1624. function GetUserProfileDirectory; external userenvlib name 'GetUserProfileDirectory' + AWSuffix;
  1625. function CreateEnvironmentBlock; external userenvlib name 'CreateEnvironmentBlock';
  1626. function DestroyEnvironmentBlock; external userenvlib name 'DestroyEnvironmentBlock';
  1627. function ExpandEnvironmentStringsForUserA; external userenvlib name 'ExpandEnvironmentStringsForUserA';
  1628. function ExpandEnvironmentStringsForUserW; external userenvlib name 'ExpandEnvironmentStringsForUserW';
  1629. function ExpandEnvironmentStringsForUser; external userenvlib name 'ExpandEnvironmentStringsForUser' + AWSuffix;
  1630. function RefreshPolicy; external userenvlib name 'RefreshPolicy';
  1631. function RefreshPolicyEx; external userenvlib name 'RefreshPolicyEx';
  1632. function EnterCriticalPolicySection; external userenvlib name 'EnterCriticalPolicySection';
  1633. function LeaveCriticalPolicySection; external userenvlib name 'LeaveCriticalPolicySection';
  1634. function RegisterGPNotification; external userenvlib name 'RegisterGPNotification';
  1635. function UnregisterGPNotification; external userenvlib name 'UnregisterGPNotification';
  1636. function GetGPOListA; external userenvlib name 'GetGPOListA';
  1637. function GetGPOListW; external userenvlib name 'GetGPOListW';
  1638. function GetGPOList; external userenvlib name 'GetGPOList' + AWSuffix;
  1639. function FreeGPOListA; external userenvlib name 'FreeGPOListA';
  1640. function FreeGPOListW; external userenvlib name 'FreeGPOListW';
  1641. function FreeGPOList; external userenvlib name 'FreeGPOList' + AWSuffix;
  1642. function GetAppliedGPOListA; external userenvlib name 'GetAppliedGPOListA';
  1643. function GetAppliedGPOListW; external userenvlib name 'GetAppliedGPOListW';
  1644. function GetAppliedGPOList; external userenvlib name 'GetAppliedGPOList' + AWSuffix;
  1645. function ProcessGroupPolicyCompleted; external userenvlib name 'ProcessGroupPolicyCompleted';
  1646. function ProcessGroupPolicyCompletedEx; external userenvlib name 'ProcessGroupPolicyCompletedEx';
  1647. function RsopAccessCheckByType; external userenvlib name 'RsopAccessCheckByType';
  1648. function RsopFileAccessCheck; external userenvlib name 'RsopFileAccessCheck';
  1649. function RsopSetPolicySettingStatus; external userenvlib name 'RsopSetPolicySettingStatus';
  1650. function RsopResetPolicySettingStatus; external userenvlib name 'RsopResetPolicySettingStatus';
  1651. {$ENDIF DYNAMIC_LINK}
  1652. end.