Jump to content
Sign in to follow this  
John-Paul

Group Policy & How to Create Local

Recommended Posts

John-Paul

Can anyone help with local Group Policy setup.

I have been trying to create a very basic .au3 and while it works it seems so long winded and is alos producing a lot of SendKey errors at the end of the script.

Here's what i have done so far... I'm not a code guru so excuse the very basic nature of this.

=====

; Run CMD

Run("mmc")

; Wait for the MSC Console to become active - it is titled "Console1" on English systems

WinWaitActive("Console1")

Sleep(3000)

Send("!F") ; Alt+F = File menu

Send("M") ; M = Add/Remove Snap-in... menu

Send("!D") ; Alt+D = Add Snap-in required

Sleep(500)

Send("{DOWN 10}") ; DOWN = Tab DOWN 10 times and select "Group Policy" snap-in

Send("!A") ; Alt+A = Add selected policy

Send("{ENTER}") ; ENTER = ENTER and accept default Local Machine value

Send("!C") ; Alt+C = Close "Add Snap-in" dialog

Sleep(1000)

WinWaitActive("Add/Remove Snap-in")

Send("{ENTER}") ; ENTER = ENTER, close "Add/Remove Snap-in"

Sleep(5000)

WinWaitActive("Microsoft Management Console")

Send("{ENTER}")

Sleep(1000)

WinWaitActive("Console1")

Send("!F") ; Alt+F = File menu

; Save policy profile to - C:\Documents and Settings\Angelic Lover\Start Menu\Programs\Administrative Tools

Send("!S") ; Alt+S = Save

Sleep(500)

Send("LocalGP.msc") ; NAME = Name Plug-in "LocalGP.msc"

WinWaitActive("Console1")

WinClose("Console1")

========================

Thing is a am really trying to get the Startup and Shutdown features setup and using the SendKey process takes time to create as i have to go over each step - guess thats learning!

Any ideas?

jp

Share this post


Link to post
Share on other sites
herewasplato

There is probably a better way to do this task - perhaps writing directly to the registry - but below is my suggestion for the first part of your code:

AutoItSetOption("SendKeyDelay", 1) ;(milliseconds)
AutoItSetOption("WinWaitDelay", 1) ;(milliseconds)
AutoItSetOption("WinTitleMatchMode", 3) ;1-from the start, 2-any substring, 3-exact match
AutoItSetOption("TrayIconDebug", 1) ;0-off

Run("mmc")
; Wait for the MSC Console to become active - it is titled "Console1" on English systems
WinWait("Console1")
WinActivate("Console1")
WinWaitActive("Console1")
Send("!F"); Alt+F = File menu
Send("M"); M = Add/Remove Snap-in... menu


WinWait("Add/Remove Snap-in")
WinActivate("Add/Remove Snap-in")
WinWaitActive("Add/Remove Snap-in")
Send("!D"); Alt+D = Add Snap-in required


WinWait("Add Standalone Snap-in")
WinActivate("Add Standalone Snap-in")
WinWaitActive("Add Standalone Snap-in")
Send("g"); select "Group Policy" snap-in

I would suggest that you not send keys to a window unless it is active.

Using WinWait, WinActivate, WinWaitActive as shown above is a bit of overkill and there is an easier way to implement those three lines, but they help me run a script when another process could pop to the foreground during the script.

hope this helps......


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
SvenP

Hello,

I'm not quite sure about the purpose of your script. But when you just want to open the local group policy MMC, why not doing:

Run("mmc.exe " & @SystemDir & "\gpedit.msc")

(it can be used for any other *.msc file in your @SystemDir.)

Regards,

-Sven

Share this post


Link to post
Share on other sites
John-Paul

This helped so much - thanks.

I have a respect for the accuracy that you have placed in the Wait,Activate,WaitActive, feels good.

I have gone further along the same lines and have struck a snag, well for me its a snag.

I am now trying to get to the following menu and have tried

Send and several other options but it fails to work...

:"> "Console Root\Local Computer Policy\Computer Configuration\Windows Settings\Scripts (Startup/Shutdown)\Startup")

This is what Windows spy shows as text in the Policy Manager.

Any ideas other than the normal SendKey solution to get to this quickly.

jp

There is probably a better way to do this task - perhaps writing directly to the registry - but below is my suggestion for the first part of your code:

AutoItSetOption("SendKeyDelay", 1);(milliseconds)
AutoItSetOption("WinWaitDelay", 1);(milliseconds)
AutoItSetOption("WinTitleMatchMode", 3);1-from the start, 2-any substring, 3-exact match
AutoItSetOption("TrayIconDebug", 1);0-off

Run("mmc")
; Wait for the MSC Console to become active - it is titled "Console1" on English systems
WinWait("Console1")
WinActivate("Console1")
WinWaitActive("Console1")
Send("!F"); Alt+F = File menu
Send("M"); M = Add/Remove Snap-in... menu
WinWait("Add/Remove Snap-in")
WinActivate("Add/Remove Snap-in")
WinWaitActive("Add/Remove Snap-in")
Send("!D"); Alt+D = Add Snap-in required
WinWait("Add Standalone Snap-in")
WinActivate("Add Standalone Snap-in")
WinWaitActive("Add Standalone Snap-in")
Send("g"); select "Group Policy" snap-in

I would suggest that you not send keys to a window unless it is active.

Using WinWait, WinActivate, WinWaitActive as shown above is a bit of overkill and there is an easier way to implement those three lines, but they help me run a script when another process could pop to the foreground during the script.

hope this helps......

<{POST_SNAPBACK}>

Share this post


Link to post
Share on other sites
nobby

First of all, why don't you run

Run("mmc.exe " & @SystemDir & "\gpedit.msc")
instead of all the add snap ins etc, as suggested by SvenP.

The best way to get to you policy is going to be by sending DOWN, TAB and ENTER keys, with the appropriate SLEEP to allow for focus etc. I don't think the ControlSend will work under the MMC console.

You could write a registry with the necessary information. Any settings under the group policy will be written to the registry, for example a startup script goes under:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Startup\0\0]"Script"="c:\\windows\script.cmd"

"Parameters"=""

"ExecTime"=hex(B):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00

Apply a startup script manually to your local policy, then look in the registry for the changes it makes. From there, check the autoit help file for writing to the registry.

CheersNobby

Share this post


Link to post
Share on other sites
herewasplato

I am now trying to get to the following menu and have tried

Send and several other options but it fails to work...

:"> "Console Root\Local Computer Policy\Computer Configuration\Windows Settings\Scripts (Startup/Shutdown)\Startup")

This is what Windows spy shows as text in the Policy Manager.

jp

<{POST_SNAPBACK}>

Like others have said - There are probably better ways to accomplish this task (but that assumes that I understand what the task is) If your goal is to replicate group policy settings, then you can do it this way but there are several easier ways to do that. In any case - see the attached file....

EDIT typo

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
John-Paul

:idiot: My immense thanks to the last couple of posts, both have opened the door for me to move into this afresh.

The background to all this is to automate setting up the Group Policy to run several files I want to place in the startup and shutdown directories. Thus using AutoIT to do it has already proved its worth as the SendKey function in VBS is shacky and in AutoIT under my limited testing has shown 100% accuracy.

This is a standalone machine I am working with and is not connected to a network, so with multiple users I want certain scripts to run automatically and the best method to do this is through Group Policy.

From bootup if I have scripts that run automatically and I never leave and change users the system will retain the original settings, however if i logoff as one user and start another user then when i return to the first user the settings i had engaged at bootup will not run again, so by using the Group Policy Startup facility i can resolve this.

The process i refer to is a personal touch that i have engaged for my partitions by supplying them with individual icons and when i open Explorer the partitions all have varying icons, to do this i have a script that runs at bootup and as mentioned above they stay there until the system is shutdown or the user is changed. I have searched for registry tweaks to do this but have fialed to find anything on the net thus far and so i continue to use this method of delivery.

I hope this is helpful to understand where I am coming form and not over the top, as I feel I have been given such great support here and so my followup is a reflection of my respect to those here in this forum.

Maybe I will post the final script once completed, don't expect anything fancy, I'm bare-bones and functional.

jp

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.