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

📄 userenv.pas

📁 详细Windows API大全有关知识以及相关问题
💻 PAS
📖 第 1 页 / 共 4 页
字号:
{******************************************************************}
{                                                       	   }
{       Borland Delphi Runtime Library                  	   }
{       User Profile interface unit                                }
{ 								   }
{ Portions created by Microsoft are 				   }
{ Copyright (C) 1995-1999 Microsoft Corporation. 		   }
{ All Rights Reserved. 						   }
{ 								   }
{ The original file is: userenv.h, released June 2000. 	           }
{ The original Pascal code is: UserEnv.pas, released December 2000 }
{ The initial developer of the Pascal code is Marcel van Brakel    }
{ (brakelm@bart.nl).                      			   }
{ 								   }
{ Portions created by Marcel van Brakel are			   }
{ Copyright (C) 1999 Marcel van Brakel.				   }
{ 								   }
{ Obtained through:                               	           }
{ Joint Endeavour of Delphi Innovators (Project JEDI)              }
{								   }
{ You may retrieve the latest version of this file at the Project  }
{ JEDI home page, located at http://delphi-jedi.org                }
{								   }
{ The contents of this file are used with permission, subject to   }
{ the Mozilla Public License Version 1.1 (the "License"); you may  }
{ not use this file except in compliance with the License. You may }
{ obtain a copy of the License at                                  }
{ http://www.mozilla.org/MPL/MPL-1.1.html 	                   }
{                                                                  }
{ Software distributed under the License is distributed on an 	   }
{ "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or   }
{ implied. See the License for the specific language governing     }
{ rights and limitations under the License. 			   }
{ 								   }
{******************************************************************}

unit UserEnv;

{$WEAKPACKAGEUNIT}

{$HPPEMIT ''}
{$HPPEMIT '#include "userenv.h"'}
{$HPPEMIT ''}
{$HPPEMIT 'typedef PGROUP_POLICY_OBJECTA *PPGROUP_POLICY_OBJECTA'}
{$HPPEMIT 'typedef PGROUP_POLICY_OBJECTW *PPGROUP_POLICY_OBJECTW'}
{$HPPEMIT ''}
{$HPPEMIT 'typedef #ifdef UNICODE'}
{$HPPEMIT 'typedef PPGROUP_POLICY_OBJECTW PPGROUP_POLICY_OBJECT'}
{$HPPEMIT 'typedef #else'}
{$HPPEMIT 'typedef PPGROUP_POLICY_OBJECTA PPGROUP_POLICY_OBJECT'}
{$HPPEMIT 'typedef #endif'}
{$HPPEMIT ''}

{$I WINDEFINES.INC}

interface

uses
  WinType, WinNT;

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

//
// Flags that can be set in the dwFlags field
//

const
  PI_NOUI        = $00000001; // Prevents displaying of messages
  {$EXTERNALSYM PI_NOUI}
  PI_APPLYPOLICY = $00000002; // Apply NT4 style policy
  {$EXTERNALSYM PI_APPLYPOLICY}

type
  LPPROFILEINFOA = ^PROFILEINFOA;
  {$EXTERNALSYM LPPROFILEINFOA}
  _PROFILEINFOA = record
    dwSize: DWORD;         // Set to sizeof(PROFILEINFO) before calling
    dwFlags: DWORD;        // See flags above
    lpUserName: LPSTR;     // User name (required)
    lpProfilePath: LPSTR;  // Roaming profile path (optional, can be NULL)
    lpDefaultPath: LPSTR;  // Default user profile path (optional, can be NULL)
    lpServerName: LPSTR;   // Validating domain controller name in netbios format (optional, can be NULL but group NT4 style policy won't be applied)
    lpPolicyPath: LPSTR;   // Path to the NT4 style policy file (optional, can be NULL)
    hProfile: HANDLE;      // Filled in by the function.  Registry key handle open to the root.
  end;
  {$EXTERNALSYM _PROFILEINFOA}
  PROFILEINFOA = _PROFILEINFOA;
  {$EXTERNALSYM PROFILEINFOA}
  TProfileInfoA = PROFILEINFOA;
  PProfileInfoA = LPPROFILEINFOA;

  LPPROFILEINFOW = ^PROFILEINFOW;
  {$EXTERNALSYM LPPROFILEINFOW}
  _PROFILEINFOW = record
    dwSize: DWORD;         // Set to sizeof(PROFILEINFO) before calling
    dwFlags: DWORD;        // See flags above
    lpUserName: LPWSTR;    // User name (required)
    lpProfilePath: LPWSTR; // Roaming profile path (optional, can be NULL)
    lpDefaultPath: LPWSTR; // Default user profile path (optional, can be NULL)
    lpServerName: LPWSTR;  // Validating domain controller name in netbios format (optional, can be NULL but group NT4 style policy won't be applied)
    lpPolicyPath: LPWSTR;  // Path to the NT4 style policy file (optional, can be NULL)
    hProfile: HANDLE;      // Filled in by the function.  Registry key handle open to the root.
  end;
  {$EXTERNALSYM _PROFILEINFOW}
  PROFILEINFOW = _PROFILEINFOW;
  {$EXTERNALSYM PROFILEINFOW}
  TProfileInfoW = PROFILEINFOW;
  PProfileInfoW = LPPROFILEINFOW;

{$IFDEF UNICODE}
  PROFILEINFO = PROFILEINFOW;
  {$EXTERNALSYM PROFILEINFO}
  LPPROFILEINFO = LPPROFILEINFOW;
  {$EXTERNALSYM LPPROFILEINFO}
  TProfileInfo = TProfileInfoW;
  PProfileInfo = PProfileInfoW;
{$ELSE}
  PROFILEINFO = PROFILEINFOA;
  {$EXTERNALSYM PROFILEINFO}
  LPPROFILEINFO = LPPROFILEINFOA;
  {$EXTERNALSYM LPPROFILEINFO}
  TProfileInfo = TProfileInfoA;
  PProfileInfo = PProfileInfoA;
{$ENDIF}

function LoadUserProfileA(hToken: HANDLE; var lpProfileInfo: PROFILEINFOA): BOOL; stdcall;
{$EXTERNALSYM LoadUserProfileA}
function LoadUserProfileW(hToken: HANDLE; var lpProfileInfo: PROFILEINFOW): BOOL; stdcall;
{$EXTERNALSYM LoadUserProfileW}

{$IFDEF UNICODE}
function LoadUserProfile(hToken: HANDLE; var lpProfileInfo: PROFILEINFO): BOOL; stdcall;
{$EXTERNALSYM LoadUserProfile}
{$ELSE}
function LoadUserProfile(hToken: HANDLE; var lpProfileInfo: PROFILEINFO): BOOL; stdcall;
{$EXTERNALSYM LoadUserProfile}
{$ENDIF}

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

function UnloadUserProfile(hToken: HANDLE; hProfile: HANDLE): BOOL; stdcall;
{$EXTERNALSYM UnloadUserProfile}

//=============================================================================
//
// 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, the function will fail,
//           and lpcchSize will contain the necessary buffer size.
//
// Example return value: C:\Documents and Settings
//
//=============================================================================

function GetProfilesDirectoryA(lpProfilesDir: LPSTR; var lpcchSize: DWORD): BOOL; stdcall;
{$EXTERNALSYM GetProfilesDirectoryA}
function GetProfilesDirectoryW(lpProfilesDir: LPWSTR; var lpcchSize: DWORD): BOOL; stdcall;
{$EXTERNALSYM GetProfilesDirectoryW}

{$IFDEF UNICODE}
function GetProfilesDirectory(lpProfilesDir: LPWSTR; var lpcchSize: DWORD): BOOL; stdcall;
{$EXTERNALSYM GetProfilesDirectory}
{$ELSE}
function GetProfilesDirectory(lpProfilesDir: LPSTR; var lpcchSize: DWORD): BOOL; stdcall;
{$EXTERNALSYM GetProfilesDirectory}
{$ENDIF}

//=============================================================================
//
//  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)
//
//=============================================================================

//
// Flags that can be set in the dwFlags field
//

const
  PT_TEMPORARY = $00000001; // A profile has been allocated that will be deleted at logoff.
  {$EXTERNALSYM PT_TEMPORARY}
  PT_ROAMING   = $00000002; // The loaded profile is a roaming profile.
  {$EXTERNALSYM PT_ROAMING}
  PT_MANDATORY = $00000004; // The loaded profile is mandatory.
  {$EXTERNALSYM PT_MANDATORY}

function GetProfileType(var dwFlags: DWORD): BOOL; stdcall;
{$EXTERNALSYM GetProfileType}

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

function DeleteProfileA(lpSidString: LPCSTR; lpProfilePath: LPCSTR;
  lpComputerName: LPCSTR): BOOL; stdcall;
{$EXTERNALSYM DeleteProfileA}
function DeleteProfileW(lpSidString: LPCWSTR; lpProfilePath: LPCWSTR;
  lpComputerName: LPCWSTR): BOOL; stdcall;

⌨️ 快捷键说明

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