⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 userenv.pas

📁 详细Windows API大全有关知识以及相关问题
💻 PAS
📖 第 1 页 / 共 4 页
字号:
//
// FreeGPOList
//
//
// Frees the link list returned from GetGPOList
//
// pGPOList - Pointer to the link list of GPOs
//
//
// Returns:  TRUE if successful
//           FALSE if not
//
//=============================================================================

function FreeGPOListA(pGPOList: PGROUP_POLICY_OBJECTA): BOOL; stdcall;
{$EXTERNALSYM FreeGPOListA}
function FreeGPOListW(pGPOList: PGROUP_POLICY_OBJECTW): BOOL; stdcall;
{$EXTERNALSYM FreeGPOListW}

{$IFDEF UNICODE}
function FreeGPOList(pGPOList: PGROUP_POLICY_OBJECT): BOOL; stdcall;
{$EXTERNALSYM FreeGPOList}
{$ELSE}
function FreeGPOList(pGPOList: PGROUP_POLICY_OBJECT): BOOL; stdcall;
{$EXTERNALSYM FreeGPOList}
{$ENDIF}

//=============================================================================
//
// 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 listof 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.
//
//=============================================================================

function GetAppliedGPOListA(dwFlags: DWORD; pMachineName: LPCSTR; pSidUser: PSID;
  pGuidExtension: LPGUID; ppGPOList: PPGROUP_POLICY_OBJECTA): DWORD; stdcall;
{$EXTERNALSYM GetAppliedGPOListA}
function GetAppliedGPOListW(dwFlags: DWORD; pMachineName: LPCWSTR; pSidUser: PSID;
  pGuidExtension: LPGUID; ppGPOList: PPGROUP_POLICY_OBJECTW): DWORD; stdcall;
{$EXTERNALSYM GetAppliedGPOListW}

{$IFDEF UNICODE}
function GetAppliedGPOList(dwFlags: DWORD; pMachineName: LPCWSTR; pSidUser: PSID;
  pGuidExtension: LPGUID; ppGPOList: PPGROUP_POLICY_OBJECT): DWORD; stdcall;
{$EXTERNALSYM GetAppliedGPOList}
{$ELSE}
function GetAppliedGPOList(dwFlags: DWORD; pMachineName: LPCSTR; pSidUser: PSID;
  pGuidExtension: LPGUID; ppGPOList: PPGROUP_POLICY_OBJECT): DWORD; stdcall;
{$EXTERNALSYM GetAppliedGPOList}
{$ENDIF}

//=============================================================================
//
// 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)
//     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 on.
//                                                 policies applied in background.
//     NoGPOListChanges             REG_DWORD    True, if extension does not have to be called when
//                                                 there are no changes between cached can 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 function failed.
//
//=============================================================================

const
  GPO_INFO_FLAG_MACHINE        = $00000001;   // Apply machine policy rather than user policy
  {$EXTERNALSYM GPO_INFO_FLAG_MACHINE}
  GPO_INFO_FLAG_BACKGROUND     = $00000010;   // Background refresh of policy (ok to do slow stuff)
  {$EXTERNALSYM GPO_INFO_FLAG_BACKGROUND}
  GPO_INFO_FLAG_SLOWLINK       = $00000020;   // Policy is being applied across a slow link
  {$EXTERNALSYM GPO_INFO_FLAG_SLOWLINK}
  GPO_INFO_FLAG_VERBOSE        = $00000040;   // Verbose output to the eventlog
  {$EXTERNALSYM GPO_INFO_FLAG_VERBOSE}
  GPO_INFO_FLAG_NOCHANGES      = $00000080;   // No changes were detected to the Group Policy Objects
  {$EXTERNALSYM GPO_INFO_FLAG_NOCHANGES}
  GPO_INFO_FLAG_LINKTRANSITION = $00000100;   // A change in link speed was detected between previous policy
  {$EXTERNALSYM GPO_INFO_FLAG_LINKTRANSITION} // application and current policy application

type
  ASYNCCOMPLETIONHANDLE = UINT_PTR;
  {$EXTERNALSYM ASYNCCOMPLETIONHANDLE}

  PFNSTATUSMESSAGECALLBACK = function (bVerbose: BOOL; lpMessage: LPWSTR): DWORD; stdcall;
  {$EXTERNALSYM PFNSTATUSMESSAGECALLBACK}

  PFNPROCESSGROUPPOLICY = function (
    dwFlags: DWORD;                              // GPO_INFO_FLAGS
    hToken: HANDLE;                              // User or machine token
    hKeyRoot: HKEY;                              // Root of registry
    pDeletedGPOList: PGROUP_POLICY_OBJECT;       // Linked list of deleted GPOs
    pChangedGPOList: PGROUP_POLICY_OBJECT;       // Linked list of changed GPOs
    pHandle: ASYNCCOMPLETIONHANDLE;              // For asynchronous completion
    pbAbort: LPBOOL;                             // If true, then abort GPO processing
    pStatusCallback: PFNSTATUSMESSAGECALLBACK    // Callback function for displaying status messages
    ): DWORD; stdcall;                           // Note, this can be NULL
  {$EXTERNALSYM PFNPROCESSGROUPPOLICY}

//
// GUID that identifies the registry extension
//

const
  REGISTRY_EXTENSION_GUID: GUID = (
    D1: $35378EAC; D2:$683F; D3:$11D2; D4:($A8, $9A, $00, $C0, $4F, $BB, $CF, $A2));
  {$EXTERNALSYM REGISTRY_EXTENSION_GUID}

//=============================================================================
//
// Group Policy Object client side asynchronous extension processing
//
// extensionId    - Unique guid identifying the extension
// pAsyncHandle   - Asynchronous completion handle that was passed to extension in
//                  ProcessGroupPolicy call
// dwStatus       - Completion status of asynchronous processing
//
// The return value is a Win32 error code. ERROR_SUCCESS means the ProcessGroupPolicyCompleted
// function completed successfully. Otherwise it indicates that the function failed.
//
//=============================================================================

type
  REFGPEXTENSIONID = LPGUID;
  {$EXTERNALSYM REFGPEXTENSIONID}

function ProcessGroupPolicyCompleted(extensionId: REFGPEXTENSIONID;
  pAsyncHandle: ASYNCCOMPLETIONHANDLE; dwStatus: DWORD): DWORD; stdcall;
{$EXTERNALSYM ProcessGroupPolicyCompleted}

implementation

const
  userenvlib = 'userenv.dll';

function LoadUserProfileA; external userenvlib name 'LoadUserProfileA';
function LoadUserProfileW; external userenvlib name 'LoadUserProfileW';
{$IFDEF UNICODE}
function LoadUserProfile; external userenvlib name 'LoadUserProfileW';
{$ELSE}
function LoadUserProfile; external userenvlib name 'LoadUserProfileA';
{$ENDIF}
function UnloadUserProfile; external userenvlib name 'UnloadUserProfile';
function GetProfilesDirectoryA; external userenvlib name 'GetProfilesDirectoryA';
function GetProfilesDirectoryW; external userenvlib name 'GetProfilesDirectoryW';
{$IFDEF UNICODE}
function GetProfilesDirectory; external userenvlib name 'GetProfilesDirectoryW';
{$ELSE}
function GetProfilesDirectory; external userenvlib name 'GetProfilesDirectoryA';
{$ENDIF}
function GetProfileType; external userenvlib name 'GetProfileType';
function DeleteProfileA; external userenvlib name 'DeleteProfileA';
function DeleteProfileW; external userenvlib name 'DeleteProfileW';
{$IFDEF UNICODE}
function DeleteProfile; external userenvlib name 'DeleteProfileW';
{$ELSE}
function DeleteProfile; external userenvlib name 'DeleteProfileA';
{$ENDIF}
function GetDefaultUserProfileDirectoryA; external userenvlib name 'GetDefaultUserProfileDirectoryA';
function GetDefaultUserProfileDirectoryW; external userenvlib name 'GetDefaultUserProfileDirectoryW';
{$IFDEF UNICODE}
function GetDefaultUserProfileDirectory; external userenvlib name 'GetDefaultUserProfileDirectoryW';
{$ELSE}
function GetDefaultUserProfileDirectory; external userenvlib name 'GetDefaultUserProfileDirectoryA';
{$ENDIF}
function GetAllUsersProfileDirectoryA; external userenvlib name 'GetAllUsersProfileDirectoryA';
function GetAllUsersProfileDirectoryW; external userenvlib name 'GetAllUsersProfileDirectoryW';
{$IFDEF UNICODE}
function GetAllUsersProfileDirectory; external userenvlib name 'GetAllUsersProfileDirectoryW';
{$ELSE}
function GetAllUsersProfileDirectory; external userenvlib name 'GetAllUsersProfileDirectoryA';
{$ENDIF}
function GetUserProfileDirectoryA; external userenvlib name 'GetUserProfileDirectoryA';
function GetUserProfileDirectoryW; external userenvlib name 'GetUserProfileDirectoryW';
{$IFDEF UNICODE}
function GetUserProfileDirectory; external userenvlib name 'GetUserProfileDirectoryW';
{$ELSE}
function GetUserProfileDirectory; external userenvlib name 'GetUserProfileDirectoryA';
{$ENDIF}
function CreateEnvironmentBlock; external userenvlib name 'CreateEnvironmentBlock';
function DestroyEnvironmentBlock; external userenvlib name 'DestroyEnvironmentBlock';
function ExpandEnvironmentStringsForUserA; external userenvlib name 'ExpandEnvironmentStringsForUserA';
function ExpandEnvironmentStringsForUserW; external userenvlib name 'ExpandEnvironmentStringsForUserW';
{$IFDEF UNICODE}
function ExpandEnvironmentStringsForUser; external userenvlib name 'ExpandEnvironmentStringsForUserW';
{$ELSE}
function ExpandEnvironmentStringsForUser; external userenvlib name 'ExpandEnvironmentStringsForUserA';
{$ENDIF}
function RefreshPolicy; external userenvlib name 'RefreshPolicy';
function EnterCriticalPolicySection; external userenvlib name 'EnterCriticalPolicySection';
function LeaveCriticalPolicySection; external userenvlib name 'LeaveCriticalPolicySection';
function RegisterGPNotification; external userenvlib name 'RegisterGPNotification';
function UnregisterGPNotification; external userenvlib name 'UnregisterGPNotification';
function GetGPOListA; external userenvlib name 'GetGPOListA';
function GetGPOListW; external userenvlib name 'GetGPOListW';
{$IFDEF UNICODE}
function GetGPOList; external userenvlib name 'GetGPOListW';
{$ELSE}
function GetGPOList; external userenvlib name 'GetGPOListA';
{$ENDIF}
function FreeGPOListA; external userenvlib name 'FreeGPOListA';
function FreeGPOListW; external userenvlib name 'FreeGPOListW';
{$IFDEF UNICODE}
function FreeGPOList; external userenvlib name 'FreeGPOListW';
{$ELSE}
function FreeGPOList; external userenvlib name 'FreeGPOListA';
{$ENDIF}
function GetAppliedGPOListA; external userenvlib name 'GetAppliedGPOListA';
function GetAppliedGPOListW; external userenvlib name 'GetAppliedGPOListW';
{$IFDEF UNICODE}
function GetAppliedGPOList; external userenvlib name 'GetAppliedGPOListW';
{$ELSE}
function GetAppliedGPOList; external userenvlib name 'GetAppliedGPOListA';
{$ENDIF}
function ProcessGroupPolicyCompleted; external userenvlib name 'ProcessGroupPolicyCompleted';

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -