Developers Jos Posted March 15, 2023 Developers Share Posted March 15, 2023 Was just playing a little and sort-off suggesting to show how things should be done by tidying code when posting an answer. ioa747 and gal9 2 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
gal9 Posted March 15, 2023 Author Share Posted March 15, 2023 31 minutes ago, ioa747 said: expandcollapse popup#RequireAdmin #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator #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) Sleep(200) ; we give some time until the window appears Local $sEditTitle = WinGetTitle("[ACTIVE]") ConsoleWrite("$sEditTitle=" & $sEditTitle & @CRLF) Local $hGPOedit = WinWaitActive($sEditTitle) ControlFocus($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16") For $i = 5 To 1 Step -1 If $setting = "disable" Or $setting ="Disabled" Then ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "d") Sleep(3000) ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad112", "a") EndIf If $setting = "enabled" Or $setting ="Enabled" Then ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "e") Sleep(3000) ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad112", "a") EndIf If $setting = "not configured" Or $setting ="Not configured" Then Send("{c}") EndIf ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad112", "{p}") Next ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad112", "{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) ;Retrieves the SysListView321 control handle Local $hListView = ControlGetHandle($hGPO, "", "SysListView321") ;Sets the focus to SysListView321 ControlFocus($hGPO, "", $hListView) Sleep(50) Local $Item, $ItemCnt, $ItemTxt, $FindItem ControlSend($hGPO, "", $hListView, "{HOME}") Sleep(50) $SelectedItem = ControlListView($hGPO, "", $hListView, "GetSelected") ConsoleWrite("$SelectedItem=" & $SelectedItem & @CRLF) Sleep(50) $ItemCnt = ControlListView($hGPO, "", $hListView, "GetItemCount") ConsoleWrite("$ItemCnt=" & $ItemCnt & @CRLF) Sleep(50) MsgBox(4096, "$ItemCnt", "$ItemCnt "& $ItemCnt , 15) For $x = 0 To $ItemCnt - 1 ControlListView($hGPO, "", $hListView, "Select", $x) $SelectedItem = ControlListView($hGPO, "", $hListView, "GetSelected") ConsoleWrite("$SelectedItem=" & $SelectedItem & " ") $ItemTxt = ControlListView($hGPO, "", $hListView, "GetText", $SelectedItem, 3) ConsoleWrite("$ItemTxt=" & $ItemTxt & @CRLF) Sleep(1000) MsgBox(4096, "$ItemCnt", "$ItemTxt "& $ItemTxt , 15) Next ;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 he wanted some Sleep(50) it is now showing me the counter but: and after the message box i get Link to comment Share on other sites More sharing options...
ioa747 Posted March 15, 2023 Share Posted March 15, 2023 I don't know, what is the file "C:\share\open_close_gpedit\gpedit_v1.msc /a" I know that I know nothing Link to comment Share on other sites More sharing options...
gal9 Posted March 15, 2023 Author Share Posted March 15, 2023 1 minute ago, ioa747 said: I don't know, what is the file "C:\share\open_close_gpedit\gpedit_v1.msc /a" temple of gpedit i can update for you file https://file.io/goBbXkzmGGy4 Link to comment Share on other sites More sharing options...
ioa747 Posted March 15, 2023 Share Posted March 15, 2023 what is tha /a parameter I know that I know nothing Link to comment Share on other sites More sharing options...
gal9 Posted March 15, 2023 Author Share Posted March 15, 2023 16 minutes ago, ioa747 said: what is tha /a parameter https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/mmc but if i remove /a it still does not work for me... for you it is work? Link to comment Share on other sites More sharing options...
ioa747 Posted March 15, 2023 Share Posted March 15, 2023 (edited) I don't use it yet, so far i am using the ShellExecute("C:\WINDOWS\SYSTEM32\MMC.EXE", "C:\WINDOWS\SYSTEM32\GPEDIT.MSC") Edited March 15, 2023 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
gal9 Posted March 15, 2023 Author Share Posted March 15, 2023 1 minute ago, ioa747 said: I don't use it yet, so far i am using the ShellExecute("C:\WINDOWS\SYSTEM32\MMC.EXE", "C:\WINDOWS\SYSTEM32\GPEDIT.MSC") if use this line It stuck in: Link to comment Share on other sites More sharing options...
ioa747 Posted March 15, 2023 Share Posted March 15, 2023 and for me, there must be items for the filter to appear, for example I must first go to all settings, or where settings appear and then is the filter available I know that I know nothing Link to comment Share on other sites More sharing options...
gal9 Posted March 15, 2023 Author Share Posted March 15, 2023 1 minute ago, ioa747 said: and for me, there must be items for the filter to appear, for example I must first go to all settings, or where settings appear and then is the filter available for to filter to appear you need to be in admintriv template /all setting Link to comment Share on other sites More sharing options...
gal9 Posted March 15, 2023 Author Share Posted March 15, 2023 8 minutes ago, ioa747 said: and for me, there must be items for the filter to appear, for example I must first go to all settings, or where settings appear and then is the filter available I tried on another machine i get the same error Microsoft management console has stopped working Link to comment Share on other sites More sharing options...
ioa747 Posted March 15, 2023 Share Posted March 15, 2023 that's why I asked because your script didn't work for me, and I had to modify it here is calls {ALT}{A}{O} before he goes to all setting 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) gal9 1 I know that I know nothing Link to comment Share on other sites More sharing options...
TheXman Posted March 15, 2023 Share Posted March 15, 2023 @gal9 You didn't respond to my question in your previous topic about reading GPO settings, so let me ask it again. Why are you doing all of this GUI automation in order to simply read & write registry entries? You are aware that all of these policies are stored in the registry right? CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
gal9 Posted March 15, 2023 Author Share Posted March 15, 2023 8 minutes ago, ioa747 said: that's why I asked because your script didn't work for me, and I had to modify it here is calls {ALT}{A}{O} before he goes to all setting 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) yes but i want to search and after go over all results Link to comment Share on other sites More sharing options...
gal9 Posted March 15, 2023 Author Share Posted March 15, 2023 5 minutes ago, TheXman said: @gal9 You didn't respond to my question in your previous topic about reading GPO settings, so let me ask it again. Why are you doing all of this GUI automation in order to simply read & write registry entries? You are aware that all of these policies are stored in the registry right? I write automation for a product and write a registry it is not will be work After consulting with kernel people Link to comment Share on other sites More sharing options...
Skysnake Posted March 15, 2023 Share Posted March 15, 2023 I think it's restriction of use type issue Skysnake Why is the snake in the sky? Link to comment Share on other sites More sharing options...
gal9 Posted March 15, 2023 Author Share Posted March 15, 2023 1 minute ago, Skysnake said: I think it's restriction of use type issue to get the path? Link to comment Share on other sites More sharing options...
gal9 Posted March 15, 2023 Author Share Posted March 15, 2023 small question if you can help me again with send and ControlSend 22 minutes ago, ioa747 said: that's why I asked because your script didn't work for me, and I had to modify it here is calls {ALT}{A}{O} before he goes to all setting 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) small question if you can help me again with send and ControlSend Send("{ALT down}{F4}{ALT up}") Sleep(2000) Send ("{N}") at the end of the code Link to comment Share on other sites More sharing options...
ioa747 Posted March 15, 2023 Share Posted March 15, 2023 1 hour ago, gal9 said: small question if you can help me again with send and ControlSend you can send it to $hTreeView_1 ControlFocus($hGPO, "", $hTreeView_1) ControlSend($hGPO, "", $hTreeView_1, "{ALT down}{F4}{ALT up}") but after that, for me, that closes Group Policy Editor window , where to send the {N} ? if not for you then try ControlSend($hGPO, "", $hTreeView_1, "{N}") I know that I know nothing Link to comment Share on other sites More sharing options...
gal9 Posted March 19, 2023 Author Share Posted March 19, 2023 (edited) On 3/15/2023 at 6:25 PM, ioa747 said: you can send it to $hTreeView_1 ControlFocus($hGPO, "", $hTreeView_1) ControlSend($hGPO, "", $hTreeView_1, "{ALT down}{F4}{ALT up}") but after that, for me, that closes Group Policy Editor window , where to send the {N} ? if not for you then try ControlSend($hGPO, "", $hTreeView_1, "{N}") send n for this :ControlSend($hGPO, "", $hTreeView_1, "{N}") it is not work this work for me Sleep(2000) Local $hGPO = WinWaitActive("Microsoft Management Console") ControlSend($hGPO, "", "[CLASS:Static; INSTANCE:2]", "{N}") about the path did you succeed? Edited March 19, 2023 by gal9 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now