Jump to content

IGroupPolicyObject interface


Bilgus
 Share

Recommended Posts

 IGroupPolicyObject interface

;;IGroupPolicyObject
#RequireAdmin
#include-once
#include <WinAPIConstants.au3> ; $S_OK
#include <WinAPIReg.au3> ;_WinAPI_GetRegKeyNameByHandle

Global Enum $GPO_SECTION_ROOT = 0x0, $GPO_SECTION_USER, $GPO_SECTION_MACHINE
Global Enum $GPO_OPEN_LOAD_REGISTRY = 0x1, $GPO_OPEN_READ_ONLY
Global Enum $GPO_OPTION_DISABLE_USER = 0x1, $GPO_OPTION_DISABLE_MACHINE
Global Enum $GPOTypeLocal = 0x0, $GPOTypeRemote, $GPOTypeDS, $GPOTypeLocalUser, $GPOTypeLocalGroup


Global Const $sCLSID_GroupPolicyObject = "{EA502722-A23D-11D1-A7D3-0000F87571E3}"

Global Const $sIID_IGroupPolicyObject = "{EA502723-A23D-11D1-A7D3-0000F87571E3}"

Global Const $dtag_IGroupPolicyObject = _
        "New                   hresult(wstr;wstr;dword);" & _ ; Creates a new GPO in the Active Directory with the specified display name.
        "OpenDSGPO             hresult(wstr;dword);" & _ ; Opens the specified GPO and optionally loads the registry information.
        "OpenLocalMachineGPO   hresult(dword);" & _ ; Opens the default GPO for the computer and optionally loads the registry information.
        "OpenRemoteMachineGPO  hresult(wstr;dword);" & _ ; Opens the default GPO for the specified remote computer and optionally loads the registry information.
        "Save                  hResult(bool;bool;ptr;ptr);" & _ ; Saves the specified registry policy settings to disk and updates the revision number of the GPO.
        "Delete                hresult();" & _ ; Deletes the GPO.
        "GetName               hResult(wstr;int);" & _ ; Retrieves the unique name for the GPO.
        "GetDisplayName        hResult(wstr;int);" & _ ; Retrieves the display name for the GPO.
        "SetDisplayName        hresult(wstr);" & _ ; Sets the display name for the GPO.
        "GetPath               hResult(wstr;int);" & _ ; Retrieves the path to the GPO.
        "GetDSPath             hresult(dword;wstr;int);" & _ ; Retrieves the Active Directory path to the root of the specified GPO section.
        "GetFileSysPath        hresult(dword;wstr;int);" & _ ; Retrieves the file system path (UNC format) to the root of the specified GPO section.
        "GetRegistryKey        hresult(dword;handle);" & _ ; Retrieves a handle to the root of the registry key for the specified GPO section.
        "GetOptions            hResult(dword*);" & _ ; Retrieves the options for the GPO.
        "SetOptions            hresult(dword;dword);" & _ ; Sets the options for the GPO.
        "GetType               hResult(dword*);" & _ ; Retrieves type information for the GPO being edited.
        "GetMachineName        hResult(wstr;int);" & _ ; Retrieves the computer name of the remote GPO.
        "GetPropertySheetPages hresult(ptr;uint*);" ; Retrieves the property sheet pages associated with the GPO.

Test()

Func Test()
    Local $iResult
    Local $oIGroupPolicy
    Local $aGpoType[5] = ["Local", "Remote", "Active Directory", "LocalUser", "LocalGroup"]

    $oIGroupPolicy = ObjCreateInterface($sCLSID_GroupPolicyObject, $sIID_IGroupPolicyObject, $dtag_IGroupPolicyObject)
    While True
        If Not IsObj($oIGroupPolicy) Then
            ConsoleWrite("Failed To Retrieve Interface")
            $iResult = $E_NOINTERFACE
            ExitLoop
        Else
            ConsoleWrite("Success: " & ObjName($oIGroupPolicy, 1) & @CRLF)
        EndIf

        Local $sLoc, $sPath, $sName, $iType
        $tKey = DllStructCreate("handle hKey")

        $iResult = $oIGroupPolicy.OpenLocalMachineGPO(BitOR($GPO_OPEN_LOAD_REGISTRY, $GPO_OPEN_READ_ONLY))
        If $iResult <> $S_OK Then ExitLoop

        $iResult = $oIGroupPolicy.GetDisplayName($sLoc, 65535)
        If $iResult <> $S_OK Then ExitLoop

        $iResult = $oIGroupPolicy.GetName($sName, 65535)
        If $iResult <> $S_OK Then ExitLoop

        ConsoleWrite($sLoc & " : " & $sName & @CRLF)

        $iResult = $oIGroupPolicy.GetPath($sPath, 65535)
        If $iResult <> $S_OK Then ExitLoop

        $iResult = $oIGroupPolicy.GetType($iType)
        If $iResult <> $S_OK Then ExitLoop

        ConsoleWrite($sPath & @CRLF)

        $iResult = $oIGroupPolicy.GetType($iType)
        If $iResult <> $S_OK Then ExitLoop

        ConsoleWrite("Type: " & $aGpoType[$iType] & @CRLF)

        $iResult = $oIGroupPolicy.GetRegistryKey($GPO_SECTION_USER, DllStructGetPtr($tKey))
        If $iResult <> $S_OK Then ExitLoop

        ConsoleWrite(_WinAPI_GetRegKeyNameByHandle(DllStructGetData($tKey, "hKey")) & @CRLF)
        ExitLoop
    WEnd
    Return SetError($iResult, 0, ($iResult = $S_OK))
EndFunc   ;==>Test

Note: Not well tested..

Edited by Bilgus
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...