ModemJunki

Help with zorphnogs Registry Policy File Editor

1 post in this topic

#1 ·  Posted (edited)

Edit: I extracted the functions I needed - Add and Delete - and made a much smaller file from the functions inside (attached here).
But I'd still like to fix the command line issue someday, this is a great effort by zorphnog for those of us who have to admin local GPOs for deployed systems!

Hi all (and zorphnog, if you're around, I will be trying to PM you on this topic).

I'm trying to use this Registry Policy File Editor script on Windows 7 x64.

 

The problem I'm having is that the commandline example which has spaces in the -v (value) and -d (data) doesn't work. It only writes the first word of the value or data into the policy file.

I tracked the problem down starting at the function _ParseOptions.

I compile and run the tool with command line:

gre -a -f=computer -k=Software\Policies\Microsoft\MyTestKey -v="My Test Value" -t REG_SZ -d="Registry Policy File editing"

It creates the array with extra entries for the items with spaces, like this:

[0]|12
[1]|--add
[2]|-f=computer
[3]|-k=Software\Policies\Microsoft\MyTestKey
[4]|-v=My
[5]|Test
[6]|Value
[7]|-t
[8]|REG_SZ
[9]|-d=Registry
[10]|Policy
[11]|File
[12]|editing

And that works but then in the .pol file the key name (-v) is "My" and the data (-d) is "Registry.

But when I try to change the way the array is created, the tool no longer parses the command line successfully (nothing gets written). E.g., I do this:

Local $local_CmdLine = StringSplit($cmdlineraw, "-", 1)
    _arraydelete($local_CmdLine, 1)
    $local_CmdLine[0] = Ubound($local_CmdLine,1) - 1
    For $i = 1 to $local_CmdLine[0]
        $local_CmdLine[$i] = "-" & $local_CmdLine[$i]
    Next
    For $j = 1 to $local_CmdLine[0]
        If StringInStr($local_CmdLine[$j], "-t") Then
            Local $s_typestring = StringSplit($local_CmdLine[$j]," ")
                _ArrayInsert($local_CmdLine, $j + 1, $s_typestring[2])
                $local_CmdLine[$j] = "-t"
            ;   ExitLoop
        EndIf
    Next

Now the output is like this:

[0]|6
[1]|-a 
[2]|-f=computer 
[3]|-k=Software\Policies\Microsoft\MyTestKey 
[4]|-v=My Test Value 
[5]|-t
[6]|REG_SZ
[7]|-d=Registry Policy File editing

And then the function _OptParse_GetOpts from the include _OptParse.au3 doesn't seem to be able to parse my new array.

And there I get lost - my array-fu is weak... I've spent a few hours on this and all I get is subscript errors and stuff.

Anyone able to have a look?
_____________________________________

Below is my modified file with the bare functions needed to add and delete local policy objects in the .pol files.

LocalGPOPolEdit_Include.au3

Edited by ModemJunki
Add file for sharing

Share this post


Link to post
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