-
Notifications
You must be signed in to change notification settings - Fork 322
/
UserEnv.h
executable file
·1557 lines (1371 loc) · 58.7 KB
/
UserEnv.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//=============================================================================
// userenv.h - Header file for user environment API.
// User Profiles, environment variables, and Group Policy
//
// Copyright (c) Microsoft Corporation 1995-2002
// All rights reserved
//
//=============================================================================
#ifndef _INC_USERENV
#define _INC_USERENV
#include <winapifamily.h>
#pragma region Desktop Family or OneCore Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM)
#include <wbemcli.h>
//
// Define API decoration for direct importing of DLL references.
//
#if !defined(_USERENV_)
#define USERENVAPI DECLSPEC_IMPORT
#else
#define USERENVAPI
#endif
#ifdef __cplusplus
extern "C" {
#endif
//=============================================================================
//
// LoadUserProfile
//
// Loads the specified user's profile.
//
// Most applications should not need to use this function. It's used
// when a user has logged onto the system or a service starts in a named
// user account.
//
// hToken - Token for the user, returned from LogonUser()
// lpProfileInfo - Address of a PROFILEINFO structure
//
// Returns: TRUE if successful
// FALSE if not. Call GetLastError() for more details
//
// Note: The caller of this function must have admin privileges on the machine.
//
// Upon successful return, the hProfile member of the PROFILEINFO
// structure is a registry key handle opened to the root
// of the user's hive. It has been opened with full access. If
// you need to read or write to the user's registry file, use
// this key instead of HKEY_CURRENT_USER. Do not close this
// handle. Instead pass it to UnloadUserProfile to close
// the handle.
//
//=============================================================================
#include <profinfo.h>
#define PI_NOUI 0x00000001 // Prevents displaying of messages
#define PI_APPLYPOLICY 0x00000002 // Apply NT4 style policy
USERENVAPI
BOOL
WINAPI
LoadUserProfileA(
_In_ HANDLE hToken,
_Inout_ LPPROFILEINFOA lpProfileInfo);
USERENVAPI
BOOL
WINAPI
LoadUserProfileW(
_In_ HANDLE hToken,
_Inout_ LPPROFILEINFOW lpProfileInfo);
#ifdef UNICODE
#define LoadUserProfile LoadUserProfileW
#else
#define LoadUserProfile LoadUserProfileA
#endif // !UNICODE
//=============================================================================
//
// UnloadUserProfile
//
// Unloads a user's profile that was loaded by LoadUserProfile()
//
// hToken - Token for the user, returned from LogonUser()
// hProfile - hProfile member of the PROFILEINFO structure
//
// Returns: TRUE if successful
// FALSE if not. Call GetLastError() for more details
//
// Note: The caller of this function must have admin privileges on the machine.
//
//=============================================================================
USERENVAPI
BOOL
WINAPI
UnloadUserProfile(
_In_ HANDLE hToken,
_In_ HANDLE hProfile);
//=============================================================================
//
// GetProfilesDirectory
//
// Returns the path to the root of where all user profiles are stored.
//
// lpProfilesDir - Receives the path
// lpcchSize - Size of lpProfilesDir
//
// Returns: TRUE if successful
// FALSE if not. Call GetLastError() for more details
//
// Note: If lpProfilesDir is not large enough or NULL, the function will fail,
// and lpcchSize will contain the necessary buffer size.
//
// Example return value: C:\Users
//
//=============================================================================
USERENVAPI
BOOL
WINAPI
GetProfilesDirectoryA(
_Out_writes_opt_(*lpcchSize) LPSTR lpProfileDir,
_Inout_ LPDWORD lpcchSize);
USERENVAPI
BOOL
WINAPI
GetProfilesDirectoryW(
_Out_writes_opt_(*lpcchSize) LPWSTR lpProfileDir,
_Inout_ LPDWORD lpcchSize);
#ifdef UNICODE
#define GetProfilesDirectory GetProfilesDirectoryW
#else
#define GetProfilesDirectory GetProfilesDirectoryA
#endif // !UNICODE
//=============================================================================
//
// GetProfileType()
//
// Returns the type of the profile that is loaded for a user.
//
// dwFlags - Returns the profile flags
//
// Return: TRUE if successful
// FALSE if an error occurs. Call GetLastError for more details
//
// Comments: if profile is not already loaded the function will return an error.
// The caller needs to have access to HKLM part of the registry.
// (exists by default)
//
//=============================================================================
#if(WINVER >= 0x0500)
//
// Flags that can be set in the dwFlags field
//
#define PT_TEMPORARY 0x00000001 // A profile has been allocated that will be deleted at logoff.
#define PT_ROAMING 0x00000002 // The loaded profile is a roaming profile.
#define PT_MANDATORY 0x00000004 // The loaded profile is mandatory.
#define PT_ROAMING_PREEXISTING 0x00000008 // The loaded roaming profile is not a brand new one - it was obtained from roamed location
USERENVAPI
BOOL
WINAPI
GetProfileType(
_Out_ DWORD *dwFlags);
#endif /* WINVER >= 0x0500 */
//=============================================================================
//
// DeleteProfile()
//
// Deletes the profile and all other user related settings from the machine
//
// lpSidString - String form of the user sid.
// lpProfilePath - ProfilePath (if Null, lookup in the registry)
// lpComputerName - Computer Name from which profile has to be deleted
//
// Return: TRUE if successful
// FALSE if an error occurs. Call GetLastError for more details
//
// Comments: Deletes the profile directory, registry and appmgmt stuff
//=============================================================================
#if(WINVER >= 0x0500)
USERENVAPI
BOOL
WINAPI
DeleteProfileA (
_In_ LPCSTR lpSidString,
_In_opt_ LPCSTR lpProfilePath,
_In_opt_ LPCSTR lpComputerName);
USERENVAPI
BOOL
WINAPI
DeleteProfileW (
_In_ LPCWSTR lpSidString,
_In_opt_ LPCWSTR lpProfilePath,
_In_opt_ LPCWSTR lpComputerName);
#ifdef UNICODE
#define DeleteProfile DeleteProfileW
#else
#define DeleteProfile DeleteProfileA
#endif // !UNICODE
#endif /* WINVER >= 0x0500 */
//=============================================================================
//
// CreateProfile()
//
// Creating a user profile without loading it.
//
// pszUserSid - String form of the user sid.
// pszUserName - Name of the user, used as the base name to create the
// profile directory
// pszProfilePath - Returned full profile path
// cchProfilePath - Size of pszProfilePath buffer
//
// Return: S_OK : Successfully created the profile
// E_ACCESSDENIED : The caller does not have enough permission to
// create the profile. The caller has to be administrators
// in order for this API to succeed.
// HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS) : a profile is
// already exists for the given user.
// Others : Standard HRESULT error codes.
//
// Comments:
//=============================================================================
#if(WINVER >= 0x0600)
USERENVAPI
HRESULT
WINAPI
CreateProfile(
_In_ LPCWSTR pszUserSid,
_In_ LPCWSTR pszUserName,
_Out_writes_(cchProfilePath) LPWSTR pszProfilePath,
_In_ DWORD cchProfilePath);
#endif /* WINVER >= 0x0600 */
//=============================================================================
//
// GetDefaultUserProfilesDirectory
//
// Returns the path to the root of the default user profile
//
// lpProfileDir - Receives the path
// lpcchSize - Size of lpProfileDir
//
// Returns: TRUE if successful
// FALSE if not. Call GetLastError() for more details
//
// Note: If lpProfileDir is not large enough or NULL, the function will fail,
// and lpcchSize will contain the necessary buffer size.
//
// Example return value: C:\Users\Default
//
//=============================================================================
#if(WINVER >= 0x0500)
USERENVAPI
BOOL
WINAPI
GetDefaultUserProfileDirectoryA(
_Out_writes_opt_(*lpcchSize) LPSTR lpProfileDir,
_Inout_ LPDWORD lpcchSize);
USERENVAPI
BOOL
WINAPI
GetDefaultUserProfileDirectoryW(
_Out_writes_opt_(*lpcchSize) LPWSTR lpProfileDir,
_Inout_ LPDWORD lpcchSize);
#ifdef UNICODE
#define GetDefaultUserProfileDirectory GetDefaultUserProfileDirectoryW
#else
#define GetDefaultUserProfileDirectory GetDefaultUserProfileDirectoryA
#endif // !UNICODE
#endif /* WINVER >= 0x0500 */
//=============================================================================
//
// GetAllUsersProfilesDirectory
//
// Returns the path to the root of the All Users profile
//
// lpProfileDir - Receives the path
// lpcchSize - Size of lpProfileDir
//
// Returns: TRUE if successful
// FALSE if not. Call GetLastError() for more details
//
// Note: If lpProfileDir is not large enough or NULL, the function will fail,
// and lpcchSize will contain the necessary buffer size.
//
// Example return value: C:\Program Data
//
//=============================================================================
#if(WINVER >= 0x0500)
USERENVAPI
BOOL
WINAPI
GetAllUsersProfileDirectoryA(
_Out_writes_opt_(*lpcchSize) LPSTR lpProfileDir,
_Inout_ LPDWORD lpcchSize);
USERENVAPI
BOOL
WINAPI
GetAllUsersProfileDirectoryW(
_Out_writes_opt_(*lpcchSize) LPWSTR lpProfileDir,
_Inout_ LPDWORD lpcchSize);
#ifdef UNICODE
#define GetAllUsersProfileDirectory GetAllUsersProfileDirectoryW
#else
#define GetAllUsersProfileDirectory GetAllUsersProfileDirectoryA
#endif // !UNICODE
#endif /* WINVER >= 0x0500 */
//=============================================================================
//
// GetUserProfileDirectory
//
// Returns the path to the root of the requested user's profile
//
// hToken - User's token returned from LogonUser()
// lpProfileDir - Receives the path
// lpcchSize - Size of lpProfileDir
//
// Returns: TRUE if successful
// FALSE if not. Call GetLastError() for more details
//
// Note: If lpProfileDir is not large enough or NULL, the function will fail,
// and lpcchSize will contain the necessary buffer size.
//
// Example return value: C:\Users\Joe
//
//=============================================================================
USERENVAPI
BOOL
WINAPI
GetUserProfileDirectoryA(
_In_ HANDLE hToken,
_Out_writes_opt_(*lpcchSize) LPSTR lpProfileDir,
_Inout_ LPDWORD lpcchSize);
USERENVAPI
BOOL
WINAPI
GetUserProfileDirectoryW(
_In_ HANDLE hToken,
_Out_writes_opt_(*lpcchSize) LPWSTR lpProfileDir,
_Inout_ LPDWORD lpcchSize);
#ifdef UNICODE
#define GetUserProfileDirectory GetUserProfileDirectoryW
#else
#define GetUserProfileDirectory GetUserProfileDirectoryA
#endif // !UNICODE
//=============================================================================
//
// CreateEnvironmentBlock
//
// Returns the environment variables for the specified user. This block
// can then be passed to CreateProcessAsUser().
//
// lpEnvironment - Receives a pointer to the new environment block
// hToken - User's token returned from LogonUser() (optional, can be NULL)
// bInherit - Inherit from the current process's environment block
// or start from a clean state.
//
// Returns: TRUE if successful
// FALSE if not. Call GetLastError() for more details
//
// Note: If hToken is NULL, the returned environment block will contain
// system variables only.
//
// Call DestroyEnvironmentBlock to free the buffer when finished.
//
// If this block is passed to CreateProcessAsUser, the
// CREATE_UNICODE_ENVIRONMENT flag must also be set.
//
//=============================================================================
BOOL
WINAPI
CreateEnvironmentBlock(
_At_((PZZWSTR *)lpEnvironment, _Outptr_) LPVOID *lpEnvironment,
_In_opt_ HANDLE hToken,
_In_ BOOL bInherit);
//=============================================================================
//
// DestroyEnvironmentBlock
//
// Frees environment variables created by CreateEnvironmentBlock
//
// lpEnvironment - A pointer to the environment block
//
// Returns: TRUE if successful
// FALSE if not. Call GetLastError() for more details
//
//=============================================================================
BOOL
WINAPI
DestroyEnvironmentBlock(
_In_ LPVOID lpEnvironment);
//=============================================================================
//
// ExpandEnvironmentStringsForUser
//
// Expands the source string using the environment block for the
// specified user. If hToken is null, the system environment block
// will be used (no user environment variables).
//
// hToken - User's token returned from LogonUser() (optional, can be NULL)
// lpSrc - Pointer to the string with environment variables
// lpDest - Buffer that receives the expanded string
// dwSize - Size of lpDest in characters (max chars)
//
// Returns: TRUE if successful
// FALSE if not. Call GetLastError() for more details
//
// Note: If the user profile for hToken is not loaded, this api will fail.
//
//=============================================================================
#if(WINVER >= 0x0500)
USERENVAPI
BOOL
WINAPI
ExpandEnvironmentStringsForUserA(
_In_opt_ HANDLE hToken,
_In_ LPCSTR lpSrc,
_Out_writes_(dwSize) LPSTR lpDest,
_In_ DWORD dwSize);
USERENVAPI
BOOL
WINAPI
ExpandEnvironmentStringsForUserW(
_In_opt_ HANDLE hToken,
_In_ LPCWSTR lpSrc,
_Out_writes_(dwSize) LPWSTR lpDest,
_In_ DWORD dwSize);
#ifdef UNICODE
#define ExpandEnvironmentStringsForUser ExpandEnvironmentStringsForUserW
#else
#define ExpandEnvironmentStringsForUser ExpandEnvironmentStringsForUserA
#endif // !UNICODE
#endif /* WINVER >= 0x0500 */
//=============================================================================
//
// RefreshPolicy()
//
// Causes group policy to be applied immediately on the client machine
//
// bMachine - Refresh machine or user policy
//
// Returns: TRUE if successful
// FALSE if not. Call GetLastError() for more details
//
//=============================================================================
#if(WINVER >= 0x0500)
USERENVAPI
BOOL
WINAPI
RefreshPolicy(
_In_ BOOL bMachine);
#endif /* WINVER >= 0x0500 */
//=============================================================================
//
// RefreshPolicyEx()
//
// Causes group policy to be applied immediately on the client machine.
//
// bMachine - Refresh machine or user policy
// dwOptions - Option specifying the kind of refresh that needs to be done.
//
// Returns: TRUE if successful
// FALSE if not. Call GetLastError() for more details
//
//=============================================================================
#if(WINVER >= 0x0500)
#define RP_FORCE 1 // Refresh policies without any optimisations.
#define RP_SYNC 2 // Refresh Policy sync; the call does not return till the time policy processing is completed
USERENVAPI
BOOL
WINAPI
RefreshPolicyEx(
_In_ BOOL bMachine,
_In_ DWORD dwOptions);
#endif /* WINVER >= 0x0500 */
//=============================================================================
//
// EnterCriticalPolicySection
//
// Pauses the background application of group policy to allow safe
// reading of the registry. Applications that need to read multiple
// policy entries and ensure that the values are not changed while reading
// them should use this function.
//
// The maximum amount of time an application can hold a critical section
// is 10 minutes. After 10 minutes, policy can be applied again.
//
// bMachine - Pause machine or user policy
//
// Returns: Handle if successful
// NULL if not. Call GetLastError() for more details
//
// Note 1: The handle returned should be passed to LeaveCriticalPolicySection
// when finished. Do not close this handle, LeaveCriticalPolicySection
// will do that.
//
// Note 2: If both user and machine critical sections need to be acquired then
// they should be done in this order: first acquire user critical section and
// then acquire machine critical section.
//
//=============================================================================
#if(WINVER >= 0x0500)
USERENVAPI
HANDLE
WINAPI
EnterCriticalPolicySection(
_In_ BOOL bMachine);
#endif /* WINVER >= 0x0500 */
//=============================================================================
//
// LeaveCriticalPolicySection
//
// Resumes the background application of group policy. See
// EnterCriticalPolicySection for more details.
//
// hSection - Handle returned from EnterCriticalPolicySection
//
// Returns: TRUE if successful
// FALSE if not. Call GetLastError() for more details
//
// Note: This function will close the handle.
//
//=============================================================================
#if(WINVER >= 0x0500)
USERENVAPI
BOOL
WINAPI
LeaveCriticalPolicySection(
_In_ HANDLE hSection);
#endif /* WINVER >= 0x0500 */
//=============================================================================
//
// RegisterGPNotification
//
// Entry point for registering for Group Policy change notification.
//
// Parameters: hEvent - Event to be notified, by calling SetEvent(hEvent)
// bMachine - If true, then register machine policy notification
// else register user policy notification
//
// Returns: True if successful
// False if error occurs
//
// Notes: Group Policy Notifications. There are 2 ways an application can
// be notify when Group Policy is finished being applied.
//
// 1) Using the RegisterGPNotifcation function and waiting for the
// event to be signalled.
//
// 2) A WM_SETTINGCHANGE message is broadcast to all desktops.
// wParam - 1 if machine policy was applied, 0 if user policy was applied.
// lParam - Points to the string "Policy"
//
//=============================================================================
#if(WINVER >= 0x0500)
USERENVAPI
BOOL
WINAPI
RegisterGPNotification(
_In_ HANDLE hEvent,
_In_ BOOL bMachine);
#endif /* WINVER >= 0x0500 */
//=============================================================================
//
// UnregisterGPNotification
//
// Removes registration for a Group Policy change notification.
//
// Parameters: hEvent - Event to be removed
//
// Returns: True if successful
// False if error occurs
//
//=============================================================================
#if(WINVER >= 0x0500)
USERENVAPI
BOOL
WINAPI
UnregisterGPNotification(
_In_ HANDLE hEvent);
#endif /* WINVER >= 0x0500 */
//=============================================================================
//
// GPOptions flags
//
// These are the flags found in the GPOptions property of a DS object
//
// For a given DS object (Site, Domain, OU), the GPOptions property
// contains options that effect all the GPOs link to this SDOU.
//
// This is a DWORD type
//
//=============================================================================
#if(WINVER >= 0x0500)
#define GPC_BLOCK_POLICY 0x00000001 // Block all non-forced policy from above
#endif /* WINVER >= 0x0500 */
//=============================================================================
//
// GPLink flags
//
// These are the flags found on the GPLink property of a DS object after
// the GPO path.
//
// For a given DS object (Site, Domain, OU), the GPLink property will
// be in this text format
//
// [LDAP://CN={E615A0E3-C4F1-11D1-A3A7-00AA00615092},CN=Policies,CN=System,DC=mydomain,DC=Microsoft,DC=Com;1]
//
// The GUID is the GPO name, and the number following the LDAP path are the options
// for that link from this DS object. Note, there can be multiple GPOs
// each in their own square brackets in a prioritized list.
//
//=============================================================================
#if(WINVER >= 0x0500)
//
// Options for a GPO link
//
#define GPO_FLAG_DISABLE 0x00000001 // This GPO is disabled
#define GPO_FLAG_FORCE 0x00000002 // Don't override the settings in
// this GPO with settings from
// a GPO below it.
#endif /* WINVER >= 0x0500 */
//=============================================================================
//
// GetGPOList
//
//
// Queries for the list of Group Policy Objects for the specified
// user or machine. This function will return a link list
// of Group Policy Objects. Call FreeGPOList to free the list.
//
// Note, most applications will not need to call this function.
// This will primarily be used by services acting on behalf of
// another user or machine. The caller of this function will
// need to look in each GPO for their specific policy
//
// This function can be called in two different ways. Either the hToken for
// a user or machine can be supplied and the correct name and domain
// controller name will be generated, or hToken is NULL and the caller
// must supply the name and the domain controller name.
//
// Calling this function with an hToken ensures the list of Group Policy
// Objects is correct for the user or machine since security access checking
// can be perfomed. If hToken is not supplied, the security of the caller
// is used instead which means that list may or may not be 100% correct
// for the intended user / machine. However, this is the fastest way
// to call this function.
//
// hToken - User or machine token, if NULL, lpName and lpHostName must be supplied
// lpName - User or machine name in DN format, if hToken is supplied, this must be NULL
// lpHostName - Domain DN name or domain controller name. If hToken is supplied, this must be NULL
// lpComputerName - Computer name to use to determine site location. If NULL,
// the local computer is used as the reference. Format: \\machinename
// dwFlags - Flags field. See flags definition below
// pGPOList - Address of a pointer which receives the link list of GPOs
//
//
// Returns: TRUE if successful
// FALSE if not. Use GetLastError() for more details.
//
// Examples:
//
// Here's how this function will typically be called for
// looking up the list of GPOs for a user:
//
// LPGROUP_POLICY_OBJECT pGPOList;
//
// if (GetGPOList (hToken, NULL, NULL, NULL, 0, &pGPOList))
// {
// // do processing here...
// FreeGPOList (pGPOList);
// }
//
//
// Here's how this function will typically be called for
// looking up the list of GPOs for a machine:
//
// LPGROUP_POLICY_OBJECT pGPOList;
//
// if (GetGPOList (NULL, lpMachineName, lpHostName, lpMachineName,
// GPO_LIST_FLAG_MACHINE, &pGPOList))
// {
// // do processing here...
// FreeGPOList (pGPOList);
// }
//
//=============================================================================
#if(WINVER >= 0x0500)
//
// Each Group Policy Object is associated (linked) with a site, domain,
// organizational unit, or machine.
//
typedef enum _GPO_LINK {
GPLinkUnknown = 0, // No link information available
GPLinkMachine, // GPO linked to a machine (local or remote)
GPLinkSite, // GPO linked to a site
GPLinkDomain, // GPO linked to a domain
GPLinkOrganizationalUnit // GPO linked to a organizational unit
} GPO_LINK, *PGPO_LINK;
typedef struct _GROUP_POLICY_OBJECTA {
DWORD dwOptions; // See GPLink option flags above
DWORD dwVersion; // Revision number of the GPO
LPSTR lpDSPath; // Path to the Active Directory portion of the GPO
LPSTR lpFileSysPath; // Path to the file system portion of the GPO
LPSTR lpDisplayName; // Friendly display name
CHAR szGPOName[50]; // Unique name
GPO_LINK GPOLink; // Link information
LPARAM lParam; // Free space for the caller to store GPO specific information
struct _GROUP_POLICY_OBJECTA * pNext; // Next GPO in the list
struct _GROUP_POLICY_OBJECTA * pPrev; // Previous GPO in the list
LPSTR lpExtensions; // Extensions that are relevant for this GPO
LPARAM lParam2; // Free space for the caller to store GPO specific information
LPSTR lpLink; // Path to the Active Directory site, domain, or organizational unit this GPO is linked to
// If this is the local GPO, this points to the word "Local"
} GROUP_POLICY_OBJECTA, *PGROUP_POLICY_OBJECTA;
typedef struct _GROUP_POLICY_OBJECTW {
DWORD dwOptions; // See GPLink option flags above
DWORD dwVersion; // Revision number of the GPO
LPWSTR lpDSPath; // Path to the Active Directory portion of the GPO
LPWSTR lpFileSysPath; // Path to the file system portion of the GPO
LPWSTR lpDisplayName; // Friendly display name
WCHAR szGPOName[50]; // Unique name
GPO_LINK GPOLink; // Link information
LPARAM lParam; // Free space for the caller to store GPO specific information
struct _GROUP_POLICY_OBJECTW * pNext; // Next GPO in the list
struct _GROUP_POLICY_OBJECTW * pPrev; // Previous GPO in the list
LPWSTR lpExtensions; // Extensions that are relevant for this GPO
LPARAM lParam2; // Free space for the caller to store GPO specific information
LPWSTR lpLink; // Path to the Active Directory site, domain, or organizational unit this GPO is linked to
// If this is the local GPO, this points to the word "Local"
} GROUP_POLICY_OBJECTW, *PGROUP_POLICY_OBJECTW;
#ifdef UNICODE
typedef GROUP_POLICY_OBJECTW GROUP_POLICY_OBJECT;
typedef PGROUP_POLICY_OBJECTW PGROUP_POLICY_OBJECT;
#else
typedef GROUP_POLICY_OBJECTA GROUP_POLICY_OBJECT;
typedef PGROUP_POLICY_OBJECTA PGROUP_POLICY_OBJECT;
#endif // UNICODE
//
// dwFlags for GetGPOList()
//
#define GPO_LIST_FLAG_MACHINE 0x00000001 // Return machine policy information
#define GPO_LIST_FLAG_SITEONLY 0x00000002 // Return site policy information only
#define GPO_LIST_FLAG_NO_WMIFILTERS 0x00000004 // Ignore WMI filters when filtering GPO's
#define GPO_LIST_FLAG_NO_SECURITYFILTERS 0x00000008 // Ignore security filters
USERENVAPI
BOOL
WINAPI
GetGPOListA (
_In_opt_ HANDLE hToken,
_In_opt_ LPCSTR lpName,
_In_opt_ LPCSTR lpHostName,
_In_opt_ LPCSTR lpComputerName,
_In_ DWORD dwFlags,
_Outptr_ PGROUP_POLICY_OBJECTA * pGPOList);
USERENVAPI
BOOL
WINAPI
GetGPOListW (
_In_opt_ HANDLE hToken,
_In_opt_ LPCWSTR lpName,
_In_opt_ LPCWSTR lpHostName,
_In_opt_ LPCWSTR lpComputerName,
_In_ DWORD dwFlags,
_Outptr_ PGROUP_POLICY_OBJECTW * pGPOList);
#ifdef UNICODE
#define GetGPOList GetGPOListW
#else
#define GetGPOList GetGPOListA
#endif // !UNICODE
#endif /* WINVER >= 0x0500 */
//=============================================================================
//
// FreeGPOList
//
//
// Frees the linked list returned from GetGPOList
//
// pGPOList - Pointer to the linked list of GPOs
//
//
// Returns: TRUE if successful
// FALSE if not
//
//=============================================================================
#if(WINVER >= 0x0500)
USERENVAPI
BOOL
WINAPI
FreeGPOListA (
_In_ PGROUP_POLICY_OBJECTA pGPOList);
USERENVAPI
BOOL
WINAPI
FreeGPOListW (
_In_ PGROUP_POLICY_OBJECTW pGPOList);
#ifdef UNICODE
#define FreeGPOList FreeGPOListW
#else
#define FreeGPOList FreeGPOListA
#endif // !UNICODE
#endif /* WINVER >= 0x0500 */
//=============================================================================
//
// GetAppliedGPOList
//
// Queries for the list of applied Group Policy Objects for the specified
// user or machine and specified client side extension. This function will return
// a linked list of Group Policy Objects. Call FreeGPOList to free the list.
//
// dwFlags - User or machine policy, if it is GPO_LIST_FLAG_MACHINE then
// return machine policy information
// pMachineName - Name of remote computer in the form \\computername. If null
// then local computer is used.
// pSidUser - Security id of user (relevant for user policy). If pMachineName is
// null and pSidUser is null then it means current logged on user.
// If pMachine is null and pSidUser is non-null then it means user
// represented by pSidUser on local machine. If pMachineName is non-null
// then and if dwFlags specifies user policy, then pSidUser must be
// non-null.
// pGuidExtension - Guid of the specified extension
// ppGPOList - Address of a pointer which receives the link list of GPOs
//
// The return value is a Win32 error code. ERROR_SUCCESS means the GetAppliedGPOList
// function completed successfully. Otherwise it indicates that the function failed.
//
//=============================================================================
#if(WINVER >= 0x0500)
USERENVAPI
DWORD
WINAPI
GetAppliedGPOListA (
_In_ DWORD dwFlags,
_In_opt_ LPCSTR pMachineName,
_In_opt_ PSID pSidUser,
_In_ GUID *pGuidExtension,
_Outptr_ PGROUP_POLICY_OBJECTA *ppGPOList);
USERENVAPI
DWORD
WINAPI
GetAppliedGPOListW (
_In_ DWORD dwFlags,
_In_opt_ LPCWSTR pMachineName,
_In_opt_ PSID pSidUser,
_In_ GUID *pGuidExtension,
_Outptr_ PGROUP_POLICY_OBJECTW *ppGPOList);
#ifdef UNICODE
#define GetAppliedGPOList GetAppliedGPOListW
#else
#define GetAppliedGPOList GetAppliedGPOListA
#endif // !UNICODE
#endif /* WINVER >= 0x0500 */
//=============================================================================
//
// Group Policy Object client side extension support
//
// Flags, data structures and function prototype
//
// To register your extension, create a subkey under this key
//
// Software\Microsoft\Windows NT\CurrentVersion\Winlogon\GPExtensions
//
// The subkey needs to be a guid so that it is unique. The noname value of the subkey
// can be the friendly name of the extension. Then add these values:
//
// DllName REG_EXPAND_SZ Path to your DLL
// ProcessGroupPolicy REG_SZ Function name (see PFNPROCESSGROUPPOLICY prototype). This
// is obsolete, it has been superseded by ProcessGroupPolicyEx.
// It's here for backward compatibility reasons only.
// ProcessGroupPolicyEx REG_SZ Function name (see PFNPROCESSGROUPPOLICYEX prototype)
// GenerateGroupPolicy REG_SZ Function name for Rsop (see PFNGENERATEGROUPPOLICY prototype)
// NoMachinePolicy REG_DWORD True, if extension does not have to be called when
// machine policies are being processed.
// NoUserPolicy REG_DWORD True, if extension does not have to be called when
// user policies are being processed.
// NoSlowLink REG_DWORD True, if extension does not have to be called on a slow link
// NoBackgroundPolicy REG_DWORD True, if extension does not have to be called
// for background policy processing.
// NoGPOListChanges REG_DWORD True, if extension does not have to be called when
// there are no changes between cached and current GPO lists.
// PerUserLocalSettings REG_DWORD True, if user policies have to be cached on a per user and
// per machine basis.
// RequiresSuccessfulRegistry REG_DWORD True, if extension should be called only if registry extension
// was successfully processed.
// EnableAsynchronousProcessing REG_DWORD True, if registry extension will complete its processing
// asynchronously.
// NotifyLinkTransition REG_DWORD True, if extension should be called when a change in link
// speed is detected between previous policy application and
// current policy application.
//
// The return value is a Win32 error code. ERROR_SUCCESS means the ProcessGroupPolicy
// function completed successfully. If return value is ERROR_OVERRIDE_NOCHANGES then it
// means that the extension will be called the next time even if NoGPOListChanges is set
// and there are no changes to the GPO list. Any other return value indicates that the
// ProcessGroupPolicy or ProcessGroupPolicyEx function failed.
//
//=============================================================================
#if(WINVER >= 0x0500)
#define GP_DLLNAME TEXT("DllName")
#define GP_ENABLEASYNCHRONOUSPROCESSING TEXT("EnableAsynchronousProcessing")