jwauserenv.pas 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865
  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. unit JwaUserEnv;
  43. {$WEAKPACKAGEUNIT}
  44. {$HPPEMIT ''}
  45. {$HPPEMIT '#include "userenv.h"'}
  46. {$HPPEMIT ''}
  47. {$HPPEMIT 'typedef PGROUP_POLICY_OBJECTA *PPGROUP_POLICY_OBJECTA'}
  48. {$HPPEMIT 'typedef PGROUP_POLICY_OBJECTW *PPGROUP_POLICY_OBJECTW'}
  49. {$HPPEMIT ''}
  50. {$HPPEMIT 'typedef #ifdef UNICODE'}
  51. {$HPPEMIT 'typedef PPGROUP_POLICY_OBJECTW PPGROUP_POLICY_OBJECT'}
  52. {$HPPEMIT 'typedef #else'}
  53. {$HPPEMIT 'typedef PPGROUP_POLICY_OBJECTA PPGROUP_POLICY_OBJECT'}
  54. {$HPPEMIT 'typedef #endif'}
  55. {$HPPEMIT ''}
  56. {$I jediapilib.inc}
  57. interface
  58. uses
  59. ActiveX, {TODO}
  60. JwaProfInfo, JwaWbemCli, JwaWinType, JWaWinBase, JwaWinNT;
  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. const
  1096. userenvlib = 'userenv.dll';
  1097. {$IFDEF UNICODE}
  1098. AWSuffix = 'W';
  1099. {$ELSE}
  1100. AWSuffix = 'A';
  1101. {$ENDIF UNICODE}
  1102. {$IFDEF DYNAMIC_LINK}
  1103. var
  1104. _LoadUserProfileA: Pointer;
  1105. function LoadUserProfileA;
  1106. begin
  1107. GetProcedureAddress(_LoadUserProfileA, userenvlib, 'LoadUserProfileA');
  1108. asm
  1109. MOV ESP, EBP
  1110. POP EBP
  1111. JMP [_LoadUserProfileA]
  1112. end;
  1113. end;
  1114. var
  1115. _LoadUserProfileW: Pointer;
  1116. function LoadUserProfileW;
  1117. begin
  1118. GetProcedureAddress(_LoadUserProfileW, userenvlib, 'LoadUserProfileW');
  1119. asm
  1120. MOV ESP, EBP
  1121. POP EBP
  1122. JMP [_LoadUserProfileW]
  1123. end;
  1124. end;
  1125. var
  1126. _LoadUserProfile: Pointer;
  1127. function LoadUserProfile;
  1128. begin
  1129. GetProcedureAddress(_LoadUserProfile, userenvlib, 'LoadUserProfile' + AWSuffix);
  1130. asm
  1131. MOV ESP, EBP
  1132. POP EBP
  1133. JMP [_LoadUserProfile]
  1134. end;
  1135. end;
  1136. var
  1137. _UnloadUserProfile: Pointer;
  1138. function UnloadUserProfile;
  1139. begin
  1140. GetProcedureAddress(_UnloadUserProfile, userenvlib, 'UnloadUserProfile');
  1141. asm
  1142. MOV ESP, EBP
  1143. POP EBP
  1144. JMP [_UnloadUserProfile]
  1145. end;
  1146. end;
  1147. var
  1148. _GetProfilesDirectoryA: Pointer;
  1149. function GetProfilesDirectoryA;
  1150. begin
  1151. GetProcedureAddress(_GetProfilesDirectoryA, userenvlib, 'GetProfilesDirectoryA');
  1152. asm
  1153. MOV ESP, EBP
  1154. POP EBP
  1155. JMP [_GetProfilesDirectoryA]
  1156. end;
  1157. end;
  1158. var
  1159. _GetProfilesDirectoryW: Pointer;
  1160. function GetProfilesDirectoryW;
  1161. begin
  1162. GetProcedureAddress(_GetProfilesDirectoryW, userenvlib, 'GetProfilesDirectoryW');
  1163. asm
  1164. MOV ESP, EBP
  1165. POP EBP
  1166. JMP [_GetProfilesDirectoryW]
  1167. end;
  1168. end;
  1169. var
  1170. _GetProfilesDirectory: Pointer;
  1171. function GetProfilesDirectory;
  1172. begin
  1173. GetProcedureAddress(_GetProfilesDirectory, userenvlib, 'GetProfilesDirectory' + AWSuffix);
  1174. asm
  1175. MOV ESP, EBP
  1176. POP EBP
  1177. JMP [_GetProfilesDirectory]
  1178. end;
  1179. end;
  1180. var
  1181. _GetProfileType: Pointer;
  1182. function GetProfileType;
  1183. begin
  1184. GetProcedureAddress(_GetProfileType, userenvlib, 'GetProfileType');
  1185. asm
  1186. MOV ESP, EBP
  1187. POP EBP
  1188. JMP [_GetProfileType]
  1189. end;
  1190. end;
  1191. var
  1192. _DeleteProfileA: Pointer;
  1193. function DeleteProfileA;
  1194. begin
  1195. GetProcedureAddress(_DeleteProfileA, userenvlib, 'DeleteProfileA');
  1196. asm
  1197. MOV ESP, EBP
  1198. POP EBP
  1199. JMP [_DeleteProfileA]
  1200. end;
  1201. end;
  1202. var
  1203. _DeleteProfileW: Pointer;
  1204. function DeleteProfileW;
  1205. begin
  1206. GetProcedureAddress(_DeleteProfileW, userenvlib, 'DeleteProfileW');
  1207. asm
  1208. MOV ESP, EBP
  1209. POP EBP
  1210. JMP [_DeleteProfileW]
  1211. end;
  1212. end;
  1213. var
  1214. _DeleteProfile: Pointer;
  1215. function DeleteProfile;
  1216. begin
  1217. GetProcedureAddress(_DeleteProfile, userenvlib, 'DeleteProfile' + AWSuffix);
  1218. asm
  1219. MOV ESP, EBP
  1220. POP EBP
  1221. JMP [_DeleteProfile]
  1222. end;
  1223. end;
  1224. var
  1225. _GetDefaultUserProfileDirectoryA: Pointer;
  1226. function GetDefaultUserProfileDirectoryA;
  1227. begin
  1228. GetProcedureAddress(_GetDefaultUserProfileDirectoryA, userenvlib, 'GetDefaultUserProfileDirectoryA');
  1229. asm
  1230. MOV ESP, EBP
  1231. POP EBP
  1232. JMP [_GetDefaultUserProfileDirectoryA]
  1233. end;
  1234. end;
  1235. var
  1236. _GetDefaultUserProfileDirectoryW: Pointer;
  1237. function GetDefaultUserProfileDirectoryW;
  1238. begin
  1239. GetProcedureAddress(_GetDefaultUserProfileDirectoryW, userenvlib, 'GetDefaultUserProfileDirectoryW');
  1240. asm
  1241. MOV ESP, EBP
  1242. POP EBP
  1243. JMP [_GetDefaultUserProfileDirectoryW]
  1244. end;
  1245. end;
  1246. var
  1247. _GetDefaultUserProfileDirectory: Pointer;
  1248. function GetDefaultUserProfileDirectory;
  1249. begin
  1250. GetProcedureAddress(_GetDefaultUserProfileDirectory, userenvlib, 'GetDefaultUserProfileDirectory' + AWSuffix);
  1251. asm
  1252. MOV ESP, EBP
  1253. POP EBP
  1254. JMP [_GetDefaultUserProfileDirectory]
  1255. end;
  1256. end;
  1257. var
  1258. _GetAllUsersProfileDirectoryA: Pointer;
  1259. function GetAllUsersProfileDirectoryA;
  1260. begin
  1261. GetProcedureAddress(_GetAllUsersProfileDirectoryA, userenvlib, 'GetAllUsersProfileDirectoryA');
  1262. asm
  1263. MOV ESP, EBP
  1264. POP EBP
  1265. JMP [_GetAllUsersProfileDirectoryA]
  1266. end;
  1267. end;
  1268. var
  1269. _GetAllUsersProfileDirectoryW: Pointer;
  1270. function GetAllUsersProfileDirectoryW;
  1271. begin
  1272. GetProcedureAddress(_GetAllUsersProfileDirectoryW, userenvlib, 'GetAllUsersProfileDirectoryW');
  1273. asm
  1274. MOV ESP, EBP
  1275. POP EBP
  1276. JMP [_GetAllUsersProfileDirectoryW]
  1277. end;
  1278. end;
  1279. var
  1280. _GetAllUsersProfileDirectory: Pointer;
  1281. function GetAllUsersProfileDirectory;
  1282. begin
  1283. GetProcedureAddress(_GetAllUsersProfileDirectory, userenvlib, 'GetAllUsersProfileDirectory' + AWSuffix);
  1284. asm
  1285. MOV ESP, EBP
  1286. POP EBP
  1287. JMP [_GetAllUsersProfileDirectory]
  1288. end;
  1289. end;
  1290. var
  1291. _GetUserProfileDirectoryA: Pointer;
  1292. function GetUserProfileDirectoryA;
  1293. begin
  1294. GetProcedureAddress(_GetUserProfileDirectoryA, userenvlib, 'GetUserProfileDirectoryA');
  1295. asm
  1296. MOV ESP, EBP
  1297. POP EBP
  1298. JMP [_GetUserProfileDirectoryA]
  1299. end;
  1300. end;
  1301. var
  1302. _GetUserProfileDirectoryW: Pointer;
  1303. function GetUserProfileDirectoryW;
  1304. begin
  1305. GetProcedureAddress(_GetUserProfileDirectoryW, userenvlib, 'GetUserProfileDirectoryW');
  1306. asm
  1307. MOV ESP, EBP
  1308. POP EBP
  1309. JMP [_GetUserProfileDirectoryW]
  1310. end;
  1311. end;
  1312. var
  1313. _GetUserProfileDirectory: Pointer;
  1314. function GetUserProfileDirectory;
  1315. begin
  1316. GetProcedureAddress(_GetUserProfileDirectory, userenvlib, 'GetUserProfileDirectory' + AWSuffix);
  1317. asm
  1318. MOV ESP, EBP
  1319. POP EBP
  1320. JMP [_GetUserProfileDirectory]
  1321. end;
  1322. end;
  1323. var
  1324. _CreateEnvironmentBlock: Pointer;
  1325. function CreateEnvironmentBlock;
  1326. begin
  1327. GetProcedureAddress(_CreateEnvironmentBlock, userenvlib, 'CreateEnvironmentBlock');
  1328. asm
  1329. MOV ESP, EBP
  1330. POP EBP
  1331. JMP [_CreateEnvironmentBlock]
  1332. end;
  1333. end;
  1334. var
  1335. _DestroyEnvironmentBlock: Pointer;
  1336. function DestroyEnvironmentBlock;
  1337. begin
  1338. GetProcedureAddress(_DestroyEnvironmentBlock, userenvlib, 'DestroyEnvironmentBlock');
  1339. asm
  1340. MOV ESP, EBP
  1341. POP EBP
  1342. JMP [_DestroyEnvironmentBlock]
  1343. end;
  1344. end;
  1345. var
  1346. _ExpandEnvStringsForUserA: Pointer;
  1347. function ExpandEnvironmentStringsForUserA;
  1348. begin
  1349. GetProcedureAddress(_ExpandEnvStringsForUserA, userenvlib, 'ExpandEnvironmentStringsForUserA');
  1350. asm
  1351. MOV ESP, EBP
  1352. POP EBP
  1353. JMP [_ExpandEnvStringsForUserA]
  1354. end;
  1355. end;
  1356. var
  1357. _ExpandEnvStringsForUserW: Pointer;
  1358. function ExpandEnvironmentStringsForUserW;
  1359. begin
  1360. GetProcedureAddress(_ExpandEnvStringsForUserW, userenvlib, 'ExpandEnvironmentStringsForUserW');
  1361. asm
  1362. MOV ESP, EBP
  1363. POP EBP
  1364. JMP [_ExpandEnvStringsForUserW]
  1365. end;
  1366. end;
  1367. var
  1368. _ExpandEnvironmentStringsForUser: Pointer;
  1369. function ExpandEnvironmentStringsForUser;
  1370. begin
  1371. GetProcedureAddress(_ExpandEnvironmentStringsForUser, userenvlib, 'ExpandEnvironmentStringsForUser' + AWSuffix);
  1372. asm
  1373. MOV ESP, EBP
  1374. POP EBP
  1375. JMP [_ExpandEnvironmentStringsForUser]
  1376. end;
  1377. end;
  1378. var
  1379. _RefreshPolicy: Pointer;
  1380. function RefreshPolicy;
  1381. begin
  1382. GetProcedureAddress(_RefreshPolicy, userenvlib, 'RefreshPolicy');
  1383. asm
  1384. MOV ESP, EBP
  1385. POP EBP
  1386. JMP [_RefreshPolicy]
  1387. end;
  1388. end;
  1389. var
  1390. _RefreshPolicyEx: Pointer;
  1391. function RefreshPolicyEx;
  1392. begin
  1393. GetProcedureAddress(_RefreshPolicyEx, userenvlib, 'RefreshPolicyEx');
  1394. asm
  1395. MOV ESP, EBP
  1396. POP EBP
  1397. JMP [_RefreshPolicyEx]
  1398. end;
  1399. end;
  1400. var
  1401. _EnterCriticalPolicySection: Pointer;
  1402. function EnterCriticalPolicySection;
  1403. begin
  1404. GetProcedureAddress(_EnterCriticalPolicySection, userenvlib, 'EnterCriticalPolicySection');
  1405. asm
  1406. MOV ESP, EBP
  1407. POP EBP
  1408. JMP [_EnterCriticalPolicySection]
  1409. end;
  1410. end;
  1411. var
  1412. _LeaveCriticalPolicySection: Pointer;
  1413. function LeaveCriticalPolicySection;
  1414. begin
  1415. GetProcedureAddress(_LeaveCriticalPolicySection, userenvlib, 'LeaveCriticalPolicySection');
  1416. asm
  1417. MOV ESP, EBP
  1418. POP EBP
  1419. JMP [_LeaveCriticalPolicySection]
  1420. end;
  1421. end;
  1422. var
  1423. _RegisterGPNotification: Pointer;
  1424. function RegisterGPNotification;
  1425. begin
  1426. GetProcedureAddress(_RegisterGPNotification, userenvlib, 'RegisterGPNotification');
  1427. asm
  1428. MOV ESP, EBP
  1429. POP EBP
  1430. JMP [_RegisterGPNotification]
  1431. end;
  1432. end;
  1433. var
  1434. _UnregisterGPNotification: Pointer;
  1435. function UnregisterGPNotification;
  1436. begin
  1437. GetProcedureAddress(_UnregisterGPNotification, userenvlib, 'UnregisterGPNotification');
  1438. asm
  1439. MOV ESP, EBP
  1440. POP EBP
  1441. JMP [_UnregisterGPNotification]
  1442. end;
  1443. end;
  1444. var
  1445. _GetGPOListA: Pointer;
  1446. function GetGPOListA;
  1447. begin
  1448. GetProcedureAddress(_GetGPOListA, userenvlib, 'GetGPOListA');
  1449. asm
  1450. MOV ESP, EBP
  1451. POP EBP
  1452. JMP [_GetGPOListA]
  1453. end;
  1454. end;
  1455. var
  1456. _GetGPOListW: Pointer;
  1457. function GetGPOListW;
  1458. begin
  1459. GetProcedureAddress(_GetGPOListW, userenvlib, 'GetGPOListW');
  1460. asm
  1461. MOV ESP, EBP
  1462. POP EBP
  1463. JMP [_GetGPOListW]
  1464. end;
  1465. end;
  1466. var
  1467. _GetGPOList: Pointer;
  1468. function GetGPOList;
  1469. begin
  1470. GetProcedureAddress(_GetGPOList, userenvlib, 'GetGPOList' + AWSuffix);
  1471. asm
  1472. MOV ESP, EBP
  1473. POP EBP
  1474. JMP [_GetGPOList]
  1475. end;
  1476. end;
  1477. var
  1478. _FreeGPOListA: Pointer;
  1479. function FreeGPOListA;
  1480. begin
  1481. GetProcedureAddress(_FreeGPOListA, userenvlib, 'FreeGPOListA');
  1482. asm
  1483. MOV ESP, EBP
  1484. POP EBP
  1485. JMP [_FreeGPOListA]
  1486. end;
  1487. end;
  1488. var
  1489. _FreeGPOListW: Pointer;
  1490. function FreeGPOListW;
  1491. begin
  1492. GetProcedureAddress(_FreeGPOListW, userenvlib, 'FreeGPOListW');
  1493. asm
  1494. MOV ESP, EBP
  1495. POP EBP
  1496. JMP [_FreeGPOListW]
  1497. end;
  1498. end;
  1499. var
  1500. _FreeGPOList: Pointer;
  1501. function FreeGPOList;
  1502. begin
  1503. GetProcedureAddress(_FreeGPOList, userenvlib, 'FreeGPOList' + AWSuffix);
  1504. asm
  1505. MOV ESP, EBP
  1506. POP EBP
  1507. JMP [_FreeGPOList]
  1508. end;
  1509. end;
  1510. var
  1511. _GetAppliedGPOListA: Pointer;
  1512. function GetAppliedGPOListA;
  1513. begin
  1514. GetProcedureAddress(_GetAppliedGPOListA, userenvlib, 'GetAppliedGPOListA');
  1515. asm
  1516. MOV ESP, EBP
  1517. POP EBP
  1518. JMP [_GetAppliedGPOListA]
  1519. end;
  1520. end;
  1521. var
  1522. _GetAppliedGPOListW: Pointer;
  1523. function GetAppliedGPOListW;
  1524. begin
  1525. GetProcedureAddress(_GetAppliedGPOListW, userenvlib, 'GetAppliedGPOListW');
  1526. asm
  1527. MOV ESP, EBP
  1528. POP EBP
  1529. JMP [_GetAppliedGPOListW]
  1530. end;
  1531. end;
  1532. var
  1533. _GetAppliedGPOList: Pointer;
  1534. function GetAppliedGPOList;
  1535. begin
  1536. GetProcedureAddress(_GetAppliedGPOList, userenvlib, 'GetAppliedGPOList' + AWSuffix);
  1537. asm
  1538. MOV ESP, EBP
  1539. POP EBP
  1540. JMP [_GetAppliedGPOList]
  1541. end;
  1542. end;
  1543. var
  1544. _ProcessGroupPolicyCompleted: Pointer;
  1545. function ProcessGroupPolicyCompleted;
  1546. begin
  1547. GetProcedureAddress(_ProcessGroupPolicyCompleted, userenvlib, 'ProcessGroupPolicyCompleted');
  1548. asm
  1549. MOV ESP, EBP
  1550. POP EBP
  1551. JMP [_ProcessGroupPolicyCompleted]
  1552. end;
  1553. end;
  1554. var
  1555. _ProcessGroupPolicyCompletedEx: Pointer;
  1556. function ProcessGroupPolicyCompletedEx;
  1557. begin
  1558. GetProcedureAddress(_ProcessGroupPolicyCompletedEx, userenvlib, 'ProcessGroupPolicyCompletedEx');
  1559. asm
  1560. MOV ESP, EBP
  1561. POP EBP
  1562. JMP [_ProcessGroupPolicyCompletedEx]
  1563. end;
  1564. end;
  1565. var
  1566. _RsopAccessCheckByType: Pointer;
  1567. function RsopAccessCheckByType;
  1568. begin
  1569. GetProcedureAddress(_RsopAccessCheckByType, userenvlib, 'RsopAccessCheckByType');
  1570. asm
  1571. MOV ESP, EBP
  1572. POP EBP
  1573. JMP [_RsopAccessCheckByType]
  1574. end;
  1575. end;
  1576. var
  1577. _RsopFileAccessCheck: Pointer;
  1578. function RsopFileAccessCheck;
  1579. begin
  1580. GetProcedureAddress(_RsopFileAccessCheck, userenvlib, 'RsopFileAccessCheck');
  1581. asm
  1582. MOV ESP, EBP
  1583. POP EBP
  1584. JMP [_RsopFileAccessCheck]
  1585. end;
  1586. end;
  1587. var
  1588. _RsopSetPolicySettingStatus: Pointer;
  1589. function RsopSetPolicySettingStatus;
  1590. begin
  1591. GetProcedureAddress(_RsopSetPolicySettingStatus, userenvlib, 'RsopSetPolicySettingStatus');
  1592. asm
  1593. MOV ESP, EBP
  1594. POP EBP
  1595. JMP [_RsopSetPolicySettingStatus]
  1596. end;
  1597. end;
  1598. var
  1599. _RsopResetPolicySettingStatus: Pointer;
  1600. function RsopResetPolicySettingStatus;
  1601. begin
  1602. GetProcedureAddress(_RsopResetPolicySettingStatus, userenvlib, 'RsopResetPolicySettingStatus');
  1603. asm
  1604. MOV ESP, EBP
  1605. POP EBP
  1606. JMP [_RsopResetPolicySettingStatus]
  1607. end;
  1608. end;
  1609. {$ELSE}
  1610. function LoadUserProfileA; external userenvlib name 'LoadUserProfileA';
  1611. function LoadUserProfileW; external userenvlib name 'LoadUserProfileW';
  1612. function LoadUserProfile; external userenvlib name 'LoadUserProfile' + AWSuffix;
  1613. function UnloadUserProfile; external userenvlib name 'UnloadUserProfile';
  1614. function GetProfilesDirectoryA; external userenvlib name 'GetProfilesDirectoryA';
  1615. function GetProfilesDirectoryW; external userenvlib name 'GetProfilesDirectoryW';
  1616. function GetProfilesDirectory; external userenvlib name 'GetProfilesDirectory' + AWSuffix;
  1617. function GetProfileType; external userenvlib name 'GetProfileType';
  1618. function DeleteProfileA; external userenvlib name 'DeleteProfileA';
  1619. function DeleteProfileW; external userenvlib name 'DeleteProfileW';
  1620. function DeleteProfile; external userenvlib name 'DeleteProfile' + AWSuffix;
  1621. function GetDefaultUserProfileDirectoryA; external userenvlib name 'GetDefaultUserProfileDirectoryA';
  1622. function GetDefaultUserProfileDirectoryW; external userenvlib name 'GetDefaultUserProfileDirectoryW';
  1623. function GetDefaultUserProfileDirectory; external userenvlib name 'GetDefaultUserProfileDirectory' + AWSuffix;
  1624. function GetAllUsersProfileDirectoryA; external userenvlib name 'GetAllUsersProfileDirectoryA';
  1625. function GetAllUsersProfileDirectoryW; external userenvlib name 'GetAllUsersProfileDirectoryW';
  1626. function GetAllUsersProfileDirectory; external userenvlib name 'GetAllUsersProfileDirectory' + AWSuffix;
  1627. function GetUserProfileDirectoryA; external userenvlib name 'GetUserProfileDirectoryA';
  1628. function GetUserProfileDirectoryW; external userenvlib name 'GetUserProfileDirectoryW';
  1629. function GetUserProfileDirectory; external userenvlib name 'GetUserProfileDirectory' + AWSuffix;
  1630. function CreateEnvironmentBlock; external userenvlib name 'CreateEnvironmentBlock';
  1631. function DestroyEnvironmentBlock; external userenvlib name 'DestroyEnvironmentBlock';
  1632. function ExpandEnvironmentStringsForUserA; external userenvlib name 'ExpandEnvironmentStringsForUserA';
  1633. function ExpandEnvironmentStringsForUserW; external userenvlib name 'ExpandEnvironmentStringsForUserW';
  1634. function ExpandEnvironmentStringsForUser; external userenvlib name 'ExpandEnvironmentStringsForUser' + AWSuffix;
  1635. function RefreshPolicy; external userenvlib name 'RefreshPolicy';
  1636. function RefreshPolicyEx; external userenvlib name 'RefreshPolicyEx';
  1637. function EnterCriticalPolicySection; external userenvlib name 'EnterCriticalPolicySection';
  1638. function LeaveCriticalPolicySection; external userenvlib name 'LeaveCriticalPolicySection';
  1639. function RegisterGPNotification; external userenvlib name 'RegisterGPNotification';
  1640. function UnregisterGPNotification; external userenvlib name 'UnregisterGPNotification';
  1641. function GetGPOListA; external userenvlib name 'GetGPOListA';
  1642. function GetGPOListW; external userenvlib name 'GetGPOListW';
  1643. function GetGPOList; external userenvlib name 'GetGPOList' + AWSuffix;
  1644. function FreeGPOListA; external userenvlib name 'FreeGPOListA';
  1645. function FreeGPOListW; external userenvlib name 'FreeGPOListW';
  1646. function FreeGPOList; external userenvlib name 'FreeGPOList' + AWSuffix;
  1647. function GetAppliedGPOListA; external userenvlib name 'GetAppliedGPOListA';
  1648. function GetAppliedGPOListW; external userenvlib name 'GetAppliedGPOListW';
  1649. function GetAppliedGPOList; external userenvlib name 'GetAppliedGPOList' + AWSuffix;
  1650. function ProcessGroupPolicyCompleted; external userenvlib name 'ProcessGroupPolicyCompleted';
  1651. function ProcessGroupPolicyCompletedEx; external userenvlib name 'ProcessGroupPolicyCompletedEx';
  1652. function RsopAccessCheckByType; external userenvlib name 'RsopAccessCheckByType';
  1653. function RsopFileAccessCheck; external userenvlib name 'RsopFileAccessCheck';
  1654. function RsopSetPolicySettingStatus; external userenvlib name 'RsopSetPolicySettingStatus';
  1655. function RsopResetPolicySettingStatus; external userenvlib name 'RsopResetPolicySettingStatus';
  1656. {$ENDIF DYNAMIC_LINK}
  1657. end.