Jump to content

send key tab jumps somewhere else


Go to solution Solved by ioa747,

Recommended Posts


I use AutoIt to change gpo and after I search in autoitscript I send(tab) to move the setting sometimes it jumps somewhere else and sometimes it jumps right place :
The wrong place it is jumped can send circled in red how can solve it?

cimage.png.e65a0b76a1035bd19e2ea643eb9e9768.pngimage.png.53a2222623cbfbb2b75fc411c1684542.png

The part from the code i send the tab

Sleep(3500)
    ;;Type search
    ControlSend("[TITLE:Filter Options]", "", "[CLASS:Edit; INSTANCE:1]", $mtric)
Sleep(3500)

Send("{ENTER}")
Send("{ENTER}")

Sleep(5500)
                Send("{tab}{down 20}{ENTER}")
                Sleep(2000)
        Send("{down 1}{ENTER}")
        Sleep(4000)


  While 1
    Local $TitleText = WinGetTitle("[ACTIVE]")
    If $mtric = $TitleText Then
            _selectDisEna($setting)
        ExitLoop
    Else
    Send("{N}")
    EndIf
    WEnd

 

Edited by gal9
Link to comment
Share on other sites

  • Solution
#RequireAdmin
#AutoIt3Wrapper_UseX64=y

Example()

Func Example()

    Local $hGPO = WinWaitActive("Local Group Policy Editor")
    ConsoleWrite("$hGPO=" & $hGPO & @CRLF)

    Local $hTreeView_1 = ControlGetHandle($hGPO, "", "SysTreeView321")

    ControlTreeView($hGPO, "", $hTreeView_1, "Expand", "#0|#0|#2")
    ControlTreeView($hGPO, "", $hTreeView_1, "Select", "#0|#0|#2")

    ControlFocus($hGPO, "", $hTreeView_1)
    ControlSend($hGPO, "", $hTreeView_1, "a")

    ControlFocus($hGPO, "", "AMCCustomTab1")
    ControlSend($hGPO, "", "AMCCustomTab1", "{RIGHT}")
;~  Sleep(1000)

    Local $hListView = ControlGetHandle($hGPO, "", "SysListView321")

    ControlFocus($hGPO, "", $hListView)

    ControlSend($hGPO, "", $hListView, "{HOME}")
    Sleep(2000)

    ControlSend($hGPO, "", $hListView, "{down 5}")
    Sleep(2000)
    

    Local $Item, $ItemCnt, $ItemTxt, $FindItem

    $ItemCnt = ControlListView($hGPO, "", $hListView, "GetItemCount")
    ConsoleWrite("$ItemCnt=" & $ItemCnt & @CRLF)

    $SelectedItem = ControlListView($hGPO, "", $hListView, "GetSelected")
    ConsoleWrite("$SelectedItem=" & $SelectedItem & @CRLF)


    $FindItem = ControlListView($hGPO, "", $hListView, "FindItem", "Allow remote server management through WinRM")
    ConsoleWrite("$FindItem=" & $FindItem & @CRLF)

    ControlListView($hGPO, "", $hListView, "Select", $FindItem)

    $SelectedItem = ControlListView($hGPO, "", $hListView, "GetSelected")
    ConsoleWrite("$SelectedItem=" & $SelectedItem & @CRLF)

    ControlSend($hGPO, "", $hListView, "{Enter}")


;~  ControlFocus($hGPO, "", "AMCCustomTab1")
;~  ControlSend($hGPO, "", "AMCCustomTab1", "{LEFT}")


EndFunc   ;==>Example

 

I know that I know nothing

Link to comment
Share on other sites

On 3/8/2023 at 8:58 PM, ioa747 said:
#RequireAdmin
#AutoIt3Wrapper_UseX64=y

Example()

Func Example()

    Local $hGPO = WinWaitActive("Local Group Policy Editor")
    ConsoleWrite("$hGPO=" & $hGPO & @CRLF)

    Local $hTreeView_1 = ControlGetHandle($hGPO, "", "SysTreeView321")

    ControlTreeView($hGPO, "", $hTreeView_1, "Expand", "#0|#0|#2")
    ControlTreeView($hGPO, "", $hTreeView_1, "Select", "#0|#0|#2")

    ControlFocus($hGPO, "", $hTreeView_1)
    ControlSend($hGPO, "", $hTreeView_1, "a")

    ControlFocus($hGPO, "", "AMCCustomTab1")
    ControlSend($hGPO, "", "AMCCustomTab1", "{RIGHT}")
;~  Sleep(1000)

    Local $hListView = ControlGetHandle($hGPO, "", "SysListView321")

    ControlFocus($hGPO, "", $hListView)

    ControlSend($hGPO, "", $hListView, "{HOME}")
    Sleep(2000)

    ControlSend($hGPO, "", $hListView, "{down 5}")
    Sleep(2000)
    

    Local $Item, $ItemCnt, $ItemTxt, $FindItem

    $ItemCnt = ControlListView($hGPO, "", $hListView, "GetItemCount")
    ConsoleWrite("$ItemCnt=" & $ItemCnt & @CRLF)

    $SelectedItem = ControlListView($hGPO, "", $hListView, "GetSelected")
    ConsoleWrite("$SelectedItem=" & $SelectedItem & @CRLF)


    $FindItem = ControlListView($hGPO, "", $hListView, "FindItem", "Allow remote server management through WinRM")
    ConsoleWrite("$FindItem=" & $FindItem & @CRLF)

    ControlListView($hGPO, "", $hListView, "Select", $FindItem)

    $SelectedItem = ControlListView($hGPO, "", $hListView, "GetSelected")
    ConsoleWrite("$SelectedItem=" & $SelectedItem & @CRLF)

    ControlSend($hGPO, "", $hListView, "{Enter}")


;~  ControlFocus($hGPO, "", "AMCCustomTab1")
;~  ControlSend($hGPO, "", "AMCCustomTab1", "{LEFT}")


EndFunc   ;==>Example

 

Hi, thank you very much!
this is my code now:
 

#include <Constants.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <GuiButton.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>


;==============================================================
; FUNCTION: _Example
; DESCRIPTION: This function opens the Group Policy Object Editor,
;   navigates to the specified policy setting, and changes its value
;   to the specified setting.
; PARAMETERS:
;   $metric - The name of the policy setting to be changed.
;   $setting - The value to which the policy setting should be changed.
; RETURNS: None.
;==============================================================



If Not $CmdLine[0] Then Exit Run(@AutoItExe & " " & @ScriptFullPath & " /Allow Adobe Flash /param2 disable")

MsgBox(4096, "message", "The setting  "& $CmdLine[1] & " set to " & $CmdLine[2] & " This box will time out in 3 seconds", 3)
    Sleep(5000)

        Local $mtric =$CmdLine[1]
;       "Allow Adobe Flash"
        Local $setting = $CmdLine[2]
        ;"disable"
_Example($mtric,$setting)
MsgBox(4096, "Test", "The setting saved and set "& $mtric & " to " & $setting & " This box will time out in 3 seconds", 3)
Exit(0)

; Finished!

Func _selectDisEna($setting)
        WinActivate($mtric)

    For $i = 5 To 1 Step -1
 If $setting = "disable" Or $setting ="Disabled" Then
Send("{d}")
Sleep(3000)
Send("{a}")
EndIf
If $setting = "enabled" Or $setting ="Enabled"  Then
Send("{e}")
Sleep(3000)
Send("{a}")
EndIf
If $setting = "not configured" Or $setting ="Not configured"  Then
Send("{c}")
EndIf
Send("{n}")
Next
Send("{ENTER}")
EndFunc

Func _Example($mtric,$setting)


    ; Run gpedit.msc
    ; Run("c:\Windows\system32\mmc.exe c:\Windows\system32\gpedit.msc /a")
    ;Run("c:\Windows\system32\mmc.exe C:\Users\" & @USERNAME &"\Desktop\script\gpedit_v1.msc /a")
        Run("c:\Windows\system32\mmc.exe " & "C:\share\open_close_gpedit\gpedit_v1.msc /a")

    Sleep(2500)

    WinWaitActive("[CLASS:MMCMainFrame]")
    WinActivate("Group Policy Object Editor")


    Sleep(500)

    Send("{ALT}{A}{O}")
    While ControlGetFocus("[TITLE:Filter Options]") = ""
        sleep(1)
    WEnd
    WinWaitActive("[TITLE:Filter Options]")

    Sleep(3500)

If ControlCommand("Filter Options", "Enable &Keyword Filters", "Button2", "IsChecked", "") = 0 Then
    Send("{ALT down}{K}{F}{ALT up}")
Else
    Send("{ALT down}{F}{ALT up}")
EndIf

Sleep(3500)
    ;;Type search
    ControlSend("[TITLE:Filter Options]", "", "[CLASS:Edit; INSTANCE:1]", $mtric)
Sleep(3500)

Send("{ENTER}")
Send("{ENTER}")

Sleep(5500)
                Send("{tab}{down 20}{ENTER}")
                Sleep(2000)
        Send("{down 1}{ENTER}")
        Sleep(4000)


  While 1
    Local $TitleText = WinGetTitle("[ACTIVE]")
    If $mtric = $TitleText Then
            _selectDisEna($setting)
        ExitLoop
    Else
    Send("{N}")
    EndIf
    WEnd

Sleep(3500)




;Send ("{Ctrl}{S}")
;Send("^s")
;_Validation($mtric,$setting)
Sleep(3500)

WinWaitActive("[CLASS:MMCMainFrame]")
Send("{ALT down}{F4}{ALT up}")
Sleep(2000)
Send ("{N}")

;MsgBox(4096, "Test", "The setting saved and set "& $mtric & " to " & $setting & " This box will time out in 10 seconds", 10)

EndFunc

this is my code after change 

#include <Constants.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <GuiButton.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>


;==============================================================
; FUNCTION: _Example
; DESCRIPTION: This function opens the Group Policy Object Editor,
;   navigates to the specified policy setting, and changes its value
;   to the specified setting.
; PARAMETERS:
;   $metric - The name of the policy setting to be changed.
;   $setting - The value to which the policy setting should be changed.
; RETURNS: None.
;==============================================================



If Not $CmdLine[0] Then Exit Run(@AutoItExe & " " & @ScriptFullPath & " /Allow Adobe Flash /param2 disable")

MsgBox(4096, "message", "The setting  "& $CmdLine[1] & " set to " & $CmdLine[2] & " This box will time out in 3 seconds", 3)
    Sleep(5000)

        Local $mtric =$CmdLine[1]
;       "Allow Adobe Flash"
        Local $setting = $CmdLine[2]
        ;"disable"
_Example($mtric,$setting)
MsgBox(4096, "Test", "The setting saved and set "& $mtric & " to " & $setting & " This box will time out in 3 seconds", 3)
Exit(0)

; Finished!

Func _selectDisEna($setting)
        WinActivate($mtric)

    For $i = 5 To 1 Step -1
 If $setting = "disable" Or $setting ="Disabled" Then
Send("{d}")
Sleep(3000)
Send("{a}")
EndIf
If $setting = "enabled" Or $setting ="Enabled"  Then
Send("{e}")
Sleep(3000)
Send("{a}")
EndIf
If $setting = "not configured" Or $setting ="Not configured"  Then
Send("{c}")
EndIf
Send("{n}")
Next
Send("{ENTER}")
EndFunc

Func _Example($mtric,$setting)


    ; Run gpedit.msc
    ; Run("c:\Windows\system32\mmc.exe c:\Windows\system32\gpedit.msc /a")
    ;Run("c:\Windows\system32\mmc.exe C:\Users\" & @USERNAME &"\Desktop\script\gpedit_v1.msc /a")
        Run("c:\Windows\system32\mmc.exe " & "C:\share\open_close_gpedit\gpedit_v1.msc /a")

    Sleep(2500)


    Local $hGPO = WinWaitActive("Local Group Policy Editor")
    ConsoleWrite("$hGPO=" & $hGPO & @CRLF)

    Local $hTreeView_1 = ControlGetHandle($hGPO, "", "SysTreeView321")


    Sleep(500)
    ControlSend($hGPO, "", $hTreeView_1, "{ALT}{A}{O}")
    ControlFocus($hGPO, "", "[TITLE:Filter Options]")

    WinWaitActive("[TITLE:Filter Options]")

    Sleep(3500)

If ControlCommand("Filter Options", "Enable &Keyword Filters", "Button2", "IsChecked", "") = 0 Then
    Send("{ALT down}{K}{F}{ALT up}")
Else
    Send("{ALT down}{F}{ALT up}")
EndIf

Sleep(3500)
    ;;Type search
    ControlSend("[TITLE:Filter Options]", "", "[CLASS:Edit; INSTANCE:1]", $mtric)
Sleep(3500)
    ControlSend("[TITLE:Filter Options]", "", "[CLASS:Edit; INSTANCE:1]", "{ENTER}")


    ControlFocus($hGPO, "", $hTreeView_1)
    ControlSend($hGPO, "", $hTreeView_1, "a")

    ControlFocus($hGPO, "", "AMCCustomTab1")
    ControlSend($hGPO, "", "AMCCustomTab1", "{RIGHT}")
;~  Sleep(1000)

    Local $hListView = ControlGetHandle($hGPO, "", "SysListView321")

    ControlFocus($hGPO, "", $hListView)

    ControlSend($hGPO, "", $hListView, "{HOME}")
    Sleep(2000)

    ControlSend($hGPO, "", $hListView, "{down 5}")
    Sleep(2000)

   Local $Item, $ItemCnt, $ItemTxt, $FindItem

    $ItemCnt = ControlListView($hGPO, "", $hListView, "GetItemCount")
    ConsoleWrite("$ItemCnt=" & $ItemCnt & @CRLF)

    $SelectedItem = ControlListView($hGPO, "", $hListView, "GetSelected")
    ConsoleWrite("$SelectedItem=" & $SelectedItem & @CRLF)


    $FindItem = ControlListView($hGPO, "", $hListView, "FindItem", $mtric)
    ConsoleWrite("$FindItem=" & $FindItem & @CRLF)

    ControlListView($hGPO, "", $hListView, "Select", $FindItem)

    $SelectedItem = ControlListView($hGPO, "", $hListView, "GetSelected")
    ConsoleWrite("$SelectedItem=" & $SelectedItem & @CRLF)

    ControlSend($hGPO, "", $hListView, "{Enter}")



Sleep(3500)




;Send ("{Ctrl}{S}")
;Send("^s")
;_Validation($mtric,$setting)
Sleep(3500)

WinWaitActive("[CLASS:MMCMainFrame]")
Send("{ALT down}{F4}{ALT up}")
Sleep(2000)
Send ("{N}")

;MsgBox(4096, "Test", "The setting saved and set "& $mtric & " to " & $setting & " This box will time out in 10 seconds", 10)

EndFunc

but It's stuck in this part:image.thumb.png.75926d2ec3595722984ee103b38cf9b8.png


I have another question:

can get this path? in Autoit i want to compare There are some with the same name but a different path
 image.thumb.png.c38f848cabe6841bf5a566403b1d3d5c.png

 

Link to comment
Share on other sites

26 minutes ago, ioa747 said:

what do I have to do to see it too?

give me the value to go

image.thumb.png.d9e9eb8f31193b6c2ea203f829dbaa5f.png
for example, after i search the result and i want only the first change with the path '\Google\Google Chrome\Password manager' , so I will send another parameter but how i can get the path text to compare? with path and another parameter i will send

Edited by gal9
Link to comment
Share on other sites

1 minute ago, ioa747 said:

you should press enter to open the new window where you can see more details depending on the parameter (value)

image.png.29f141ca3ec481a8e55215ff2f8c600b.png

ok l know  about send enter but, i have two different questions:
1. before i send enter i want to get the path I want to know what the path is. if it is not what I expect I move to next... but I don't succeed to catch the path text 
2. after I send enter and open the screen how i can get the screen i want to send(d) or send (e) if disabled or enabled but i want to use ControlSend I don't know how to use ControlSend. 
Thank you very much for this information it really helps me!

Link to comment
Share on other sites

As example how to get with controls

#RequireAdmin
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator


Example()

Func Example()
;work case
;find the item "Add primary intranet search location"
;and set to "WWW.google.com"

    ShellExecute("C:\WINDOWS\SYSTEM32\MMC.EXE", "C:\WINDOWS\SYSTEM32\GPEDIT.MSC")

    ;Retrieves the 'Local Group Policy Editor' window handle
    Local $hGPO = WinWaitActive("Local Group Policy Editor")
    ConsoleWrite("$hGPO=" & $hGPO & @CRLF)

    ;Retrieves the SysTreeView321 control handle
    Local $hTreeView_1 = ControlGetHandle($hGPO, "", "SysTreeView321")

    ControlTreeView($hGPO, "", $hTreeView_1, "Expand", "#0|#0|#2")
    ControlTreeView($hGPO, "", $hTreeView_1, "Select", "#0|#0|#2")
    ControlFocus($hGPO, "", $hTreeView_1)
    ControlSend($hGPO, "", $hTreeView_1, "a")

    ;at the bottom tabs we go right to the standard tab
    ControlFocus($hGPO, "", "AMCCustomTab1")
    ControlSend($hGPO, "", "AMCCustomTab1", "{RIGHT}")
    Sleep(300)

    ;Retrieves the SysListView321 control handle
    Local $hListView = ControlGetHandle($hGPO, "", "SysListView321")

    ;Sets the focus to SysListView321
    ControlFocus($hGPO, "", $hListView)

    Local $Item, $ItemCnt, $ItemTxt, $FindItem

    $SelectedItem = ControlListView($hGPO, "", $hListView, "GetSelected")
    ConsoleWrite("$SelectedItem=" & $SelectedItem & @CRLF)

    ;find the item "Add primary intranet search location"
    Local $FindTxt = "Add primary intranet search location"
    $FindItem = ControlListView($hGPO, "", $hListView, "FindItem", $FindTxt)
    ConsoleWrite("$FindItem=" & $FindItem & @CRLF)

    ;If not found then exit
    If $FindItem = -1 Then
        ConsoleWrite("not found the entry:" & $FindTxt & @CRLF)
        Exit
    EndIf

    ;select the found item
    ControlListView($hGPO, "", $hListView, "Select", $FindItem)

    ;and send enter to open
    ControlSend($hGPO, "", $hListView, "{Enter}")
    Sleep(300)

    Local $sWinTitle = WinGetTitle("[ACTIVE]")
    ConsoleWrite("$sWinTitle=" & $sWinTitle & @CRLF)

    ;If WinTitle not $FindTxt then exit
    If $sWinTitle <> $FindTxt Then
        ConsoleWrite($sWinTitle & " not match to " & $FindTxt & @CRLF)
        Exit
    EndIf

    ;Retrieves the 'Editor' window handle
    Local $hGPOedit = WinWaitActive($sWinTitle)

    ;Click at the Enabled
    ControlClick($hGPOedit, "", "WindowsForms10.BUTTON.app.0.297b065_r69_ad14")

    ;set the text in the edit
    ControlSetText($hGPOedit, "", "WindowsForms10.EDIT.app.0.297b065_r69_ad13", "WWW.google.com")

    ;Click ok
    ControlClick($hGPOedit, "", "WindowsForms10.BUTTON.app.0.297b065_r69_ad16")

EndFunc   ;==>Example

 

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

16 hours ago, ioa747 said:

As example how to get with controls

#RequireAdmin
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator


Example()

Func Example()
;work case
;find the item "Add primary intranet search location"
;and set to "WWW.google.com"

    ShellExecute("C:\WINDOWS\SYSTEM32\MMC.EXE", "C:\WINDOWS\SYSTEM32\GPEDIT.MSC")

    ;Retrieves the 'Local Group Policy Editor' window handle
    Local $hGPO = WinWaitActive("Local Group Policy Editor")
    ConsoleWrite("$hGPO=" & $hGPO & @CRLF)

    ;Retrieves the SysTreeView321 control handle
    Local $hTreeView_1 = ControlGetHandle($hGPO, "", "SysTreeView321")

    ControlTreeView($hGPO, "", $hTreeView_1, "Expand", "#0|#0|#2")
    ControlTreeView($hGPO, "", $hTreeView_1, "Select", "#0|#0|#2")
    ControlFocus($hGPO, "", $hTreeView_1)
    ControlSend($hGPO, "", $hTreeView_1, "a")

    ;at the bottom tabs we go right to the standard tab
    ControlFocus($hGPO, "", "AMCCustomTab1")
    ControlSend($hGPO, "", "AMCCustomTab1", "{RIGHT}")
    Sleep(300)

    ;Retrieves the SysListView321 control handle
    Local $hListView = ControlGetHandle($hGPO, "", "SysListView321")

    ;Sets the focus to SysListView321
    ControlFocus($hGPO, "", $hListView)

    Local $Item, $ItemCnt, $ItemTxt, $FindItem

    $SelectedItem = ControlListView($hGPO, "", $hListView, "GetSelected")
    ConsoleWrite("$SelectedItem=" & $SelectedItem & @CRLF)

    ;find the item "Add primary intranet search location"
    Local $FindTxt = "Add primary intranet search location"
    $FindItem = ControlListView($hGPO, "", $hListView, "FindItem", $FindTxt)
    ConsoleWrite("$FindItem=" & $FindItem & @CRLF)

    ;If not found then exit
    If $FindItem = -1 Then
        ConsoleWrite("not found the entry:" & $FindTxt & @CRLF)
        Exit
    EndIf

    ;select the found item
    ControlListView($hGPO, "", $hListView, "Select", $FindItem)

    ;and send enter to open
    ControlSend($hGPO, "", $hListView, "{Enter}")
    Sleep(300)

    Local $sWinTitle = WinGetTitle("[ACTIVE]")
    ConsoleWrite("$sWinTitle=" & $sWinTitle & @CRLF)

    ;If WinTitle not $FindTxt then exit
    If $sWinTitle <> $FindTxt Then
        ConsoleWrite($sWinTitle & " not match to " & $FindTxt & @CRLF)
        Exit
    EndIf

    ;Retrieves the 'Editor' window handle
    Local $hGPOedit = WinWaitActive($sWinTitle)

    ;Click at the Enabled
    ControlClick($hGPOedit, "", "WindowsForms10.BUTTON.app.0.297b065_r69_ad14")

    ;set the text in the edit
    ControlSetText($hGPOedit, "", "WindowsForms10.EDIT.app.0.297b065_r69_ad13", "WWW.google.com")

    ;Click ok
    ControlClick($hGPOedit, "", "WindowsForms10.BUTTON.app.0.297b065_r69_ad16")

EndFunc   ;==>Example

 

OK but i want use Controlsend key not using ControlClick. so i need using Something like that? 

Local $sWinTitle = WinGetTitle("[ACTIVE]")
    ConsoleWrite("$sWinTitle=" & $sWinTitle & @CRLF)
    Local $hGPOedit = WinWaitActive($sWinTitle)

 If $setting = "disable" Or $setting ="Disabled" Then
    ControlSend($hGPOedit, "", "{d}")
    ControlSend($hGPOedit, "", "{a}")
EndIf
If $setting = "enabled" Or $setting ="Enabled"  Then
    ControlSend($hGPOedit, "", "{e}")

i get this error
image.thumb.png.730a97716449a327eccfdf3330ec45b7.png
and another question how i can get the path? into a variableimage.thumb.png.28c8aa9eb4e18cdba94b0fcf3bfac80a.png

image.png

Edited by gal9
Link to comment
Share on other sites

this was to see how to use the control

the ControlClick() is to enable\ disable things, or click the ok

of course you can use the ControlSend to send key

with how i can get the path I don't know, I didn't deal with it. maybe tomorrow

But I did that

#RequireAdmin
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator

Local $sPath = "\Computer Configuration\Administrative Templates\Windows Components\OneDrive"
Local $sItem = "Prevent OneDrive from generating network traffic until the user signs in to OneDrive"
Local $sResult = _GroupPolicy($sPath, $sItem)


Exit

; #FUNCTION# ;---------------------------------------------------------------------------
; Name...........: _GroupPolicy()
; Description ...: Opens and uses the Group Policy Editor to configure the given settings
; Syntax.........: _GroupPolicy($sPolicyPath, $sPolicyItem [, $iMode = 2])
; Parameters ....: $sPolicyPath     - The path of nodes to navigate
;                  $sPolicyItem     - The Item/option to navigate/edit
;                  $iMode           - 0=Disabled, 1=Enabled, 2=Configured
; Author ........: ioa747
; Notes .........: Testet on Win10(22H2) with AutoIt(3.3.16.1)
;----------------------------------------------------------------------------------------
Func _GroupPolicy($sPolicyPath, $sPolicyItem, $iMode = 2)

    If Not WinExists("Local Group Policy Editor") Then
        ShellExecute("C:\WINDOWS\SYSTEM32\MMC.EXE", "C:\WINDOWS\SYSTEM32\GPEDIT.MSC")
        WinWait("Local Group Policy Editor", '', 5)
    EndIf

    Local $hGPO = WinActivate("Local Group Policy Editor")
    ConsoleWrite("$hGPO=" & $hGPO & @CRLF)

    ;Retrieves the SysTreeView321 control handle
    Local $hTreeView_1 = ControlGetHandle($hGPO, "", "SysTreeView321")

    $sPolicyPath = "Local Computer Policy" & $sPolicyPath
    ConsoleWrite("$sPolicyPath=" & $sPolicyPath & @CRLF)
    ConsoleWrite("$sPolicyItem=" & $sPolicyItem & @CRLF)

    Local $aPath = StringSplit($sPolicyPath, "\", 1)
    Local $tmpPath = ""
    For $i = 1 To $aPath[0]
        $tmpPath &= $aPath[$i] & "|"
        ConsoleWrite("$tmpPath=" & StringTrimRight($tmpPath, 1) & @CRLF)
        ControlTreeView($hGPO, "", $hTreeView_1, "Expand", StringTrimRight($tmpPath, 1))
        ControlTreeView($hGPO, "", $hTreeView_1, "Select", StringTrimRight($tmpPath, 1))
        Sleep(50)
    Next

    ;at the bottom tabs we go right to the standard tab
    ControlFocus($hGPO, "", "AMCCustomTab1")
    ControlSend($hGPO, "", "AMCCustomTab1", "{RIGHT}")

    ;Retrieves the SysListView321 control handle
    Local $hListView = ControlGetHandle($hGPO, "", "SysListView321")

    ;Sets the focus to SysListView321
    ControlFocus($hGPO, "", $hListView)

    ;find the item
    Local $FindItem = ControlListView($hGPO, "", $hListView, "FindItem", $sPolicyItem)
    ConsoleWrite("$FindItem=" & $FindItem & @CRLF)

    ;If not found then Return Error
    If $FindItem = -1 Then
        ConsoleWrite("not found the entry:'" & $sPolicyItem & "'" & @CRLF)
        Return SetError(1, 0, "")
    EndIf

    ;select the found item
    ControlListView($hGPO, "", $hListView, "Select", $FindItem)
    Sleep(50)

    ;and send enter to open
    ControlSend($hGPO, '', $hListView, '{ENTER}')
    ;Return $sPolicyItem

    ;give the window some time to appear
    Sleep(300)

    Local $sEditTitle = WinGetTitle("[ACTIVE]")
    ConsoleWrite("$sEditTitle=" & $sEditTitle & @CRLF)

    ;If WinTitle not $FindTxt then Return Error
    If $sEditTitle <> $sPolicyItem Then
        ConsoleWrite($sEditTitle & " not match to " & $sPolicyItem & @CRLF)
        Return SetError(1, 0, "")
    EndIf

    ;Retrieves the 'Editor' window handle
    Local $hGPOedit = WinWaitActive($sEditTitle)

    Switch $iMode
        Case 0 ;Disabled
            ControlClick($hGPOedit, "", "WindowsForms10.BUTTON.app.0.297b065_r69_ad15")
            ControlClick($hGPOedit, "", "WindowsForms10.BUTTON.app.0.297b065_r69_ad16")
            ConsoleWrite("$iMode=Disabled" & @CRLF)

        Case 1 ;Enabled
            ControlClick($hGPOedit, "", "WindowsForms10.BUTTON.app.0.297b065_r69_ad14")
            ControlClick($hGPOedit, "", "WindowsForms10.BUTTON.app.0.297b065_r69_ad16")
            ConsoleWrite("$iMode=Enabled" & @CRLF)

        Case 2 ;Configured
            ControlClick($hGPOedit, "", "WindowsForms10.BUTTON.app.0.297b065_r69_ad14")
            ConsoleWrite("$iMode=Configured" & @CRLF)

    EndSwitch


EndFunc   ;==>_GroupPolicy
;----------------------------------------------------------------------------------------

which you can modify and bring to your measure :)

I know that I know nothing

Link to comment
Share on other sites

3 hours ago, ioa747 said:

this was to see how to use the control

the ControlClick() is to enable\ disable things, or click the ok

of course you can use the ControlSend to send key

with how i can get the path I don't know, I didn't deal with it. maybe tomorrow

But I did that

#RequireAdmin
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator

Local $sPath = "\Computer Configuration\Administrative Templates\Windows Components\OneDrive"
Local $sItem = "Prevent OneDrive from generating network traffic until the user signs in to OneDrive"
Local $sResult = _GroupPolicy($sPath, $sItem)


Exit

; #FUNCTION# ;---------------------------------------------------------------------------
; Name...........: _GroupPolicy()
; Description ...: Opens and uses the Group Policy Editor to configure the given settings
; Syntax.........: _GroupPolicy($sPolicyPath, $sPolicyItem [, $iMode = 2])
; Parameters ....: $sPolicyPath     - The path of nodes to navigate
;                  $sPolicyItem     - The Item/option to navigate/edit
;                  $iMode           - 0=Disabled, 1=Enabled, 2=Configured
; Author ........: ioa747
; Notes .........: Testet on Win10(22H2) with AutoIt(3.3.16.1)
;----------------------------------------------------------------------------------------
Func _GroupPolicy($sPolicyPath, $sPolicyItem, $iMode = 2)

    If Not WinExists("Local Group Policy Editor") Then
        ShellExecute("C:\WINDOWS\SYSTEM32\MMC.EXE", "C:\WINDOWS\SYSTEM32\GPEDIT.MSC")
        WinWait("Local Group Policy Editor", '', 5)
    EndIf

    Local $hGPO = WinActivate("Local Group Policy Editor")
    ConsoleWrite("$hGPO=" & $hGPO & @CRLF)

    ;Retrieves the SysTreeView321 control handle
    Local $hTreeView_1 = ControlGetHandle($hGPO, "", "SysTreeView321")

    $sPolicyPath = "Local Computer Policy" & $sPolicyPath
    ConsoleWrite("$sPolicyPath=" & $sPolicyPath & @CRLF)
    ConsoleWrite("$sPolicyItem=" & $sPolicyItem & @CRLF)

    Local $aPath = StringSplit($sPolicyPath, "\", 1)
    Local $tmpPath = ""
    For $i = 1 To $aPath[0]
        $tmpPath &= $aPath[$i] & "|"
        ConsoleWrite("$tmpPath=" & StringTrimRight($tmpPath, 1) & @CRLF)
        ControlTreeView($hGPO, "", $hTreeView_1, "Expand", StringTrimRight($tmpPath, 1))
        ControlTreeView($hGPO, "", $hTreeView_1, "Select", StringTrimRight($tmpPath, 1))
        Sleep(50)
    Next

    ;at the bottom tabs we go right to the standard tab
    ControlFocus($hGPO, "", "AMCCustomTab1")
    ControlSend($hGPO, "", "AMCCustomTab1", "{RIGHT}")

    ;Retrieves the SysListView321 control handle
    Local $hListView = ControlGetHandle($hGPO, "", "SysListView321")

    ;Sets the focus to SysListView321
    ControlFocus($hGPO, "", $hListView)

    ;find the item
    Local $FindItem = ControlListView($hGPO, "", $hListView, "FindItem", $sPolicyItem)
    ConsoleWrite("$FindItem=" & $FindItem & @CRLF)

    ;If not found then Return Error
    If $FindItem = -1 Then
        ConsoleWrite("not found the entry:'" & $sPolicyItem & "'" & @CRLF)
        Return SetError(1, 0, "")
    EndIf

    ;select the found item
    ControlListView($hGPO, "", $hListView, "Select", $FindItem)
    Sleep(50)

    ;and send enter to open
    ControlSend($hGPO, '', $hListView, '{ENTER}')
    ;Return $sPolicyItem

    ;give the window some time to appear
    Sleep(300)

    Local $sEditTitle = WinGetTitle("[ACTIVE]")
    ConsoleWrite("$sEditTitle=" & $sEditTitle & @CRLF)

    ;If WinTitle not $FindTxt then Return Error
    If $sEditTitle <> $sPolicyItem Then
        ConsoleWrite($sEditTitle & " not match to " & $sPolicyItem & @CRLF)
        Return SetError(1, 0, "")
    EndIf

    ;Retrieves the 'Editor' window handle
    Local $hGPOedit = WinWaitActive($sEditTitle)

    Switch $iMode
        Case 0 ;Disabled
            ControlClick($hGPOedit, "", "WindowsForms10.BUTTON.app.0.297b065_r69_ad15")
            ControlClick($hGPOedit, "", "WindowsForms10.BUTTON.app.0.297b065_r69_ad16")
            ConsoleWrite("$iMode=Disabled" & @CRLF)

        Case 1 ;Enabled
            ControlClick($hGPOedit, "", "WindowsForms10.BUTTON.app.0.297b065_r69_ad14")
            ControlClick($hGPOedit, "", "WindowsForms10.BUTTON.app.0.297b065_r69_ad16")
            ConsoleWrite("$iMode=Enabled" & @CRLF)

        Case 2 ;Configured
            ControlClick($hGPOedit, "", "WindowsForms10.BUTTON.app.0.297b065_r69_ad14")
            ConsoleWrite("$iMode=Configured" & @CRLF)

    EndSwitch


EndFunc   ;==>_GroupPolicy
;----------------------------------------------------------------------------------------

which you can modify and bring to your measure :)

i send a partmter to autoit $mtric and $setting i call from cmd like ' poledit.au3  "Allow Adobe Flash" "enabled" ' 
this is my code:

#RequireAdmin
#AutoIt3Wrapper_UseX64=y
#include <Constants.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <GuiButton.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>


;==============================================================
; FUNCTION: _Example
; DESCRIPTION: This function opens the Group Policy Object Editor,
;   navigates to the specified policy setting, and changes its value
;   to the specified setting.
; PARAMETERS:
;   $metric - The name of the policy setting to be changed.
;   $setting - The value to which the policy setting should be changed.
; RETURNS: None.
;==============================================================



If Not $CmdLine[0] Then Exit Run(@AutoItExe & " " & @ScriptFullPath & " /Allow Adobe Flash /param2 disable")

MsgBox(4096, "message", "The setting  "& $CmdLine[1] & " set to " & $CmdLine[2] & " This box will time out in 3 seconds", 3)
    Sleep(5000)

        Local $mtric =$CmdLine[1]
;       "Allow Adobe Flash"
        Local $setting = $CmdLine[2]
        ;"disable"
_Example($mtric,$setting)
MsgBox(4096, "Test", "The setting saved and set "& $mtric & " to " & $setting & " This box will time out in 3 seconds", 3)
Exit(0)

; Finished!

Func _selectDisEna($setting)
    Local $sEditTitle = WinGetTitle("[ACTIVE]")
    ConsoleWrite("$sEditTitle=" & $sEditTitle & @CRLF)
    Local $hGPOedit = WinWaitActive($sEditTitle)

    For $i = 5 To 1 Step -1
 If $setting = "disable" Or $setting ="Disabled" Then
Send("{d}")
Sleep(3000)
Send("{a}")
EndIf
If $setting = "enabled" Or $setting ="Enabled"  Then
Send("{e}")
Sleep(3000)
Send("{a}")
EndIf
If $setting = "not configured" Or $setting ="Not configured"  Then
Send("{c}")
EndIf
Send("{n}")
Next
Send("{ENTER}")
EndFunc



Func _Example($mtric,$setting)


    ; Run gpedit.msc
    ; Run("c:\Windows\system32\mmc.exe c:\Windows\system32\gpedit.msc /a")
    ;Run("c:\Windows\system32\mmc.exe C:\Users\" & @USERNAME &"\Desktop\script\gpedit_v1.msc /a")
        Run("c:\Windows\system32\mmc.exe " & "C:\share\open_close_gpedit\gpedit_v1.msc /a")

    Sleep(2500)


    Local $hGPO = WinWaitActive("Local Group Policy Editor")
    ConsoleWrite("$hGPO=" & $hGPO & @CRLF)

    Local $hTreeView_1 = ControlGetHandle($hGPO, "", "SysTreeView321")


    Sleep(500)
    ControlSend($hGPO, "", $hTreeView_1, "{ALT}{A}{O}")
    ControlFocus($hGPO, "", "[TITLE:Filter Options]")

    WinWaitActive("[TITLE:Filter Options]")

    Sleep(3500)

If ControlCommand("Filter Options", "Enable &Keyword Filters", "Button2", "IsChecked", "") = 0 Then
    Send("{ALT down}{K}{F}{ALT up}")
Else
    Send("{ALT down}{F}{ALT up}")
EndIf

Sleep(3500)
    ;;Type search
    ControlSend("[TITLE:Filter Options]", "", "[CLASS:Edit; INSTANCE:1]", $mtric)
Sleep(3500)
    ControlSend("[TITLE:Filter Options]", "", "[CLASS:Edit; INSTANCE:1]", "{ENTER}")


    ControlFocus($hGPO, "", $hTreeView_1)
    ControlSend($hGPO, "", $hTreeView_1, "a")

    ControlFocus($hGPO, "", "AMCCustomTab1")
    ControlSend($hGPO, "", "AMCCustomTab1", "{RIGHT}")
;~  Sleep(1000)

    Local $hListView = ControlGetHandle($hGPO, "", "SysListView321")

    ControlFocus($hGPO, "", $hListView)

    ControlSend($hGPO, "", $hListView, "{HOME}")
    Sleep(2000)

    ControlSend($hGPO, "", $hListView, "{down 5}")
    Sleep(2000)

   Local $Item, $ItemCnt, $ItemTxt, $FindItem

    $ItemCnt = ControlListView($hGPO, "", $hListView, "GetItemCount")
    ConsoleWrite("$ItemCnt=" & $ItemCnt & @CRLF)

    $SelectedItem = ControlListView($hGPO, "", $hListView, "GetSelected")
    ConsoleWrite("$SelectedItem=" & $SelectedItem & @CRLF)


    $FindItem = ControlListView($hGPO, "", $hListView, "FindItem", $mtric)
    ConsoleWrite("$FindItem=" & $FindItem & @CRLF)

    ControlListView($hGPO, "", $hListView, "Select", $FindItem)

    $SelectedItem = ControlListView($hGPO, "", $hListView, "GetSelected")
    ConsoleWrite("$SelectedItem=" & $SelectedItem & @CRLF)

    ControlSend($hGPO, "", $hListView, "{Enter}")



Sleep(3500)

_selectDisEna($setting)


;Send ("{Ctrl}{S}")
;Send("^s")
;_Validation($mtric,$setting)
Sleep(3500)
 WinWaitActive("[CLASS:MMCMainFrame]")


ControlSend($hGPO, "", $hTreeView_1, "{ALT down}{F4}{ALT up}")
Sleep(2000)
    Local $hGPO = WinWaitActive("Microsoft Management Console")
ConsoleWrite("$sEditTitle=" & $sEditTitle & @CRLF)
Local $hGPOedit = WinWaitActive($sEditTitle)
Send ("{N}")

;MsgBox(4096, "Test", "The setting saved and set "& $mtric & " to " & $setting & " This box will time out in 10 seconds", 10)

EndFunc

if you can help me to Replace send instead of controlsend and improve my code using ControlSend I am trying to do this without success.  

And because I don't know what a specific path is, so I mark them all in the, disable or enable That's why it's in for loop. 

And another thing I'm trying to do is send another path parameter to compare....
for  example  image.thumb.png.06b1358d742291e4c4dad5a2a26900c5.png
 

Edited by gal9
Link to comment
Share on other sites

And because I don't know what a specific path

The paths you can export as txt file

select All Settings and then  right click export list

if you can help me to Replace send instead of controlsend and improve my code using ControlSend I am trying to do this without success. 

which control did you trying  without success ?

we want three things

  1. win title
  2.  ClassnameNN
  3.  String to send

ControlSend ( 1, "",  2,  3)

 

 

Edited by ioa747
del image

I know that I know nothing

Link to comment
Share on other sites

try it carefully, I can't test it on me because I don't have your data, I tried it on other data, I brought it to you (I believe) as you wanted, I also put the additional information about the items  text, but it need  your own hand to arrange it , as you want

within the function
Func _selectDisEna($setting)
you have     For $i = 5 To 1 Step -1    where does this come from? is it always 5? or is it only for the Adobe

 

#RequireAdmin
#AutoIt3Wrapper_UseX64=y
#include <Constants.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <GuiButton.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>


;==============================================================
; FUNCTION: _Example
; DESCRIPTION: This function opens the Group Policy Object Editor,
;   navigates to the specified policy setting, and changes its value
;   to the specified setting.
; PARAMETERS:
;   $metric - The name of the policy setting to be changed.
;   $setting - The value to which the policy setting should be changed.
; RETURNS: None.
;==============================================================

Global $iParams = $CmdLine[0]

;If Not file parameters then as example set 3 parameters
If Not $iParams Then
    Global $iParams[3] = [2, "Allow Adobe Flash", "disable"]
Else
    $iParams = $CmdLine
EndIf

MsgBox(4096, "message", "The setting  " & $iParams[1] & " set to " & $iParams[2] & " This box will time out in 3 seconds", 3)
Sleep(5000)

Local $mtric = $iParams[1]
;       "Allow Adobe Flash"
Local $setting = $iParams[2]
;"disable"
_Example($mtric, $setting)
MsgBox(4096, "Test", "The setting saved and set " & $mtric & " to " & $setting & " This box will time out in 3 seconds", 3)
Exit (0)

; Finished!

Func _selectDisEna($setting)
    Sleep(200)
    Local $sEditTitle = WinGetTitle("[ACTIVE]")
    ConsoleWrite("$sEditTitle=" & $sEditTitle & @CRLF)
    Local $hGPOedit = WinWaitActive($sEditTitle)

    Switch $setting
        Case "disable", "Disabled"
            Send("d")

        Case "enabled", "Enabled"
            Send("e")

        Case "not configured", "Not configured"
            Send("c")

    EndSwitch
    ConsoleWrite("$setting=" & $setting & @CRLF)

    Sleep(100)
    Send("a")
;~  Send("{n}")
    Sleep(100)
    Send("{ENTER}")
EndFunc   ;==>_selectDisEna


Func _Example($mtric, $setting)
    ConsoleWrite("$mtric=" & $mtric & @CRLF)
    ConsoleWrite("$setting=" & $setting & @CRLF)
;~         Run("c:\Windows\system32\mmc.exe " & "C:\share\open_close_gpedit\gpedit_v1.msc /a")
    ShellExecute("C:\WINDOWS\SYSTEM32\MMC.EXE", "C:\WINDOWS\SYSTEM32\GPEDIT.MSC")

    Local $hGPO = WinWaitActive("Local Group Policy Editor")
    ConsoleWrite("$hGPO=" & $hGPO & @CRLF)

    Local $hTreeView_1 = ControlGetHandle($hGPO, "", "SysTreeView321")

    ControlTreeView($hGPO, "", $hTreeView_1, "Expand", "#0|#0|#2")
    ControlTreeView($hGPO, "", $hTreeView_1, "Select", "#0|#0|#2")
    Sleep(50)

    ControlSend($hGPO, "", $hTreeView_1, "all")
    Sleep(50)

    ControlSend($hGPO, "", $hTreeView_1, "{ALT}{A}{O}")
    WinWaitActive("[TITLE:Filter Options]")

    ;if unChecked then Checked
    If ControlCommand("Filter Options", "", "Button2", "IsChecked", "") = 0 Then
        Send("!a") ;{ALT down}{K}{ALT up}
    EndIf

    ;get in Edit1
    Send("!f") ;{ALT down}{F}{ALT up}

    ;;Type search in Edit1
    ControlSend("[TITLE:Filter Options]", "", "Edit1", $mtric)
    Sleep(1000)
    ControlSend("[TITLE:Filter Options]", "", "Edit1", "{ENTER}")

    Sleep(4000)

    ControlFocus($hGPO, "", $hTreeView_1)
    ControlSend($hGPO, "", $hTreeView_1, "a")
    Sleep(100)

    ControlFocus($hGPO, "", "AMCCustomTab1")
    ControlSend($hGPO, "", "AMCCustomTab1", "{RIGHT}")
    Sleep(100)

    ;Retrieves the SysListView321 control handle
    Local $hListView = ControlGetHandle($hGPO, "", "SysListView321")

    ;Sets the focus to SysListView321

    ConsoleWrite("ControlFocus=" & ControlFocus($hGPO, "", $hListView) & @CRLF)
    Sleep(100)

    Local $Item, $ItemCnt, $ItemTxt, $FindItem

    ;Select first item
    ControlListView($hGPO, "", $hListView, "Select", 0)
    Sleep(100)

    $SelectedItem = ControlListView($hGPO, "", $hListView, "GetSelected")
    ConsoleWrite("$SelectedItem=" & $SelectedItem & @CRLF)
    Sleep(50)

    $ItemCnt = ControlListView($hGPO, "", $hListView, "GetItemCount")
    ConsoleWrite("$ItemCnt=" & $ItemCnt & @CRLF)
    Sleep(50)

    $ItemTxt = ControlListView($hGPO, "", $hListView, "GetText", $SelectedItem, 0)
    ConsoleWrite("$ItemTxt=" & $ItemTxt & @CRLF)
    Sleep(50)

    $ItemTxt = ControlListView($hGPO, "", $hListView, "GetText", $SelectedItem, 1)
    ConsoleWrite("$ItemTxt=" & $ItemTxt & @CRLF)
    Sleep(50)

    $ItemTxt = ControlListView($hGPO, "", $hListView, "GetText", $SelectedItem, 2)
    ConsoleWrite("$ItemTxt=" & $ItemTxt & @CRLF)
    Sleep(50)

    $ItemTxt = ControlListView($hGPO, "", $hListView, "GetText", $SelectedItem, 3)
    ConsoleWrite("$ItemTxt=" & $ItemTxt & @CRLF)
    Sleep(50)

    For $x = 0 To $ItemCnt - 1
        ControlListView($hGPO, "", $hListView, "Select", $x)
        Sleep(50)
        ControlSend($hGPO, "", $hListView, "{Enter}")
        _selectDisEna($setting)
    Next

    Sleep(3500)
    WinWaitActive("[CLASS:MMCMainFrame]")

    ControlSend($hGPO, "", $hTreeView_1, "{ALT down}{F4}{ALT up}")

    ;MsgBox(4096, "Test", "The setting saved and set "& $mtric & " to " & $setting & " This box will time out in 10 seconds", 10)

EndFunc   ;==>_Example

 

I know that I know nothing

Link to comment
Share on other sites

7 hours ago, ioa747 said:

try it carefully, I can't test it on me because I don't have your data, I tried it on other data, I brought it to you (I believe) as you wanted, I also put the additional information about the items  text, but it need  your own hand to arrange it , as you want

within the function
Func _selectDisEna($setting)
you have     For $i = 5 To 1 Step -1    where does this come from? is it always 5? or is it only for the Adobe

 

#RequireAdmin
#AutoIt3Wrapper_UseX64=y
#include <Constants.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <GuiButton.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>


;==============================================================
; FUNCTION: _Example
; DESCRIPTION: This function opens the Group Policy Object Editor,
;   navigates to the specified policy setting, and changes its value
;   to the specified setting.
; PARAMETERS:
;   $metric - The name of the policy setting to be changed.
;   $setting - The value to which the policy setting should be changed.
; RETURNS: None.
;==============================================================

Global $iParams = $CmdLine[0]

;If Not file parameters then as example set 3 parameters
If Not $iParams Then
    Global $iParams[3] = [2, "Allow Adobe Flash", "disable"]
Else
    $iParams = $CmdLine
EndIf

MsgBox(4096, "message", "The setting  " & $iParams[1] & " set to " & $iParams[2] & " This box will time out in 3 seconds", 3)
Sleep(5000)

Local $mtric = $iParams[1]
;       "Allow Adobe Flash"
Local $setting = $iParams[2]
;"disable"
_Example($mtric, $setting)
MsgBox(4096, "Test", "The setting saved and set " & $mtric & " to " & $setting & " This box will time out in 3 seconds", 3)
Exit (0)

; Finished!

Func _selectDisEna($setting)
    Sleep(200)
    Local $sEditTitle = WinGetTitle("[ACTIVE]")
    ConsoleWrite("$sEditTitle=" & $sEditTitle & @CRLF)
    Local $hGPOedit = WinWaitActive($sEditTitle)

    Switch $setting
        Case "disable", "Disabled"
            Send("d")

        Case "enabled", "Enabled"
            Send("e")

        Case "not configured", "Not configured"
            Send("c")

    EndSwitch
    ConsoleWrite("$setting=" & $setting & @CRLF)

    Sleep(100)
    Send("a")
;~  Send("{n}")
    Sleep(100)
    Send("{ENTER}")
EndFunc   ;==>_selectDisEna


Func _Example($mtric, $setting)
    ConsoleWrite("$mtric=" & $mtric & @CRLF)
    ConsoleWrite("$setting=" & $setting & @CRLF)
;~         Run("c:\Windows\system32\mmc.exe " & "C:\share\open_close_gpedit\gpedit_v1.msc /a")
    ShellExecute("C:\WINDOWS\SYSTEM32\MMC.EXE", "C:\WINDOWS\SYSTEM32\GPEDIT.MSC")

    Local $hGPO = WinWaitActive("Local Group Policy Editor")
    ConsoleWrite("$hGPO=" & $hGPO & @CRLF)

    Local $hTreeView_1 = ControlGetHandle($hGPO, "", "SysTreeView321")

    ControlTreeView($hGPO, "", $hTreeView_1, "Expand", "#0|#0|#2")
    ControlTreeView($hGPO, "", $hTreeView_1, "Select", "#0|#0|#2")
    Sleep(50)

    ControlSend($hGPO, "", $hTreeView_1, "all")
    Sleep(50)

    ControlSend($hGPO, "", $hTreeView_1, "{ALT}{A}{O}")
    WinWaitActive("[TITLE:Filter Options]")

    ;if unChecked then Checked
    If ControlCommand("Filter Options", "", "Button2", "IsChecked", "") = 0 Then
        Send("!a") ;{ALT down}{K}{ALT up}
    EndIf

    ;get in Edit1
    Send("!f") ;{ALT down}{F}{ALT up}

    ;;Type search in Edit1
    ControlSend("[TITLE:Filter Options]", "", "Edit1", $mtric)
    Sleep(1000)
    ControlSend("[TITLE:Filter Options]", "", "Edit1", "{ENTER}")

    Sleep(4000)

    ControlFocus($hGPO, "", $hTreeView_1)
    ControlSend($hGPO, "", $hTreeView_1, "a")
    Sleep(100)

    ControlFocus($hGPO, "", "AMCCustomTab1")
    ControlSend($hGPO, "", "AMCCustomTab1", "{RIGHT}")
    Sleep(100)

    ;Retrieves the SysListView321 control handle
    Local $hListView = ControlGetHandle($hGPO, "", "SysListView321")

    ;Sets the focus to SysListView321

    ConsoleWrite("ControlFocus=" & ControlFocus($hGPO, "", $hListView) & @CRLF)
    Sleep(100)

    Local $Item, $ItemCnt, $ItemTxt, $FindItem

    ;Select first item
    ControlListView($hGPO, "", $hListView, "Select", 0)
    Sleep(100)

    $SelectedItem = ControlListView($hGPO, "", $hListView, "GetSelected")
    ConsoleWrite("$SelectedItem=" & $SelectedItem & @CRLF)
    Sleep(50)

    $ItemCnt = ControlListView($hGPO, "", $hListView, "GetItemCount")
    ConsoleWrite("$ItemCnt=" & $ItemCnt & @CRLF)
    Sleep(50)

    $ItemTxt = ControlListView($hGPO, "", $hListView, "GetText", $SelectedItem, 0)
    ConsoleWrite("$ItemTxt=" & $ItemTxt & @CRLF)
    Sleep(50)

    $ItemTxt = ControlListView($hGPO, "", $hListView, "GetText", $SelectedItem, 1)
    ConsoleWrite("$ItemTxt=" & $ItemTxt & @CRLF)
    Sleep(50)

    $ItemTxt = ControlListView($hGPO, "", $hListView, "GetText", $SelectedItem, 2)
    ConsoleWrite("$ItemTxt=" & $ItemTxt & @CRLF)
    Sleep(50)

    $ItemTxt = ControlListView($hGPO, "", $hListView, "GetText", $SelectedItem, 3)
    ConsoleWrite("$ItemTxt=" & $ItemTxt & @CRLF)
    Sleep(50)

    For $x = 0 To $ItemCnt - 1
        ControlListView($hGPO, "", $hListView, "Select", $x)
        Sleep(50)
        ControlSend($hGPO, "", $hListView, "{Enter}")
        _selectDisEna($setting)
    Next

    Sleep(3500)
    WinWaitActive("[CLASS:MMCMainFrame]")

    ControlSend($hGPO, "", $hTreeView_1, "{ALT down}{F4}{ALT up}")

    ;MsgBox(4096, "Test", "The setting saved and set "& $mtric & " to " & $setting & " This box will time out in 10 seconds", 10)

EndFunc   ;==>_Example

 

I get a strange error:

image.thumb.png.a467d1ad5459d84447ac310b2b49bf7e.png

and for loop, it is because I don't know which setting to change if I have the same name but a different path so I over in for loop and change everyone...
about export I know  I can export I do it in AutoIt before I call the script we work on now. I have a python script call to export and get csv overall settings and call the script to enable or disable.
 So i have two problems
1. In Func _selectDisEna($setting) I want to use controlsend not use send for i can use for this 

https://www.autoitscript.com/wiki/FAQ#Why_doesn.27t_my_script_work_on_a_locked_workstation.3F

2. if you can help me to get the path When I mark on setting and if it is the path so I send enteI i will go inside
 

 

Link to comment
Share on other sites

9 minutes ago, gal9 said:

2. if you can help me to get the path When I mark on setting and if it is the path so I send enteI i will go inside

look at line 139 to 153

$ItemTxt = ControlListView($hGPO, "", $hListView, "GetText", $SelectedItem, 0)
    ConsoleWrite("$ItemTxt=" & $ItemTxt & @CRLF)
    Sleep(50)

    $ItemTxt = ControlListView($hGPO, "", $hListView, "GetText", $SelectedItem, 1)
    ConsoleWrite("$ItemTxt=" & $ItemTxt & @CRLF)
    Sleep(50)

    $ItemTxt = ControlListView($hGPO, "", $hListView, "GetText", $SelectedItem, 2)
    ConsoleWrite("$ItemTxt=" & $ItemTxt & @CRLF)
    Sleep(50)

    $ItemTxt = ControlListView($hGPO, "", $hListView, "GetText", $SelectedItem, 3)
    ConsoleWrite("$ItemTxt=" & $ItemTxt & @CRLF)
    Sleep(50)

 

I know that I know nothing

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...