GPMC GPO(组策略) 编程(200分)(200分)

  • 主题发起人 主题发起人 abc12345678
  • 开始时间 开始时间
A

abc12345678

Unregistered / Unconfirmed
GUEST, unregistred user!
我想写一个修改组策略,禁用注册表编辑工具。
找了一些相关的资料。知道使用GPMC,可以很好的实现,但没有相关的资料及demo.(主要是搞不它的内部操作原理。到微软查了半天。把自己搞得头晕晕的。还没明白。如:“域控制器 (DC) 来连接域,GPO 的权限”,还要刷新。),我引用了类型库gpmgmt.dll,就做不下去了。
请问哪位研究过。
 
没弄过,帮你顶下
 
问题解决了。原文:http://www.g4soft.net/BBS/dispbbs.asp?boardid=6&Id=525
我做的。

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,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;

TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
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));

var
Form1: TForm1;


implementation

{$R *.dfm}

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

RootKey := Key;
if OpenKey('Software/Microsoft/Windows/CurrentVersion/Policies/System', True) then
begin
WriteInteger('DisableRegistryTools', 2);
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;



end.
 
大富翁不如从前了。只能搞自己的四个朋友(左手,右手,一双眼睛)还好有两个号。
 
后退
顶部