whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

18 Visitors Online


 
...change the local/remote/active directory system group policy?
Autor: Kingron
Homepage: http://kingron.delphibbs.com
[ Print tip ]  

Tip Rating (10):  
     


{
  For win2k, xp or higher
}

uses ComObj, ActiveX, Registry;

const
  
GPO_OPEN_LOAD_REGISTRY = $00000001;  // Load the registry files
  {$EXTERNALSYM GPO_OPEN_LOAD_REGISTRY}
  
GPO_OPEN_READ_ONLY = $00000002;  // Open the GPO as read only

  
GPO_SECTION_ROOT = 0;  // Root
  {$EXTERNALSYM GPO_SECTION_ROOT}
  
GPO_SECTION_USER = 1;  // User
  {$EXTERNALSYM GPO_SECTION_USER}
  
GPO_SECTION_MACHINE = 2;  // Machine

const
  
IID_GPO: TGUID = '{EA502722-A23D-11d1-A7D3-0000F87571E3}';

type
  
HPROPSHEETPAGE = Pointer;
  {$EXTERNALSYM HPROPSHEETPAGE}
  
PHPROPSHEETPAGE = ^HPROPSHEETPAGE;
  LPOLESTR        = POleStr;
  _GROUP_POLICY_OBJECT_TYPE = (GPOTypeLocal,
    // GPO on the local machine
    
GPOTypeRemote,                        // GPO on a remote machine
    
GPOTypeDS);                           // GPO in the Active Directory
  {$EXTERNALSYM _GROUP_POLICY_OBJECT_TYPE}
  
GROUP_POLICY_OBJECT_TYPE = _GROUP_POLICY_OBJECT_TYPE;

  IGroupPolicyObject = interface(IUnknown)
    ['{EA502723-A23D-11d1-A7D3-0000F87571E3}']

    function New(pszDomainName, pszDisplayName: LPOLESTR; dwFlags: DWORD): HRESULT;
      stdcall;
    function OpenDSGPO(pszPath: LPOLESTR; dwFlags: DWORD): HRESULT; stdcall;
    function OpenLocalMachineGPO(dwFlags: DWORD): HRESULT; stdcall;
    function OpenRemoteMachineGPO(pszComputerName: LPOLESTR; dwFlags: DWORD): HRESULT;
      stdcall;
    function Save(bMachine, bAdd: BOOL; const pGuidExtension, pGuid: TGUID): HRESULT;
      stdcall;
    function Delete: HRESULT; stdcall;
    function GetName(pszName: LPOLESTR; cchMaxLength: Integer): HRESULT; stdcall;
    function GetDisplayName(pszName: LPOLESTR; cchMaxLength: Integer): HRESULT; stdcall;
    function SetDisplayName(pszName: LPOLESTR): HRESULT; stdcall;
    function GetPath(pszPath: LPOLESTR; cchMaxPath: Integer): HRESULT; stdcall;
    function GetDSPath(dwSection: DWORD; pszPath: LPOLESTR; cchMaxPath: Integer): HRESULT;
      stdcall;
    function GetFileSysPath(dwSection: DWORD; pszPath: LPOLESTR;
      cchMaxPath: Integer): HRESULT; stdcall;

    //
    // Returns a registry key handle for the requested section.  The returned
    // key is the root of the registry, not the Policies subkey.  To set / read
    // a value in the Policies subkey, you will need to call RegOpenKeyEx to
    // open Software\Policies subkey first.
    //
    // The handle has been opened with ALL ACCESS rights.  Call RegCloseKey
    // on the handle when finished.
    //
    // If the GPO was loaded / created without the registry being loaded
    // this method will return E_FAIL.
    //
    // dwSection is either GPO_SECTION_USER or GPO_SECTION_MACHINE
    // hKey contains the registry key on return
    //

    
function GetRegistryKey(dwSection: DWORD; var hKey: HKEY): HRESULT; stdcall;
    function GetOptions(var dwOptions: DWORD): HRESULT; stdcall;
    function SetOptions(dwOptions, dwMask: DWORD): HRESULT; stdcall;
    function GetType(var gpoType: GROUP_POLICY_OBJECT_TYPE): HRESULT; stdcall;
    function GetMachineName(pszName: LPOLESTR; cchMaxLength: Integer): HRESULT; stdcall;
    function GetPropertySheetPages(var hPages: PHPROPSHEETPAGE;
      var uPageCount: UINT): HRESULT; stdcall;
  end;

const
  
REGISTRY_EXTENSION_GUID: TGUID = (D1: $35378EAC; D2: $683F; D3: $11D2;
    D4: ($A8, $9A, $00, $C0, $4F, $BB, $CF, $A2));
  CLSID_GPESnapIn: TGUID = (D1: $8fc0b734; D2: $a0e1; D3: $11d1;
    D4: ($a7, $d3, $0, $0, $f8, $75, $71, $e3));

procedure TForm1.Button1Click(Sender: TObject);
var
  
GPO: IGroupPolicyObject;
  Key: HKEY;
begin
  
GPO := CreateComObject(IID_GPO) as IGroupPolicyObject;
  if GPO.OpenLocalMachineGPO(GPO_OPEN_LOAD_REGISTRY) = S_OK then
  begin
    if 
GPO.GetRegistryKey(GPO_SECTION_USER, Key) = S_OK then
      with 
TRegistry.Create do
        try
          
RootKey := HKEY_CURRENT_USER;
          if OpenKey('Software\Microsoft\Windows\CurrentVersion\Policies\Explorer', True) then
          begin
            
WriteInteger('StartMenuLogOff', 0);
          end;

          RootKey := Key;
          if OpenKey('\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer', True) then
          begin
            
WriteInteger('StartMenuLogOff', 0);
          end;
          RegCloseKey(Key);
          GPO.Save(False, True, REGISTRY_EXTENSION_GUID, CLSID_GPESnapIn);
        finally
          
Free;
        end;
    SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, Integer(PChar('Polices')), 0);
  end;
end;

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners