ioa747 Posted March 26, 2023 Share Posted March 26, 2023 ; #FUNCTION# ;--------------------------------------------------------------------------- ; Name...........: _GroupPolicy() ; Description ...: Opens and uses the Group Policy Editor to configure the given settings ; Syntax.........: _GroupPolicy($sPolicyPath, $sPolicyItem, $iSetting [, $sOption = ""]) ; Parameters ....: $sPolicyPath - The path of nodes to navigate ; $sPolicyItem - The Item/option to navigate/edit ; $iSetting - 0=Disabled, 1=Enabled, 2=Configured ; $sOption - Options in form "ClassnameNN;SendKey" ;---------------------------------------------------------------------------------------- Func _GroupPolicy($sPolicyPath, $sPolicyItem, $iSetting, $sOption = "") $sOption = "WindowsForms10.COMBOBOX.app.0.297b065_r69_ad11;f" it sends 'f' to control for 'First Time' This policy setting allows you to require a pin for pairing. If you set this to 'Never', a pin isn't required for pairing. If you set this to 'First Time', the pairing ceremony for new devices will always require a PIN. If you set this to 'Always', all pairings will require PIN. it works normally for me, it doesn't ask me anything, when you do it manually, it asks you for something? https://fileport.io/SEvYva9WBZbf I couldn't see it I know that I know nothing Link to comment Share on other sites More sharing options...
gal9 Posted March 26, 2023 Author Share Posted March 26, 2023 (edited) 1 hour ago, ioa747 said: ; #FUNCTION# ;--------------------------------------------------------------------------- ; Name...........: _GroupPolicy() ; Description ...: Opens and uses the Group Policy Editor to configure the given settings ; Syntax.........: _GroupPolicy($sPolicyPath, $sPolicyItem, $iSetting [, $sOption = ""]) ; Parameters ....: $sPolicyPath - The path of nodes to navigate ; $sPolicyItem - The Item/option to navigate/edit ; $iSetting - 0=Disabled, 1=Enabled, 2=Configured ; $sOption - Options in form "ClassnameNN;SendKey" ;---------------------------------------------------------------------------------------- Func _GroupPolicy($sPolicyPath, $sPolicyItem, $iSetting, $sOption = "") $sOption = "WindowsForms10.COMBOBOX.app.0.297b065_r69_ad11;f" it sends 'f' to control for 'First Time' This policy setting allows you to require a pin for pairing. If you set this to 'Never', a pin isn't required for pairing. If you set this to 'First Time', the pairing ceremony for new devices will always require a PIN. If you set this to 'Always', all pairings will require PIN. it works normally for me, it doesn't ask me anything, when you do it manually, it asks you for something? https://fileport.io/SEvYva9WBZbf I couldn't see it 1. about this $sOption = "WindowsForms10.COMBOBOX.app.0.297b065_r69_ad11;f" it sends 'f' to control for 'First Time' i see and I understood that but if you can see this:https://www.dropbox.com/s/xo1wapciwxswzto/Require pin for pairing.mp4?dl=0 this is the video you see it is open "Require pin for pairing" but i is not do enable it to save it to not configure. 2. you can help after I send to enable or disable so it is closed the popup. It doesn't matter which window opens, if a window opens, close it or click OK 3. about parameter i do compile and send _GroupPolicy2.exe "\Computer Configuration\Administrative Templates\Windows Components\Connect" "Require pin for pairing" "1" "WindowsForms10.COMBOBOX.app.0.297b065_r69_ad11; f" it is doesn't work for me. I think it's an array and need do something like that If $CmdLine[0] = 4 Then ; Assign the values from command line to variables Global $param1 = $CmdLine[1] Global $param2 = $CmdLine[2] Global $param3 = $CmdLine[3] Global $param4 = $CmdLine[4] ; Use the variables in your script ; ... Else ; Display an error message or usage instructions MsgBox(16, "Error", "Invalid number of command line arguments.") EndIf What do you think? but i see msgbox with parameters but i is But it got stuckhttps://www.dropbox.com/s/3fofa21db3emzgi/parmter.mp4?dl=0 after it is open the GPO is close the exe Edited March 26, 2023 by gal9 Link to comment Share on other sites More sharing options...
ioa747 Posted March 26, 2023 Share Posted March 26, 2023 (edited) _GroupPolicy2.au3 expandcollapse popup#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> Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info ; * <--- ;============================================================== ; 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: ; $CmdLine[1] - The path of nodes to navigate. ; $CmdLine[2] - The name of the policy setting to be changed. ; $CmdLine[3] - The value of the policy setting to be changed 0=Disabled, 1=Enabled, 2=Configured ; $CmdLine[4] - Options in form "ClassnameNN;SendKey" ;============================================================== ; "\Computer Configuration\Administrative Templates\Windows Components\Microsoft Edge", "Allow Adobe Flash", 0 ; "\Computer Configuration\Administrative Templates\Windows Components\Connect", "Require pin for pairing", 1, "WindowsForms10.COMBOBOX.app.0.297b065_r69_ad11;f" If Not $CmdLine[0] Then Global $CmdLine[5] = [4, "\Computer Configuration\Administrative Templates\Windows Components\Connect", "Require pin for pairing", 1, "WindowsForms10.COMBOBOX.app.0.297b065_r69_ad11;f"] EndIf Global $iMsgBoxAnswer = "The setting" & @CRLF $iMsgBoxAnswer &= $CmdLine[1] & @CRLF $iMsgBoxAnswer &= $CmdLine[2] & @CRLF $iMsgBoxAnswer &= "will be set to " & $CmdLine[3] & @CRLF $iMsgBoxAnswer = MsgBox(4097, "This Msgbox will time out in 3 seconds", $iMsgBoxAnswer, 3) Select Case $iMsgBoxAnswer = 1 ;OK ;nothing Case $iMsgBoxAnswer = 2 ;Cancel Exit EndSelect ConsoleWrite("$CmdLine[0]=" & $CmdLine[0] & @CRLF) If $CmdLine[0] = 4 Then _GroupPolicy($CmdLine[1], $CmdLine[2], $CmdLine[3], $CmdLine[4]) ElseIf $CmdLine[0] = 3 Then _GroupPolicy($CmdLine[1], $CmdLine[2], $CmdLine[3]) Else $iMsgBoxAnswer = MsgBox(4096, "incorect number of parameters", $CmdLine[0]) EndIf Exit ; #FUNCTION# ;--------------------------------------------------------------------------- ; Name...........: _GroupPolicy() ; Description ...: Opens and uses the Group Policy Editor to configure the given settings ; Syntax.........: _GroupPolicy($sPolicyPath, $sPolicyItem, $iSetting [, $sOption = ""]) ; Parameters ....: $sPolicyPath - The path of nodes to navigate ; $sPolicyItem - The Item/option to navigate/edit ; $iSetting - 0=Disabled, 1=Enabled, 2=Configured ; $sOption - Options in form "ClassnameNN;SendKey" ;---------------------------------------------------------------------------------------- Func _GroupPolicy($sPolicyPath, $sPolicyItem, $iSetting, $sOption = "") If Not WinExists("Local Group Policy Editor") Then Run("c:\Windows\system32\mmc.exe " & "C:\share\open_close_gpedit\gpedit_v1.msc /a") WinWait("Local Group Policy Editor", '', 5) EndIf ;Retrieves the 'Local Group Policy Editor' window handle Local $hGPO = WinActivate("Local Group Policy Editor") ConsoleWrite("$hGPO=" & $hGPO & @CRLF) ;Retrieves the SysTreeView321 control handle Local $hTreeView_1 = ControlGetHandle($hGPO, "", "SysTreeView321") ;Sets the focus to $hTreeView_1 ControlFocus($hGPO, "", $hTreeView_1) Sleep(50) $sPolicyPath = "Local Computer Policy" & $sPolicyPath ConsoleWrite("$sPolicyPath=" & $sPolicyPath & @CRLF) ConsoleWrite("$sPolicyItem=" & $sPolicyItem & @CRLF) Local $aPath = StringSplit($sPolicyPath, "\", 1) Local $tmpPath = "" ;ConsoleWrite("" & @CRLF) 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}") Sleep(50) ;Retrieves the SysListView321 control handle Local $hListView = ControlGetHandle($hGPO, "", "SysListView321") ;Sets the focus to SysListView321 ControlFocus($hGPO, "", $hListView) Sleep(50) ;find the item Local $FindItem = ControlListView($hGPO, "", $hListView, "FindItem", $sPolicyItem) Sleep(500) 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 it ControlSend($hGPO, '', $hListView, '{ENTER}') ;--------------------------------------------------------------- Local $hGPOedit = WinWait("[CLASS:WindowsForms10.Window.8.app.0.297b065_r69_ad1]", "", 1) ConsoleWrite("$hGPOedit=" & $hGPOedit & @CRLF) If WinExists($hGPOedit) Then ; normal ConsoleWrite("$hGPOedit=normal" & @CRLF) ControlFocus($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16") Switch $iSetting Case 0 ;Disabled ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "d") ConsoleWrite("$iSetting=Disabled" & @CRLF) Case 1 ;Enabled ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "e") ConsoleWrite("$iSetting=Enabled" & @CRLF) If StringLen($sOption) > 0 Then ConsoleWrite("$sOption=" & $sOption & @CRLF) Local $aOpt = StringSplit($sOption, ";", 1) ControlSend($hGPOedit, "", $aOpt[1], $aOpt[2]) EndIf Case 2 ;Configured ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "c") ConsoleWrite("$iSetting=Configured" & @CRLF) EndSwitch ; Apply ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "a") ; Enter ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "{ENTER}") Else ; special $hGPOedit = WinWait("[CLASS:#32770]", "", 1) ; Retrieve the window text of the active window. Local $sText = WinGetText($hGPOedit) ConsoleWrite($sText & @CRLF) If StringLeft($sText, 22) = "Local Security Setting" Then ConsoleWrite("$hGPOedit=special" & @CRLF) Switch $iSetting Case 0 ;Disabled ControlSend($hGPOedit, "", "Button3", "s") ConsoleWrite("$iSetting=Disabled" & @CRLF) Case 1 ;Enabled ControlSend($hGPOedit, "", "Button2", "e") ConsoleWrite("$iSetting=Enabled" & @CRLF) EndSwitch ControlSend($hGPOedit, "", "SysTabControl321", "{ENTER}") Sleep(50) EndIf EndIf ;--------------------------------------------------------------- ;~ Exit ; <-- **************************************************** ControlFocus($hGPO, "", $hTreeView_1) Sleep(50) ControlSend($hGPO, "", $hTreeView_1, "{ALT down}{F4}{ALT up}") $hGPO = WinWait("Microsoft Management Console", "", 1) ControlSend($hGPO, "", "Static2", "{N}") Return $sPolicyItem EndFunc ;==>_GroupPolicy ;---------------------------------------------------------------------------------------- Edited March 26, 2023 by ioa747 I find changes in the class names I know that I know nothing Link to comment Share on other sites More sharing options...
gal9 Posted March 26, 2023 Author Share Posted March 26, 2023 (edited) 26 minutes ago, ioa747 said: _GroupPolicy2.au3 expandcollapse popup#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> Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info ; * <--- ;============================================================== ; 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: ; $CmdLine[1] - The path of nodes to navigate. ; $CmdLine[2] - The name of the policy setting to be changed. ; $CmdLine[3] - The value of the policy setting to be changed 0=Disabled, 1=Enabled, 2=Configured ; $CmdLine[4] - Options in form "ClassnameNN;SendKey" ;============================================================== ; "\Computer Configuration\Administrative Templates\Windows Components\Microsoft Edge", "Allow Adobe Flash", 0 ; "\Computer Configuration\Administrative Templates\Windows Components\Connect", "Require pin for pairing", 1, "WindowsForms10.COMBOBOX.app.0.297b065_r69_ad11;f" If Not $CmdLine[0] Then Global $CmdLine[5] = [4, "\Computer Configuration\Administrative Templates\Windows Components\Connect", "Require pin for pairing", 1, "WindowsForms10.COMBOBOX.app.0.297b065_r69_ad11;f"] EndIf Global $iMsgBoxAnswer = "The setting" & @CRLF $iMsgBoxAnswer &= $CmdLine[1] & @CRLF $iMsgBoxAnswer &= $CmdLine[2] & @CRLF $iMsgBoxAnswer &= "will be set to " & $CmdLine[3] & @CRLF $iMsgBoxAnswer = MsgBox(4097, "This Msgbox will time out in 3 seconds", $iMsgBoxAnswer, 3) Select Case $iMsgBoxAnswer = 1 ;OK ;nothing Case $iMsgBoxAnswer = 2 ;Cancel Exit EndSelect ConsoleWrite("$CmdLine[0]=" & $CmdLine[0] & @CRLF) If $CmdLine[0] = 4 Then _GroupPolicy($CmdLine[1], $CmdLine[2], $CmdLine[3], $CmdLine[4]) ElseIf $CmdLine[0] = 3 Then _GroupPolicy($CmdLine[1], $CmdLine[2], $CmdLine[3]) Else $iMsgBoxAnswer = MsgBox(4096, "incorect number of parameters", $CmdLine[0]) EndIf Exit ; #FUNCTION# ;--------------------------------------------------------------------------- ; Name...........: _GroupPolicy() ; Description ...: Opens and uses the Group Policy Editor to configure the given settings ; Syntax.........: _GroupPolicy($sPolicyPath, $sPolicyItem, $iSetting [, $sOption = ""]) ; Parameters ....: $sPolicyPath - The path of nodes to navigate ; $sPolicyItem - The Item/option to navigate/edit ; $iSetting - 0=Disabled, 1=Enabled, 2=Configured ; $sOption - Options in form "ClassnameNN;SendKey" ;---------------------------------------------------------------------------------------- Func _GroupPolicy($sPolicyPath, $sPolicyItem, $iSetting, $sOption = "") If Not WinExists("Local Group Policy Editor") Then Run("c:\Windows\system32\mmc.exe " & "C:\share\open_close_gpedit\gpedit_v1.msc /a") WinWait("Local Group Policy Editor", '', 5) EndIf ;Retrieves the 'Local Group Policy Editor' window handle Local $hGPO = WinActivate("Local Group Policy Editor") ConsoleWrite("$hGPO=" & $hGPO & @CRLF) ;Retrieves the SysTreeView321 control handle Local $hTreeView_1 = ControlGetHandle($hGPO, "", "SysTreeView321") ;Sets the focus to $hTreeView_1 ControlFocus($hGPO, "", $hTreeView_1) Sleep(50) $sPolicyPath = "Local Computer Policy" & $sPolicyPath ConsoleWrite("$sPolicyPath=" & $sPolicyPath & @CRLF) ConsoleWrite("$sPolicyItem=" & $sPolicyItem & @CRLF) Local $aPath = StringSplit($sPolicyPath, "\", 1) Local $tmpPath = "" ;ConsoleWrite("" & @CRLF) 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}") Sleep(50) ;Retrieves the SysListView321 control handle Local $hListView = ControlGetHandle($hGPO, "", "SysListView321") ;Sets the focus to SysListView321 ControlFocus($hGPO, "", $hListView) Sleep(50) ;find the item Local $FindItem = ControlListView($hGPO, "", $hListView, "FindItem", $sPolicyItem) Sleep(500) 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 it ControlSend($hGPO, '', $hListView, '{ENTER}') ;--------------------------------------------------------------- Local $hGPOedit = WinWait("[CLASS:WindowsForms10.Window.8.app.0.297b065_r69_ad1]", "", 1) ConsoleWrite("$hGPOedit=" & $hGPOedit & @CRLF) If WinExists($hGPOedit) Then ; normal ConsoleWrite("$hGPOedit=normal" & @CRLF) ControlFocus($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16") Switch $iSetting Case 0 ;Disabled ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "d") ConsoleWrite("$iSetting=Disabled" & @CRLF) Case 1 ;Enabled ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "e") ConsoleWrite("$iSetting=Enabled" & @CRLF) If StringLen($sOption) > 0 Then ConsoleWrite("$sOption=" & $sOption & @CRLF) Local $aOpt = StringSplit($sOption, ";", 1) ControlSend($hGPOedit, "", $aOpt[1], $aOpt[2]) EndIf Case 2 ;Configured ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "c") ConsoleWrite("$iSetting=Configured" & @CRLF) EndSwitch ; Apply ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "a") ; Enter ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "{ENTER}") Else ; special $hGPOedit = WinWait("[CLASS:#32770]", "", 1) ; Retrieve the window text of the active window. Local $sText = WinGetText($hGPOedit) ConsoleWrite($sText & @CRLF) If StringLeft($sText, 22) = "Local Security Setting" Then ConsoleWrite("$hGPOedit=special" & @CRLF) Switch $iSetting Case 0 ;Disabled ControlSend($hGPOedit, "", "Button3", "s") ConsoleWrite("$iSetting=Disabled" & @CRLF) Case 1 ;Enabled ControlSend($hGPOedit, "", "Button2", "e") ConsoleWrite("$iSetting=Enabled" & @CRLF) EndSwitch ControlSend($hGPOedit, "", "SysTabControl321", "{ENTER}") Sleep(50) EndIf EndIf ;--------------------------------------------------------------- ;~ Exit ; <-- **************************************************** ControlFocus($hGPO, "", $hTreeView_1) Sleep(50) ControlSend($hGPO, "", $hTreeView_1, "{ALT down}{F4}{ALT up}") $hGPO = WinWait("Microsoft Management Console", "", 1) ControlSend($hGPO, "", "Static2", "{N}") Return $sPolicyItem EndFunc ;==>_GroupPolicy ;---------------------------------------------------------------------------------------- i have problem sometimes it is work and sometimes not:https://www.dropbox.com/s/7hnxqyxivyit2cl/not work.mp4?dl=0 before you edited your comment it is work and It's acting weird maybe need more sleep? or compile 64 or 86? and about Popup You have a solution? Edited March 26, 2023 by gal9 Link to comment Share on other sites More sharing options...
ioa747 Posted March 26, 2023 Share Posted March 26, 2023 in the video it looks like "WindowsForms10.COMBOBOX.app.0.297b065_r69_ad11; f" pay attention, it doesn't want a space after ; "WindowsForms10.COMBOBOX.app.0.297b065_r69_ad11;f" gal9 1 I know that I know nothing Link to comment Share on other sites More sharing options...
gal9 Posted March 26, 2023 Author Share Posted March 26, 2023 Just now, ioa747 said: in the video it looks like "WindowsForms10.COMBOBOX.app.0.297b065_r69_ad11; f" pay attention, it doesn't want a space after ; "WindowsForms10.COMBOBOX.app.0.297b065_r69_ad11;f" I think it's a x64 compile issue only this work for me Could this be the solution? Link to comment Share on other sites More sharing options...
gal9 Posted March 26, 2023 Author Share Posted March 26, 2023 and about Popup You have a solution? Link to comment Share on other sites More sharing options...
ioa747 Posted March 26, 2023 Share Posted March 26, 2023 (edited) 29 minutes ago, gal9 said: and about Popup You have a solution? If WinExists("Confirm Setting Change") Then ControlSend("Confirm Setting Change", "", "Button1", "y") ; yes EndIf Edited March 26, 2023 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
gal9 Posted March 26, 2023 Author Share Posted March 26, 2023 28 minutes ago, ioa747 said: If WinExists("Confirm Setting Change") Then ControlSend("Confirm Setting Change", "", "Button1", "y") ; yes EndIf it is doesn't work for me maybe i need change the location i put in?? it is close the screen but no continuehttps://www.dropbox.com/s/ef1s1sqloheo0qu/popup.mp4?dl=0 and thanks a loot ! Link to comment Share on other sites More sharing options...
ioa747 Posted March 26, 2023 Share Posted March 26, 2023 *New Setting $iSetting - 0=Disabled, 1=Enabled, 2=Configured, 3=find & exit _GroupPolicy2.au3 expandcollapse popup#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> Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info ; * <--- ;============================================================== ; 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: ; $CmdLine[1] - The path of nodes to navigate. ; $CmdLine[2] - The name of the policy setting to be changed. ; $CmdLine[3] - The value of the policy setting to be changed 0=Disabled, 1=Enabled, 2=Configured ; $CmdLine[4] - Options in form "ClassnameNN;SendKey" ;============================================================== ; "\Computer Configuration\Administrative Templates\Windows Components\Microsoft Edge", "Allow Adobe Flash", 0 ; "\Computer Configuration\Administrative Templates\Windows Components\Connect", "Require pin for pairing", 1, "WindowsForms10.COMBOBOX.app.0.297b065_r69_ad11;f" ; "\Computer Configuration\Windows Settings\Security Settings\Local Policies\Security Options", "Microsoft network client: Digitally sign communications (always)", 3 If Not $CmdLine[0] Then Global $CmdLine[5] = [4, "\Computer Configuration\Windows Settings\Security Settings\Local Policies\Security Options", "Microsoft network client: Digitally sign communications (always)", 3] EndIf Global $iMsgBoxAnswer = "The setting" & @CRLF $iMsgBoxAnswer &= $CmdLine[1] & @CRLF $iMsgBoxAnswer &= $CmdLine[2] & @CRLF $iMsgBoxAnswer &= "will be set to " & $CmdLine[3] & @CRLF $iMsgBoxAnswer = MsgBox(4097, "This Msgbox will time out in 3 seconds", $iMsgBoxAnswer, 3) Select Case $iMsgBoxAnswer = 1 ;OK ;nothing Case $iMsgBoxAnswer = 2 ;Cancel Exit EndSelect ConsoleWrite("$CmdLine[0]=" & $CmdLine[0] & @CRLF) If $CmdLine[0] = 4 Then _GroupPolicy($CmdLine[1], $CmdLine[2], $CmdLine[3], $CmdLine[4]) ElseIf $CmdLine[0] = 3 Then _GroupPolicy($CmdLine[1], $CmdLine[2], $CmdLine[3]) Else $iMsgBoxAnswer = MsgBox(4096, "incorect number of parameters", $CmdLine[0]) EndIf Exit ; #FUNCTION# ;--------------------------------------------------------------------------- ; Name...........: _GroupPolicy() ; Description ...: Opens and uses the Group Policy Editor to configure the given settings ; Syntax.........: _GroupPolicy($sPolicyPath, $sPolicyItem, $iSetting [, $sOption = ""]) ; Parameters ....: $sPolicyPath - The path of nodes to navigate ; $sPolicyItem - The Item/option to navigate/edit ; $iSetting - 0=Disabled, 1=Enabled, 2=Configured, 3=find & exit ; $sOption - Options in form "ClassnameNN;SendKey" ;---------------------------------------------------------------------------------------- Func _GroupPolicy($sPolicyPath, $sPolicyItem, $iSetting, $sOption = "") If Not WinExists("Local Group Policy Editor") Then Run("c:\Windows\system32\mmc.exe " & "C:\share\open_close_gpedit\gpedit_v1.msc /a") WinWait("Local Group Policy Editor", '', 5) EndIf ;Retrieves the 'Local Group Policy Editor' window handle Local $hGPO = WinActivate("Local Group Policy Editor") ConsoleWrite("$hGPO=" & $hGPO & @CRLF) ;Retrieves the SysTreeView321 control handle Local $hTreeView_1 = ControlGetHandle($hGPO, "", "SysTreeView321") ;Sets the focus to $hTreeView_1 ControlFocus($hGPO, "", $hTreeView_1) Sleep(50) $sPolicyPath = "Local Computer Policy" & $sPolicyPath ConsoleWrite("$sPolicyPath=" & $sPolicyPath & @CRLF) ConsoleWrite("$sPolicyItem=" & $sPolicyItem & @CRLF) Local $aPath = StringSplit($sPolicyPath, "\", 1) Local $tmpPath = "" ;ConsoleWrite("" & @CRLF) 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}") Sleep(50) ;Retrieves the SysListView321 control handle Local $hListView = ControlGetHandle($hGPO, "", "SysListView321") ;Sets the focus to SysListView321 ControlFocus($hGPO, "", $hListView) Sleep(50) ;find the item Local $FindItem = ControlListView($hGPO, "", $hListView, "FindItem", $sPolicyItem) Sleep(500) 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 it ControlSend($hGPO, '', $hListView, '{ENTER}') ;--------------------------------------------------------------- Local $hGPOedit = WinWait("[CLASS:WindowsForms10.Window.8.app.0.297b065_r69_ad1]", "", 1) ConsoleWrite("$hGPOedit=" & $hGPOedit & @CRLF) If WinExists($hGPOedit) Then ; normal ConsoleWrite("$hGPOedit=normal" & @CRLF) ControlFocus($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16") Switch $iSetting Case 0 ;Disabled ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "d") ConsoleWrite("$iSetting=Disabled" & @CRLF) Case 1 ;Enabled ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "e") ConsoleWrite("$iSetting=Enabled" & @CRLF) If StringLen($sOption) > 0 Then ConsoleWrite("$sOption=" & $sOption & @CRLF) Local $aOpt = StringSplit($sOption, ";", 1) ControlSend($hGPOedit, "", $aOpt[1], $aOpt[2]) EndIf Case 2 ;Configured ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "c") ConsoleWrite("$iSetting=Configured" & @CRLF) Case 3 ;find & exit ;ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "c") ConsoleWrite("$iSetting=find & exit" & @CRLF) Exit EndSwitch ; Apply ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "a") ; Enter ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "{ENTER}") Else ; special $hGPOedit = WinWait("[CLASS:#32770]", "", 1) ; Retrieve the window text of the active window. Local $sText = WinGetText($hGPOedit) ConsoleWrite($sText & @CRLF) If StringLeft($sText, 22) = "Local Security Setting" Then ConsoleWrite("$hGPOedit=special" & @CRLF) Switch $iSetting Case 0 ;Disabled ControlSend($hGPOedit, "", "Button3", "s") ConsoleWrite("$iSetting=Disabled" & @CRLF) Case 1 ;Enabled ControlSend($hGPOedit, "", "Button2", "e") ConsoleWrite("$iSetting=Enabled" & @CRLF) Case 3 ;find & exit ConsoleWrite("$iSetting=find & exit" & @CRLF) Exit EndSwitch ControlSend($hGPOedit, "", "SysTabControl321", "{ENTER}") Sleep(50) If WinExists("Confirm Setting Change") Then ControlSend("Confirm Setting Change", "", "Button1", "y") ; yes EndIf EndIf EndIf ;--------------------------------------------------------------- ;~ Exit ; <-- **************************************************** ControlFocus($hGPO, "", $hTreeView_1) Sleep(50) ControlSend($hGPO, "", $hTreeView_1, "{ALT down}{F4}{ALT up}") $hGPO = WinWait("Microsoft Management Console", "", 1) ControlSend($hGPO, "", "Static2", "{N}") Return $sPolicyItem EndFunc ;==>_GroupPolicy ;---------------------------------------------------------------------------------------- I know that I know nothing Link to comment Share on other sites More sharing options...
gal9 Posted March 26, 2023 Author Share Posted March 26, 2023 (edited) 1 hour ago, ioa747 said: *New Setting $iSetting - 0=Disabled, 1=Enabled, 2=Configured, 3=find & exit _GroupPolicy2.au3 expandcollapse popup#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> Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info ; * <--- ;============================================================== ; 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: ; $CmdLine[1] - The path of nodes to navigate. ; $CmdLine[2] - The name of the policy setting to be changed. ; $CmdLine[3] - The value of the policy setting to be changed 0=Disabled, 1=Enabled, 2=Configured ; $CmdLine[4] - Options in form "ClassnameNN;SendKey" ;============================================================== ; "\Computer Configuration\Administrative Templates\Windows Components\Microsoft Edge", "Allow Adobe Flash", 0 ; "\Computer Configuration\Administrative Templates\Windows Components\Connect", "Require pin for pairing", 1, "WindowsForms10.COMBOBOX.app.0.297b065_r69_ad11;f" ; "\Computer Configuration\Windows Settings\Security Settings\Local Policies\Security Options", "Microsoft network client: Digitally sign communications (always)", 3 If Not $CmdLine[0] Then Global $CmdLine[5] = [4, "\Computer Configuration\Windows Settings\Security Settings\Local Policies\Security Options", "Microsoft network client: Digitally sign communications (always)", 3] EndIf Global $iMsgBoxAnswer = "The setting" & @CRLF $iMsgBoxAnswer &= $CmdLine[1] & @CRLF $iMsgBoxAnswer &= $CmdLine[2] & @CRLF $iMsgBoxAnswer &= "will be set to " & $CmdLine[3] & @CRLF $iMsgBoxAnswer = MsgBox(4097, "This Msgbox will time out in 3 seconds", $iMsgBoxAnswer, 3) Select Case $iMsgBoxAnswer = 1 ;OK ;nothing Case $iMsgBoxAnswer = 2 ;Cancel Exit EndSelect ConsoleWrite("$CmdLine[0]=" & $CmdLine[0] & @CRLF) If $CmdLine[0] = 4 Then _GroupPolicy($CmdLine[1], $CmdLine[2], $CmdLine[3], $CmdLine[4]) ElseIf $CmdLine[0] = 3 Then _GroupPolicy($CmdLine[1], $CmdLine[2], $CmdLine[3]) Else $iMsgBoxAnswer = MsgBox(4096, "incorect number of parameters", $CmdLine[0]) EndIf Exit ; #FUNCTION# ;--------------------------------------------------------------------------- ; Name...........: _GroupPolicy() ; Description ...: Opens and uses the Group Policy Editor to configure the given settings ; Syntax.........: _GroupPolicy($sPolicyPath, $sPolicyItem, $iSetting [, $sOption = ""]) ; Parameters ....: $sPolicyPath - The path of nodes to navigate ; $sPolicyItem - The Item/option to navigate/edit ; $iSetting - 0=Disabled, 1=Enabled, 2=Configured, 3=find & exit ; $sOption - Options in form "ClassnameNN;SendKey" ;---------------------------------------------------------------------------------------- Func _GroupPolicy($sPolicyPath, $sPolicyItem, $iSetting, $sOption = "") If Not WinExists("Local Group Policy Editor") Then Run("c:\Windows\system32\mmc.exe " & "C:\share\open_close_gpedit\gpedit_v1.msc /a") WinWait("Local Group Policy Editor", '', 5) EndIf ;Retrieves the 'Local Group Policy Editor' window handle Local $hGPO = WinActivate("Local Group Policy Editor") ConsoleWrite("$hGPO=" & $hGPO & @CRLF) ;Retrieves the SysTreeView321 control handle Local $hTreeView_1 = ControlGetHandle($hGPO, "", "SysTreeView321") ;Sets the focus to $hTreeView_1 ControlFocus($hGPO, "", $hTreeView_1) Sleep(50) $sPolicyPath = "Local Computer Policy" & $sPolicyPath ConsoleWrite("$sPolicyPath=" & $sPolicyPath & @CRLF) ConsoleWrite("$sPolicyItem=" & $sPolicyItem & @CRLF) Local $aPath = StringSplit($sPolicyPath, "\", 1) Local $tmpPath = "" ;ConsoleWrite("" & @CRLF) 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}") Sleep(50) ;Retrieves the SysListView321 control handle Local $hListView = ControlGetHandle($hGPO, "", "SysListView321") ;Sets the focus to SysListView321 ControlFocus($hGPO, "", $hListView) Sleep(50) ;find the item Local $FindItem = ControlListView($hGPO, "", $hListView, "FindItem", $sPolicyItem) Sleep(500) 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 it ControlSend($hGPO, '', $hListView, '{ENTER}') ;--------------------------------------------------------------- Local $hGPOedit = WinWait("[CLASS:WindowsForms10.Window.8.app.0.297b065_r69_ad1]", "", 1) ConsoleWrite("$hGPOedit=" & $hGPOedit & @CRLF) If WinExists($hGPOedit) Then ; normal ConsoleWrite("$hGPOedit=normal" & @CRLF) ControlFocus($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16") Switch $iSetting Case 0 ;Disabled ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "d") ConsoleWrite("$iSetting=Disabled" & @CRLF) Case 1 ;Enabled ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "e") ConsoleWrite("$iSetting=Enabled" & @CRLF) If StringLen($sOption) > 0 Then ConsoleWrite("$sOption=" & $sOption & @CRLF) Local $aOpt = StringSplit($sOption, ";", 1) ControlSend($hGPOedit, "", $aOpt[1], $aOpt[2]) EndIf Case 2 ;Configured ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "c") ConsoleWrite("$iSetting=Configured" & @CRLF) Case 3 ;find & exit ;ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "c") ConsoleWrite("$iSetting=find & exit" & @CRLF) Exit EndSwitch ; Apply ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "a") ; Enter ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "{ENTER}") Else ; special $hGPOedit = WinWait("[CLASS:#32770]", "", 1) ; Retrieve the window text of the active window. Local $sText = WinGetText($hGPOedit) ConsoleWrite($sText & @CRLF) If StringLeft($sText, 22) = "Local Security Setting" Then ConsoleWrite("$hGPOedit=special" & @CRLF) Switch $iSetting Case 0 ;Disabled ControlSend($hGPOedit, "", "Button3", "s") ConsoleWrite("$iSetting=Disabled" & @CRLF) Case 1 ;Enabled ControlSend($hGPOedit, "", "Button2", "e") ConsoleWrite("$iSetting=Enabled" & @CRLF) Case 3 ;find & exit ConsoleWrite("$iSetting=find & exit" & @CRLF) Exit EndSwitch ControlSend($hGPOedit, "", "SysTabControl321", "{ENTER}") Sleep(50) If WinExists("Confirm Setting Change") Then ControlSend("Confirm Setting Change", "", "Button1", "y") ; yes EndIf EndIf EndIf ;--------------------------------------------------------------- ;~ Exit ; <-- **************************************************** ControlFocus($hGPO, "", $hTreeView_1) Sleep(50) ControlSend($hGPO, "", $hTreeView_1, "{ALT down}{F4}{ALT up}") $hGPO = WinWait("Microsoft Management Console", "", 1) ControlSend($hGPO, "", "Static2", "{N}") Return $sPolicyItem EndFunc ;==>_GroupPolicy ;---------------------------------------------------------------------------------------- 1. what is new ? find & exit only for find? i run this line _GroupPolicy2.exe "\Computer Configuration\Windows Settings\Security Settings\Local Policies\Security Options" "Microsoft network client: Digitally sign communications (always)" "1" Only it doesn't close my gpo😆 edit: ok i add sleep and it is work... 2. and i want to use headless so i see you use Local $hGPO = WinActivate("Local Group Policy Editor") so I replaced it with the line Local $hGPO = WinWait("Local Group Policy Editor") Do you know another place in the code that can hurt me in headless?the script not run in headless Edited March 26, 2023 by gal9 Link to comment Share on other sites More sharing options...
ioa747 Posted March 27, 2023 Share Posted March 27, 2023 17 hours ago, gal9 said: 1. what is new ? find & exit i run this line _GroupPolicy2.exe "\Computer Configuration\Windows Settings\Security Settings\Local Policies\Security Options" "Microsoft network client: Digitally sign communications (always)" "1" $iSetting - 0=Disabled, 1=Enabled, 2=Configured, 3=find & exit _GroupPolicy2.exe "\Computer Configuration\Windows Settings\Security Settings\Local Policies\Security Options" "Microsoft network client: Digitally sign communications (always)" "3" as the name says find & exit in development state as help tool, if want to check if everything is fine, or if you want catch a control with info tool gal9 1 I know that I know nothing Link to comment Share on other sites More sharing options...
gal9 Posted March 27, 2023 Author Share Posted March 27, 2023 18 hours ago, ioa747 said: *New Setting $iSetting - 0=Disabled, 1=Enabled, 2=Configured, 3=find & exit _GroupPolicy2.au3 expandcollapse popup#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> Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info ; * <--- ;============================================================== ; 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: ; $CmdLine[1] - The path of nodes to navigate. ; $CmdLine[2] - The name of the policy setting to be changed. ; $CmdLine[3] - The value of the policy setting to be changed 0=Disabled, 1=Enabled, 2=Configured ; $CmdLine[4] - Options in form "ClassnameNN;SendKey" ;============================================================== ; "\Computer Configuration\Administrative Templates\Windows Components\Microsoft Edge", "Allow Adobe Flash", 0 ; "\Computer Configuration\Administrative Templates\Windows Components\Connect", "Require pin for pairing", 1, "WindowsForms10.COMBOBOX.app.0.297b065_r69_ad11;f" ; "\Computer Configuration\Windows Settings\Security Settings\Local Policies\Security Options", "Microsoft network client: Digitally sign communications (always)", 3 If Not $CmdLine[0] Then Global $CmdLine[5] = [4, "\Computer Configuration\Windows Settings\Security Settings\Local Policies\Security Options", "Microsoft network client: Digitally sign communications (always)", 3] EndIf Global $iMsgBoxAnswer = "The setting" & @CRLF $iMsgBoxAnswer &= $CmdLine[1] & @CRLF $iMsgBoxAnswer &= $CmdLine[2] & @CRLF $iMsgBoxAnswer &= "will be set to " & $CmdLine[3] & @CRLF $iMsgBoxAnswer = MsgBox(4097, "This Msgbox will time out in 3 seconds", $iMsgBoxAnswer, 3) Select Case $iMsgBoxAnswer = 1 ;OK ;nothing Case $iMsgBoxAnswer = 2 ;Cancel Exit EndSelect ConsoleWrite("$CmdLine[0]=" & $CmdLine[0] & @CRLF) If $CmdLine[0] = 4 Then _GroupPolicy($CmdLine[1], $CmdLine[2], $CmdLine[3], $CmdLine[4]) ElseIf $CmdLine[0] = 3 Then _GroupPolicy($CmdLine[1], $CmdLine[2], $CmdLine[3]) Else $iMsgBoxAnswer = MsgBox(4096, "incorect number of parameters", $CmdLine[0]) EndIf Exit ; #FUNCTION# ;--------------------------------------------------------------------------- ; Name...........: _GroupPolicy() ; Description ...: Opens and uses the Group Policy Editor to configure the given settings ; Syntax.........: _GroupPolicy($sPolicyPath, $sPolicyItem, $iSetting [, $sOption = ""]) ; Parameters ....: $sPolicyPath - The path of nodes to navigate ; $sPolicyItem - The Item/option to navigate/edit ; $iSetting - 0=Disabled, 1=Enabled, 2=Configured, 3=find & exit ; $sOption - Options in form "ClassnameNN;SendKey" ;---------------------------------------------------------------------------------------- Func _GroupPolicy($sPolicyPath, $sPolicyItem, $iSetting, $sOption = "") If Not WinExists("Local Group Policy Editor") Then Run("c:\Windows\system32\mmc.exe " & "C:\share\open_close_gpedit\gpedit_v1.msc /a") WinWait("Local Group Policy Editor", '', 5) EndIf ;Retrieves the 'Local Group Policy Editor' window handle Local $hGPO = WinActivate("Local Group Policy Editor") ConsoleWrite("$hGPO=" & $hGPO & @CRLF) ;Retrieves the SysTreeView321 control handle Local $hTreeView_1 = ControlGetHandle($hGPO, "", "SysTreeView321") ;Sets the focus to $hTreeView_1 ControlFocus($hGPO, "", $hTreeView_1) Sleep(50) $sPolicyPath = "Local Computer Policy" & $sPolicyPath ConsoleWrite("$sPolicyPath=" & $sPolicyPath & @CRLF) ConsoleWrite("$sPolicyItem=" & $sPolicyItem & @CRLF) Local $aPath = StringSplit($sPolicyPath, "\", 1) Local $tmpPath = "" ;ConsoleWrite("" & @CRLF) 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}") Sleep(50) ;Retrieves the SysListView321 control handle Local $hListView = ControlGetHandle($hGPO, "", "SysListView321") ;Sets the focus to SysListView321 ControlFocus($hGPO, "", $hListView) Sleep(50) ;find the item Local $FindItem = ControlListView($hGPO, "", $hListView, "FindItem", $sPolicyItem) Sleep(500) 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 it ControlSend($hGPO, '', $hListView, '{ENTER}') ;--------------------------------------------------------------- Local $hGPOedit = WinWait("[CLASS:WindowsForms10.Window.8.app.0.297b065_r69_ad1]", "", 1) ConsoleWrite("$hGPOedit=" & $hGPOedit & @CRLF) If WinExists($hGPOedit) Then ; normal ConsoleWrite("$hGPOedit=normal" & @CRLF) ControlFocus($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16") Switch $iSetting Case 0 ;Disabled ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "d") ConsoleWrite("$iSetting=Disabled" & @CRLF) Case 1 ;Enabled ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "e") ConsoleWrite("$iSetting=Enabled" & @CRLF) If StringLen($sOption) > 0 Then ConsoleWrite("$sOption=" & $sOption & @CRLF) Local $aOpt = StringSplit($sOption, ";", 1) ControlSend($hGPOedit, "", $aOpt[1], $aOpt[2]) EndIf Case 2 ;Configured ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "c") ConsoleWrite("$iSetting=Configured" & @CRLF) Case 3 ;find & exit ;ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "c") ConsoleWrite("$iSetting=find & exit" & @CRLF) Exit EndSwitch ; Apply ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "a") ; Enter ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "{ENTER}") Else ; special $hGPOedit = WinWait("[CLASS:#32770]", "", 1) ; Retrieve the window text of the active window. Local $sText = WinGetText($hGPOedit) ConsoleWrite($sText & @CRLF) If StringLeft($sText, 22) = "Local Security Setting" Then ConsoleWrite("$hGPOedit=special" & @CRLF) Switch $iSetting Case 0 ;Disabled ControlSend($hGPOedit, "", "Button3", "s") ConsoleWrite("$iSetting=Disabled" & @CRLF) Case 1 ;Enabled ControlSend($hGPOedit, "", "Button2", "e") ConsoleWrite("$iSetting=Enabled" & @CRLF) Case 3 ;find & exit ConsoleWrite("$iSetting=find & exit" & @CRLF) Exit EndSwitch ControlSend($hGPOedit, "", "SysTabControl321", "{ENTER}") Sleep(50) If WinExists("Confirm Setting Change") Then ControlSend("Confirm Setting Change", "", "Button1", "y") ; yes EndIf EndIf EndIf ;--------------------------------------------------------------- ;~ Exit ; <-- **************************************************** ControlFocus($hGPO, "", $hTreeView_1) Sleep(50) ControlSend($hGPO, "", $hTreeView_1, "{ALT down}{F4}{ALT up}") $hGPO = WinWait("Microsoft Management Console", "", 1) ControlSend($hGPO, "", "Static2", "{N}") Return $sPolicyItem EndFunc ;==>_GroupPolicy ;---------------------------------------------------------------------------------------- Trying to convert the code and replace ControlFocus with SetFocus for headless mode failed. Without success, I would appreciate the help expandcollapse popup#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> Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info ; * <--- ;============================================================== ; 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: ; $CmdLine[1] - The path of nodes to navigate. ; $CmdLine[2] - The name of the policy setting to be changed. ; $CmdLine[3] - The value of the policy setting to be changed 0=Disabled, 1=Enabled, 2=Configured ; $CmdLine[4] - Options in form "ClassnameNN;SendKey" ;============================================================== ; "\Computer Configuration\Administrative Templates\Windows Components\Microsoft Edge", "Allow Adobe Flash", 0 ; "\Computer Configuration\Administrative Templates\Windows Components\Connect", "Require pin for pairing", 1, "WindowsForms10.COMBOBOX.app.0.297b065_r69_ad11;f" ; "\Computer Configuration\Windows Settings\Security Settings\Local Policies\Security Options", "Microsoft network client: Digitally sign communications (always)", 3 If Not $CmdLine[0] Then Global $CmdLine[5] = [4, "\Computer Configuration\Windows Settings\Security Settings\Local Policies\Security Options", "Microsoft network client: Digitally sign communications (always)", 3] EndIf Global $iMsgBoxAnswer = "The setting" & @CRLF $iMsgBoxAnswer &= $CmdLine[1] & @CRLF $iMsgBoxAnswer &= $CmdLine[2] & @CRLF $iMsgBoxAnswer &= "will be set to " & $CmdLine[3] & @CRLF $iMsgBoxAnswer = MsgBox(4097, "This Msgbox will time out in 3 seconds", $iMsgBoxAnswer, 3) Select Case $iMsgBoxAnswer = 1 ;OK ;nothing Case $iMsgBoxAnswer = 2 ;Cancel Exit EndSelect ConsoleWrite("$CmdLine[0]=" & $CmdLine[0] & @CRLF) If $CmdLine[0] = 4 Then _GroupPolicy($CmdLine[1], $CmdLine[2], $CmdLine[3], $CmdLine[4]) ElseIf $CmdLine[0] = 3 Then _GroupPolicy($CmdLine[1], $CmdLine[2], $CmdLine[3]) Else $iMsgBoxAnswer = MsgBox(4096, "incorect number of parameters", $CmdLine[0]) EndIf Exit ; #FUNCTION# ;--------------------------------------------------------------------------- ; Name...........: _GroupPolicy() ; Description ...: Opens and uses the Group Policy Editor to configure the given settings ; Syntax.........: _GroupPolicy($sPolicyPath, $sPolicyItem, $iSetting [, $sOption = ""]) ; Parameters ....: $sPolicyPath - The path of nodes to navigate ; $sPolicyItem - The Item/option to navigate/edit ; $iSetting - 0=Disabled, 1=Enabled, 2=Configured, 3=find & exit ; $sOption - Options in form "ClassnameNN;SendKey" ;---------------------------------------------------------------------------------------- Func _GroupPolicy($sPolicyPath, $sPolicyItem, $iSetting, $sOption = "") If Not WinExists("Local Group Policy Editor") Then Run("c:\Windows\system32\mmc.exe " & "C:\share\open_close_gpedit\gpedit_v1.msc /a") WinWait("Local Group Policy Editor", '', 5) EndIf ;Retrieves the 'Local Group Policy Editor' window handle Local $hGPO = WinWait("Local Group Policy Editor") ConsoleWrite("$hGPO=" & $hGPO & @CRLF) ;Retrieves the SysTreeView321 control handle Local $hTreeView_1 = ControlGetHandle($hGPO, "", "SysTreeView321") ;Sets the focus to $hTreeView_1 ControlGetHandle($hGPO, "", $hTreeView_1) Sleep(50) $sPolicyPath = "Local Computer Policy" & $sPolicyPath ConsoleWrite("$sPolicyPath=" & $sPolicyPath & @CRLF) ConsoleWrite("$sPolicyItem=" & $sPolicyItem & @CRLF) Local $aPath = StringSplit($sPolicyPath, "\", 1) Local $tmpPath = "" ;ConsoleWrite("" & @CRLF) 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 ControlGetHandle($hGPO, "", "AMCCustomTab1") ControlSend($hGPO, "", "AMCCustomTab1", "{RIGHT}") Sleep(50) ;Retrieves the SysListView321 control handle Local $hListView = ControlGetHandle($hGPO, "", "SysListView321") ;Sets the focus to SysListView321 ControlGetHandle($hGPO, "", $hListView) Sleep(50) ;find the item Local $FindItem = ControlListView($hGPO, "", $hListView, "FindItem", $sPolicyItem) Sleep(500) 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 it ControlSend($hGPO, '', $hListView, '{ENTER}') ;--------------------------------------------------------------- Local $hGPOedit = WinWait("[CLASS:WindowsForms10.Window.8.app.0.297b065_r69_ad1]", "", 1) ConsoleWrite("$hGPOedit=" & $hGPOedit & @CRLF) If WinExists($hGPOedit) Then ; normal ConsoleWrite("$hGPOedit=normal" & @CRLF) ControlGetHandle($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16") Switch $iSetting Case 0 ;Disabled ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "d") ConsoleWrite("$iSetting=Disabled" & @CRLF) Case 1 ;Enabled ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "e") ConsoleWrite("$iSetting=Enabled" & @CRLF) If StringLen($sOption) > 0 Then ConsoleWrite("$sOption=" & $sOption & @CRLF) Local $aOpt = StringSplit($sOption, ";", 1) ControlSend($hGPOedit, "", $aOpt[1], $aOpt[2]) EndIf Case 2 ;Configured ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "c") ConsoleWrite("$iSetting=Configured" & @CRLF) Case 3 ;find & exit ;ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "c") ConsoleWrite("$iSetting=find & exit" & @CRLF) Exit EndSwitch ; Apply ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "a") ; Enter ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "{ENTER}") Else ; special $hGPOedit = WinWait("[CLASS:#32770]", "", 1) ; Retrieve the window text of the active window. Local $sText = WinGetText($hGPOedit) ConsoleWrite($sText & @CRLF) If StringLeft($sText, 22) = "Local Security Setting" Then ConsoleWrite("$hGPOedit=special" & @CRLF) Switch $iSetting Case 0 ;Disabled ControlSend($hGPOedit, "", "Button3", "s") ConsoleWrite("$iSetting=Disabled" & @CRLF) Case 1 ;Enabled ControlSend($hGPOedit, "", "Button2", "e") ConsoleWrite("$iSetting=Enabled" & @CRLF) Case 3 ;find & exit ConsoleWrite("$iSetting=find & exit" & @CRLF) Exit EndSwitch ControlSend($hGPOedit, "", "SysTabControl321", "{ENTER}") Sleep(50) If WinExists("Confirm Setting Change") Then ControlSend("Confirm Setting Change", "", "Button1", "y") ; yes EndIf EndIf EndIf ;--------------------------------------------------------------- ;~ Exit ; <-- **************************************************** Sleep(100) ControlGetHandle($hGPO, "", $hTreeView_1) Sleep(50) ControlSend($hGPO, "", $hTreeView_1, "{ALT down}{F4}{ALT up}") $hGPO = WinWait("Microsoft Management Console", "", 1) ControlSend($hGPO, "", "Static2", "{N}") Return $sPolicyItem EndFunc ;==>_GroupPolicy ;---------------------------------------------------------------------------------------- Link to comment Share on other sites More sharing options...
gal9 Posted March 27, 2023 Author Share Posted March 27, 2023 1 minute ago, ioa747 said: $iSetting - 0=Disabled, 1=Enabled, 2=Configured, 3=find & exit _GroupPolicy2.exe "\Computer Configuration\Windows Settings\Security Settings\Local Policies\Security Options" "Microsoft network client: Digitally sign communications (always)" "3" as the name says find & exit in development state as help tool, if want to check if everything is fine, or if you want catch a control with info tool yes it works for me and the code work for me only the headless mode Link to comment Share on other sites More sharing options...
ioa747 Posted March 27, 2023 Share Posted March 27, 2023 I edited them where I found them, take a look to see if I missed something expandcollapse popup#RequireAdmin #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <Constants.au3> #include <Array.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <GuiButton.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> ;~ Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info ; * <--- ;============================================================== ; 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: ; $CmdLine[1] - $sPolicyPath - The path of nodes to navigate ; $CmdLine[2] - $sPolicyItem - The Item/option to navigate/edit ; $CmdLine[3] - $iSetting - T0=Disabled, 1=Enabled, 2=Configured, 3=find & exit ; $CmdLine[4] - $sOption - Optional Options in form "ClassnameNN;SendKey" ;============================================================== ; EXAMPLES: ; "\Computer Configuration\Administrative Templates\Windows Components\Microsoft Edge", "Allow Adobe Flash", 0 ; * - Normal ; "\Computer Configuration\Windows Settings\Security Settings\Local Policies\Security Options", "Microsoft network client: Digitally sign communications (always)", 3 ; * - Special ; "\Computer Configuration\Administrative Templates\Windows Components\Connect", "Require pin for pairing", 1, "WindowsForms10.COMBOBOX.app.0.297b065_r69_ad11;f" ; * - With Option ; Global $CmdLine[5] = [4, "\Computer Configuration\Administrative Templates\Windows Components\Microsoft Edge", "Allow Adobe Flash", 0] If Not $CmdLine[0] Then Global $CmdLine[5] $CmdLine[0] = 4 ;cnt $CmdLine[1] = "\Computer Configuration\Administrative Templates\Windows Components\Microsoft Edge" $CmdLine[2] = "Allow Adobe Flash" $CmdLine[3] = 0 $CmdLine[4] = "" ;optional EndIf Global $iMsgBoxAnswer = "The setting" & @CRLF $iMsgBoxAnswer &= $CmdLine[1] & @CRLF $iMsgBoxAnswer &= $CmdLine[2] & @CRLF $iMsgBoxAnswer &= "will be set to " & $CmdLine[3] & @CRLF $iMsgBoxAnswer = MsgBox(4097, "This Msgbox will time out in 3 seconds", $iMsgBoxAnswer, 3) Select Case $iMsgBoxAnswer = 1 ;OK ;nothing Case $iMsgBoxAnswer = 2 ;Cancel Exit EndSelect ConsoleWrite("$CmdLine[0]=" & $CmdLine[0] & @CRLF) If $CmdLine[0] = 4 Then _GroupPolicy($CmdLine[1], $CmdLine[2], $CmdLine[3], $CmdLine[4]) ElseIf $CmdLine[0] = 3 Then _GroupPolicy($CmdLine[1], $CmdLine[2], $CmdLine[3]) Else $iMsgBoxAnswer = MsgBox(4096, "incorect number of parameters", $CmdLine[0]) EndIf Exit ; #FUNCTION# ;--------------------------------------------------------------------------- ; Name...........: _GroupPolicy() ; Description ...: Opens and uses the Group Policy Editor to configure the given settings ; Syntax.........: _GroupPolicy($sPolicyPath, $sPolicyItem, $iSetting [, $sOption = ""]) ; Parameters ....: $sPolicyPath - The path of nodes to navigate ; $sPolicyItem - The Item/option to navigate/edit ; $iSetting - 0=Disabled, 1=Enabled, 2=Configured, 3=find & exit ; $sOption - Options in form "ClassnameNN;SendKey" ;---------------------------------------------------------------------------------------- Func _GroupPolicy($sPolicyPath, $sPolicyItem, $iSetting, $sOption = "") If Not WinExists("Local Group Policy Editor") Then Run("c:\Windows\system32\mmc.exe " & "C:\share\open_close_gpedit\gpedit_v1.msc /a") WinWait("Local Group Policy Editor", '', 5) EndIf ;Retrieves the 'Local Group Policy Editor' window handle 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) ConsoleWrite("--- $iSetting=" & $iSetting & @CRLF) ConsoleWrite("--- $sOption=" & $sOption & @CRLF) Local $aPath = StringSplit($sPolicyPath, "\", 1) Local $tmpPath = "" ;Expant the path in $hTreeView_1 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 ControlSend($hGPO, "", "AMCCustomTab1", "{RIGHT}") Sleep(50) ;Retrieves the SysListView321 control handle Local $hListView = ControlGetHandle($hGPO, "", "SysListView321") ;find the item Local $FindItem = ControlListView($hGPO, "", $hListView, "FindItem", $sPolicyItem) Sleep(500) 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) ;snap Selected Item Local $SelectedItem = ControlListView($hGPO, "", $hListView, "GetSelected") ConsoleWrite("- $SelectedItem=" & $SelectedItem & @CRLF) Sleep(50) Local $ItemTxt[4] ;Returns the text of a given Item to ItemTxt[0]=col0, item[1]=col1, ... For $i = 0 To 3 $ItemTxt[$i] = ControlListView($hGPO, "", $hListView, "GetText", Int($SelectedItem), $i) ConsoleWrite("$ItemTxt[" & $i & "]=" & $ItemTxt[$i] & @CRLF) Next ;and send enter to open it ControlSend($hGPO, '', $hListView, '{ENTER}') ;--------------------------------------------------------------- Local $hGPOedit = WinWait("[CLASS:WindowsForms10.Window.8.app.0.297b065_r69_ad1]", "", 1) ConsoleWrite("- $hGPOedit=" & $hGPOedit & @CRLF) If WinExists($hGPOedit) Then ; normal <- ConsoleWrite("> $hGPOedit=normal <" & @CRLF) Switch $iSetting Case 0 ;Disabled ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "d") ConsoleWrite("-> Disabled" & @CRLF) Case 1 ;Enabled ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "e") ConsoleWrite("-> Enabled" & @CRLF) If StringLen($sOption) > 0 Then ConsoleWrite("- $sOption=" & $sOption & @CRLF) Local $aOpt = StringSplit($sOption, ";", 1) ControlSend($hGPOedit, "", $aOpt[1], $aOpt[2]) EndIf Case 2 ;Configured ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "c") ConsoleWrite("-> Configured" & @CRLF) Case 3 ;find & exit ConsoleWrite("-> find & exit" & @CRLF) Exit EndSwitch ;Apply ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "a") ;Enter ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "{ENTER}") Else ;special <- $hGPOedit = WinWait("[CLASS:#32770]", "", 1) ;Retrieve the window text of the active window. Local $sText = WinGetText($hGPOedit) ;ConsoleWrite($sText & @CRLF) If StringLeft($sText, 22) = "Local Security Setting" Then ; * <- if "Local Security Setting" ConsoleWrite("> $hGPOedit=special <" & @CRLF) Switch $iSetting Case 0 ;Disabled ControlSend($hGPOedit, "", "Button3", "s") ConsoleWrite("-> Disabled" & @CRLF) Case 1 ;Enabled ControlSend($hGPOedit, "", "Button2", "e") ConsoleWrite("-> Enabled" & @CRLF) Case 3 ;find & exit ConsoleWrite("-> find & exit" & @CRLF) Exit EndSwitch ControlSend($hGPOedit, "", "SysTabControl321", "{ENTER}") Sleep(50) If WinExists("Confirm Setting Change") Then ControlSend("Confirm Setting Change", "", "Button1", "y") ; yes EndIf EndIf EndIf ;--------------------------------------------------------------- ;snap Selected Item $SelectedItem = ControlListView($hGPO, "", $hListView, "GetSelected") ConsoleWrite("- $SelectedItem=" & $SelectedItem & @CRLF) Sleep(50) ;Returns the text of a given Item to ItemTxt[0]=col0, item[1]=col1, ... For $i = 0 To 3 $ItemTxt[$i] = ControlListView($hGPO, "", $hListView, "GetText", Int($SelectedItem), $i) ConsoleWrite("$ItemTxt[" & $i & "]=" & $ItemTxt[$i] & @CRLF) Next ;~ Exit ; <-- **************************************************** Sleep(50) ControlSend($hGPO, "", $hTreeView_1, "{ALT down}{F4}{ALT up}") $hGPO = WinWait("Microsoft Management Console", "", 1) ControlSend($hGPO, "", "Static2", "{N}") Return $sPolicyItem EndFunc ;==>_GroupPolicy ;---------------------------------------------------------------------------------------- I know that I know nothing Link to comment Share on other sites More sharing options...
gal9 Posted March 27, 2023 Author Share Posted March 27, 2023 (edited) 6 minutes ago, ioa747 said: I edited them where I found them, take a look to see if I missed something expandcollapse popup#RequireAdmin #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <Constants.au3> #include <Array.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <GuiButton.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> ;~ Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info ; * <--- ;============================================================== ; 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: ; $CmdLine[1] - $sPolicyPath - The path of nodes to navigate ; $CmdLine[2] - $sPolicyItem - The Item/option to navigate/edit ; $CmdLine[3] - $iSetting - T0=Disabled, 1=Enabled, 2=Configured, 3=find & exit ; $CmdLine[4] - $sOption - Optional Options in form "ClassnameNN;SendKey" ;============================================================== ; EXAMPLES: ; "\Computer Configuration\Administrative Templates\Windows Components\Microsoft Edge", "Allow Adobe Flash", 0 ; * - Normal ; "\Computer Configuration\Windows Settings\Security Settings\Local Policies\Security Options", "Microsoft network client: Digitally sign communications (always)", 3 ; * - Special ; "\Computer Configuration\Administrative Templates\Windows Components\Connect", "Require pin for pairing", 1, "WindowsForms10.COMBOBOX.app.0.297b065_r69_ad11;f" ; * - With Option ; Global $CmdLine[5] = [4, "\Computer Configuration\Administrative Templates\Windows Components\Microsoft Edge", "Allow Adobe Flash", 0] If Not $CmdLine[0] Then Global $CmdLine[5] $CmdLine[0] = 4 ;cnt $CmdLine[1] = "\Computer Configuration\Administrative Templates\Windows Components\Microsoft Edge" $CmdLine[2] = "Allow Adobe Flash" $CmdLine[3] = 0 $CmdLine[4] = "" ;optional EndIf Global $iMsgBoxAnswer = "The setting" & @CRLF $iMsgBoxAnswer &= $CmdLine[1] & @CRLF $iMsgBoxAnswer &= $CmdLine[2] & @CRLF $iMsgBoxAnswer &= "will be set to " & $CmdLine[3] & @CRLF $iMsgBoxAnswer = MsgBox(4097, "This Msgbox will time out in 3 seconds", $iMsgBoxAnswer, 3) Select Case $iMsgBoxAnswer = 1 ;OK ;nothing Case $iMsgBoxAnswer = 2 ;Cancel Exit EndSelect ConsoleWrite("$CmdLine[0]=" & $CmdLine[0] & @CRLF) If $CmdLine[0] = 4 Then _GroupPolicy($CmdLine[1], $CmdLine[2], $CmdLine[3], $CmdLine[4]) ElseIf $CmdLine[0] = 3 Then _GroupPolicy($CmdLine[1], $CmdLine[2], $CmdLine[3]) Else $iMsgBoxAnswer = MsgBox(4096, "incorect number of parameters", $CmdLine[0]) EndIf Exit ; #FUNCTION# ;--------------------------------------------------------------------------- ; Name...........: _GroupPolicy() ; Description ...: Opens and uses the Group Policy Editor to configure the given settings ; Syntax.........: _GroupPolicy($sPolicyPath, $sPolicyItem, $iSetting [, $sOption = ""]) ; Parameters ....: $sPolicyPath - The path of nodes to navigate ; $sPolicyItem - The Item/option to navigate/edit ; $iSetting - 0=Disabled, 1=Enabled, 2=Configured, 3=find & exit ; $sOption - Options in form "ClassnameNN;SendKey" ;---------------------------------------------------------------------------------------- Func _GroupPolicy($sPolicyPath, $sPolicyItem, $iSetting, $sOption = "") If Not WinExists("Local Group Policy Editor") Then Run("c:\Windows\system32\mmc.exe " & "C:\share\open_close_gpedit\gpedit_v1.msc /a") WinWait("Local Group Policy Editor", '', 5) EndIf ;Retrieves the 'Local Group Policy Editor' window handle 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) ConsoleWrite("--- $iSetting=" & $iSetting & @CRLF) ConsoleWrite("--- $sOption=" & $sOption & @CRLF) Local $aPath = StringSplit($sPolicyPath, "\", 1) Local $tmpPath = "" ;Expant the path in $hTreeView_1 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 ControlSend($hGPO, "", "AMCCustomTab1", "{RIGHT}") Sleep(50) ;Retrieves the SysListView321 control handle Local $hListView = ControlGetHandle($hGPO, "", "SysListView321") ;find the item Local $FindItem = ControlListView($hGPO, "", $hListView, "FindItem", $sPolicyItem) Sleep(500) 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) ;snap Selected Item Local $SelectedItem = ControlListView($hGPO, "", $hListView, "GetSelected") ConsoleWrite("- $SelectedItem=" & $SelectedItem & @CRLF) Sleep(50) Local $ItemTxt[4] ;Returns the text of a given Item to ItemTxt[0]=col0, item[1]=col1, ... For $i = 0 To 3 $ItemTxt[$i] = ControlListView($hGPO, "", $hListView, "GetText", Int($SelectedItem), $i) ConsoleWrite("$ItemTxt[" & $i & "]=" & $ItemTxt[$i] & @CRLF) Next ;and send enter to open it ControlSend($hGPO, '', $hListView, '{ENTER}') ;--------------------------------------------------------------- Local $hGPOedit = WinWait("[CLASS:WindowsForms10.Window.8.app.0.297b065_r69_ad1]", "", 1) ConsoleWrite("- $hGPOedit=" & $hGPOedit & @CRLF) If WinExists($hGPOedit) Then ; normal <- ConsoleWrite("> $hGPOedit=normal <" & @CRLF) Switch $iSetting Case 0 ;Disabled ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "d") ConsoleWrite("-> Disabled" & @CRLF) Case 1 ;Enabled ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "e") ConsoleWrite("-> Enabled" & @CRLF) If StringLen($sOption) > 0 Then ConsoleWrite("- $sOption=" & $sOption & @CRLF) Local $aOpt = StringSplit($sOption, ";", 1) ControlSend($hGPOedit, "", $aOpt[1], $aOpt[2]) EndIf Case 2 ;Configured ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "c") ConsoleWrite("-> Configured" & @CRLF) Case 3 ;find & exit ConsoleWrite("-> find & exit" & @CRLF) Exit EndSwitch ;Apply ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "a") ;Enter ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "{ENTER}") Else ;special <- $hGPOedit = WinWait("[CLASS:#32770]", "", 1) ;Retrieve the window text of the active window. Local $sText = WinGetText($hGPOedit) ;ConsoleWrite($sText & @CRLF) If StringLeft($sText, 22) = "Local Security Setting" Then ; * <- if "Local Security Setting" ConsoleWrite("> $hGPOedit=special <" & @CRLF) Switch $iSetting Case 0 ;Disabled ControlSend($hGPOedit, "", "Button3", "s") ConsoleWrite("-> Disabled" & @CRLF) Case 1 ;Enabled ControlSend($hGPOedit, "", "Button2", "e") ConsoleWrite("-> Enabled" & @CRLF) Case 3 ;find & exit ConsoleWrite("-> find & exit" & @CRLF) Exit EndSwitch ControlSend($hGPOedit, "", "SysTabControl321", "{ENTER}") Sleep(50) If WinExists("Confirm Setting Change") Then ControlSend("Confirm Setting Change", "", "Button1", "y") ; yes EndIf EndIf EndIf ;--------------------------------------------------------------- ;snap Selected Item $SelectedItem = ControlListView($hGPO, "", $hListView, "GetSelected") ConsoleWrite("- $SelectedItem=" & $SelectedItem & @CRLF) Sleep(50) ;Returns the text of a given Item to ItemTxt[0]=col0, item[1]=col1, ... For $i = 0 To 3 $ItemTxt[$i] = ControlListView($hGPO, "", $hListView, "GetText", Int($SelectedItem), $i) ConsoleWrite("$ItemTxt[" & $i & "]=" & $ItemTxt[$i] & @CRLF) Next ;~ Exit ; <-- **************************************************** Sleep(50) ControlSend($hGPO, "", $hTreeView_1, "{ALT down}{F4}{ALT up}") $hGPO = WinWait("Microsoft Management Console", "", 1) ControlSend($hGPO, "", "Static2", "{N}") Return $sPolicyItem EndFunc ;==>_GroupPolicy ;---------------------------------------------------------------------------------------- It doesn't close the gpo and it changes another setting https://www.dropbox.com/s/k8nn4pp5zlepbrs/hadles.mp4?dl=0 i try change "Require pin for pairing" Edited March 27, 2023 by gal9 Link to comment Share on other sites More sharing options...
ioa747 Posted March 27, 2023 Share Posted March 27, 2023 (edited) run the script first, see if it works, and then from the command line expandcollapse popup#RequireAdmin #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <Constants.au3> #include <Array.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <GuiButton.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> ;~ Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info ; * <--- ;============================================================== ; 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: ; $CmdLine[1] - $sPolicyPath - The path of nodes to navigate ; $CmdLine[2] - $sPolicyItem - The Item/option to navigate/edit ; $CmdLine[3] - $iSetting - T0=Disabled, 1=Enabled, 2=Configured, 3=find & exit ; $CmdLine[4] - $sOption - Optional Options in form "ClassnameNN;SendKey" ;============================================================== ; EXAMPLES: ; "\Computer Configuration\Administrative Templates\Windows Components\Microsoft Edge", "Allow Adobe Flash", 0 ; * - Normal ; "\Computer Configuration\Windows Settings\Security Settings\Local Policies\Security Options", "Microsoft network client: Digitally sign communications (always)", 3 ; * - Special ; "\Computer Configuration\Administrative Templates\Windows Components\Connect", "Require pin for pairing", 1, "WindowsForms10.COMBOBOX.app.0.297b065_r69_ad11;f" ; * - With Option ; Global $CmdLine[5] = [4, "\Computer Configuration\Administrative Templates\Windows Components\Microsoft Edge", "Allow Adobe Flash", 0] If Not $CmdLine[0] Then Global $CmdLine[5] $CmdLine[0] = 4 ;cnt $CmdLine[1] = "\Computer Configuration\Administrative Templates\Windows Components\Connect" $CmdLine[2] = "Require pin for pairing" $CmdLine[3] = 1 $CmdLine[4] = "WindowsForms10.COMBOBOX.app.0.297b065_r69_ad11;f" ;optional EndIf Global $iMsgBoxAnswer = "The setting" & @CRLF $iMsgBoxAnswer &= $CmdLine[1] & @CRLF $iMsgBoxAnswer &= $CmdLine[2] & @CRLF $iMsgBoxAnswer &= "will be set to " & $CmdLine[3] & @CRLF $iMsgBoxAnswer = MsgBox(4097, "This Msgbox will time out in 3 seconds", $iMsgBoxAnswer, 3) Select Case $iMsgBoxAnswer = 1 ;OK ;nothing Case $iMsgBoxAnswer = 2 ;Cancel Exit EndSelect ConsoleWrite("$CmdLine[0]=" & $CmdLine[0] & @CRLF) If $CmdLine[0] = 4 Then _GroupPolicy($CmdLine[1], $CmdLine[2], $CmdLine[3], $CmdLine[4]) ElseIf $CmdLine[0] = 3 Then _GroupPolicy($CmdLine[1], $CmdLine[2], $CmdLine[3]) Else $iMsgBoxAnswer = MsgBox(4096, "incorect number of parameters", $CmdLine[0]) EndIf Exit ; #FUNCTION# ;--------------------------------------------------------------------------- ; Name...........: _GroupPolicy() ; Description ...: Opens and uses the Group Policy Editor to configure the given settings ; Syntax.........: _GroupPolicy($sPolicyPath, $sPolicyItem, $iSetting [, $sOption = ""]) ; Parameters ....: $sPolicyPath - The path of nodes to navigate ; $sPolicyItem - The Item/option to navigate/edit ; $iSetting - 0=Disabled, 1=Enabled, 2=Configured, 3=find & exit ; $sOption - Options in form "ClassnameNN;SendKey" ;---------------------------------------------------------------------------------------- Func _GroupPolicy($sPolicyPath, $sPolicyItem, $iSetting, $sOption = "") If Not WinExists("Local Group Policy Editor") Then Run("c:\Windows\system32\mmc.exe " & "C:\share\open_close_gpedit\gpedit_v1.msc /a") EndIf ;Retrieves the 'Local Group Policy Editor' window handle Local $hGPO = WinWait("Local Group Policy Editor", '', 5) 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) ConsoleWrite("--- $iSetting=" & $iSetting & @CRLF) ConsoleWrite("--- $sOption=" & $sOption & @CRLF) Local $aPath = StringSplit($sPolicyPath, "\", 1) Local $tmpPath = "" ;Expant the path in $hTreeView_1 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 ControlSend($hGPO, "", "AMCCustomTab1", "{RIGHT}") Sleep(50) ;Retrieves the SysListView321 control handle Local $hListView = ControlGetHandle($hGPO, "", "SysListView321") ;find the item Local $FindItem = ControlListView($hGPO, "", $hListView, "FindItem", $sPolicyItem) Sleep(500) 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) ;snap Selected Item Local $SelectedItem = ControlListView($hGPO, "", $hListView, "GetSelected") ConsoleWrite("- $SelectedItem=" & $SelectedItem & @CRLF) Sleep(50) Local $ItemTxt[4] ;Returns the text of a given Item to ItemTxt[0]=col0, item[1]=col1, ... For $i = 0 To 3 $ItemTxt[$i] = ControlListView($hGPO, "", $hListView, "GetText", Int($SelectedItem), $i) ConsoleWrite("$ItemTxt[" & $i & "]=" & $ItemTxt[$i] & @CRLF) Next ;and send enter to open it ControlSend($hGPO, '', $hListView, '{ENTER}') ;--------------------------------------------------------------- Local $hGPOedit = WinWait("[CLASS:WindowsForms10.Window.8.app.0.297b065_r69_ad1]", "", 1) ConsoleWrite("- $hGPOedit=" & $hGPOedit & @CRLF) If WinExists($hGPOedit) Then ; normal <- ConsoleWrite("> $hGPOedit=normal <" & @CRLF) Switch $iSetting Case 0 ;Disabled ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "d") ConsoleWrite("-> Disabled" & @CRLF) Case 1 ;Enabled ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "e") ConsoleWrite("-> Enabled" & @CRLF) If StringLen($sOption) > 0 Then ConsoleWrite("- $sOption=" & $sOption & @CRLF) Local $aOpt = StringSplit($sOption, ";", 1) ControlSend($hGPOedit, "", $aOpt[1], $aOpt[2]) EndIf Case 2 ;Configured ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "c") ConsoleWrite("-> Configured" & @CRLF) Case 3 ;find & exit ConsoleWrite("-> find & exit" & @CRLF) Exit EndSwitch ;Apply ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "a") ;Enter ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "{ENTER}") Else ;special <- $hGPOedit = WinWait("[CLASS:#32770]", "", 1) ;Retrieve the window text of the active window. Local $sText = WinGetText($hGPOedit) ;ConsoleWrite($sText & @CRLF) If StringLeft($sText, 22) = "Local Security Setting" Then ; * <- if "Local Security Setting" ConsoleWrite("> $hGPOedit=special <" & @CRLF) Switch $iSetting Case 0 ;Disabled ControlSend($hGPOedit, "", "Button3", "s") ConsoleWrite("-> Disabled" & @CRLF) Case 1 ;Enabled ControlSend($hGPOedit, "", "Button2", "e") ConsoleWrite("-> Enabled" & @CRLF) Case 3 ;find & exit ConsoleWrite("-> find & exit" & @CRLF) Exit EndSwitch ControlSend($hGPOedit, "", "SysTabControl321", "{ENTER}") Sleep(50) If WinExists("Confirm Setting Change") Then ControlSend("Confirm Setting Change", "", "Button1", "y") ; yes EndIf EndIf EndIf ;--------------------------------------------------------------- ;snap Selected Item $SelectedItem = ControlListView($hGPO, "", $hListView, "GetSelected") ConsoleWrite("- $SelectedItem=" & $SelectedItem & @CRLF) Sleep(50) ;Returns the text of a given Item to ItemTxt[0]=col0, item[1]=col1, ... For $i = 0 To 3 $ItemTxt[$i] = ControlListView($hGPO, "", $hListView, "GetText", Int($SelectedItem), $i) ConsoleWrite("$ItemTxt[" & $i & "]=" & $ItemTxt[$i] & @CRLF) Next ;~ Exit ; <-- **************************************************** Sleep(50) ControlSend($hGPO, "", $hTreeView_1, "{ALT down}{F4}{ALT up}") $hGPO = WinWait("Microsoft Management Console", "", 1) ControlSend($hGPO, "", "Static2", "{N}") Return $sPolicyItem EndFunc ;==>_GroupPolicy ;---------------------------------------------------------------------------------------- edit: I deleted another one WinActivate() Edited March 27, 2023 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
ioa747 Posted March 27, 2023 Share Posted March 27, 2023 19 minutes ago, ioa747 said: I deleted another one WinActivate() I know that I know nothing Link to comment Share on other sites More sharing options...
gal9 Posted March 27, 2023 Author Share Posted March 27, 2023 20 minutes ago, ioa747 said: run the script first, see if it works, and then from the command line expandcollapse popup#RequireAdmin #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <Constants.au3> #include <Array.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <GuiButton.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> ;~ Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info ; * <--- ;============================================================== ; 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: ; $CmdLine[1] - $sPolicyPath - The path of nodes to navigate ; $CmdLine[2] - $sPolicyItem - The Item/option to navigate/edit ; $CmdLine[3] - $iSetting - T0=Disabled, 1=Enabled, 2=Configured, 3=find & exit ; $CmdLine[4] - $sOption - Optional Options in form "ClassnameNN;SendKey" ;============================================================== ; EXAMPLES: ; "\Computer Configuration\Administrative Templates\Windows Components\Microsoft Edge", "Allow Adobe Flash", 0 ; * - Normal ; "\Computer Configuration\Windows Settings\Security Settings\Local Policies\Security Options", "Microsoft network client: Digitally sign communications (always)", 3 ; * - Special ; "\Computer Configuration\Administrative Templates\Windows Components\Connect", "Require pin for pairing", 1, "WindowsForms10.COMBOBOX.app.0.297b065_r69_ad11;f" ; * - With Option ; Global $CmdLine[5] = [4, "\Computer Configuration\Administrative Templates\Windows Components\Microsoft Edge", "Allow Adobe Flash", 0] If Not $CmdLine[0] Then Global $CmdLine[5] $CmdLine[0] = 4 ;cnt $CmdLine[1] = "\Computer Configuration\Administrative Templates\Windows Components\Connect" $CmdLine[2] = "Require pin for pairing" $CmdLine[3] = 1 $CmdLine[4] = "WindowsForms10.COMBOBOX.app.0.297b065_r69_ad11;f" ;optional EndIf Global $iMsgBoxAnswer = "The setting" & @CRLF $iMsgBoxAnswer &= $CmdLine[1] & @CRLF $iMsgBoxAnswer &= $CmdLine[2] & @CRLF $iMsgBoxAnswer &= "will be set to " & $CmdLine[3] & @CRLF $iMsgBoxAnswer = MsgBox(4097, "This Msgbox will time out in 3 seconds", $iMsgBoxAnswer, 3) Select Case $iMsgBoxAnswer = 1 ;OK ;nothing Case $iMsgBoxAnswer = 2 ;Cancel Exit EndSelect ConsoleWrite("$CmdLine[0]=" & $CmdLine[0] & @CRLF) If $CmdLine[0] = 4 Then _GroupPolicy($CmdLine[1], $CmdLine[2], $CmdLine[3], $CmdLine[4]) ElseIf $CmdLine[0] = 3 Then _GroupPolicy($CmdLine[1], $CmdLine[2], $CmdLine[3]) Else $iMsgBoxAnswer = MsgBox(4096, "incorect number of parameters", $CmdLine[0]) EndIf Exit ; #FUNCTION# ;--------------------------------------------------------------------------- ; Name...........: _GroupPolicy() ; Description ...: Opens and uses the Group Policy Editor to configure the given settings ; Syntax.........: _GroupPolicy($sPolicyPath, $sPolicyItem, $iSetting [, $sOption = ""]) ; Parameters ....: $sPolicyPath - The path of nodes to navigate ; $sPolicyItem - The Item/option to navigate/edit ; $iSetting - 0=Disabled, 1=Enabled, 2=Configured, 3=find & exit ; $sOption - Options in form "ClassnameNN;SendKey" ;---------------------------------------------------------------------------------------- Func _GroupPolicy($sPolicyPath, $sPolicyItem, $iSetting, $sOption = "") If Not WinExists("Local Group Policy Editor") Then Run("c:\Windows\system32\mmc.exe " & "C:\share\open_close_gpedit\gpedit_v1.msc /a") EndIf ;Retrieves the 'Local Group Policy Editor' window handle Local $hGPO = WinWait("Local Group Policy Editor", '', 5) 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) ConsoleWrite("--- $iSetting=" & $iSetting & @CRLF) ConsoleWrite("--- $sOption=" & $sOption & @CRLF) Local $aPath = StringSplit($sPolicyPath, "\", 1) Local $tmpPath = "" ;Expant the path in $hTreeView_1 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 ControlSend($hGPO, "", "AMCCustomTab1", "{RIGHT}") Sleep(50) ;Retrieves the SysListView321 control handle Local $hListView = ControlGetHandle($hGPO, "", "SysListView321") ;find the item Local $FindItem = ControlListView($hGPO, "", $hListView, "FindItem", $sPolicyItem) Sleep(500) 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) ;snap Selected Item Local $SelectedItem = ControlListView($hGPO, "", $hListView, "GetSelected") ConsoleWrite("- $SelectedItem=" & $SelectedItem & @CRLF) Sleep(50) Local $ItemTxt[4] ;Returns the text of a given Item to ItemTxt[0]=col0, item[1]=col1, ... For $i = 0 To 3 $ItemTxt[$i] = ControlListView($hGPO, "", $hListView, "GetText", Int($SelectedItem), $i) ConsoleWrite("$ItemTxt[" & $i & "]=" & $ItemTxt[$i] & @CRLF) Next ;and send enter to open it ControlSend($hGPO, '', $hListView, '{ENTER}') ;--------------------------------------------------------------- Local $hGPOedit = WinWait("[CLASS:WindowsForms10.Window.8.app.0.297b065_r69_ad1]", "", 1) ConsoleWrite("- $hGPOedit=" & $hGPOedit & @CRLF) If WinExists($hGPOedit) Then ; normal <- ConsoleWrite("> $hGPOedit=normal <" & @CRLF) Switch $iSetting Case 0 ;Disabled ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "d") ConsoleWrite("-> Disabled" & @CRLF) Case 1 ;Enabled ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "e") ConsoleWrite("-> Enabled" & @CRLF) If StringLen($sOption) > 0 Then ConsoleWrite("- $sOption=" & $sOption & @CRLF) Local $aOpt = StringSplit($sOption, ";", 1) ControlSend($hGPOedit, "", $aOpt[1], $aOpt[2]) EndIf Case 2 ;Configured ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "c") ConsoleWrite("-> Configured" & @CRLF) Case 3 ;find & exit ConsoleWrite("-> find & exit" & @CRLF) Exit EndSwitch ;Apply ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "a") ;Enter ControlSend($hGPOedit, "", "WindowsForms10.Window.8.app.0.297b065_r69_ad16", "{ENTER}") Else ;special <- $hGPOedit = WinWait("[CLASS:#32770]", "", 1) ;Retrieve the window text of the active window. Local $sText = WinGetText($hGPOedit) ;ConsoleWrite($sText & @CRLF) If StringLeft($sText, 22) = "Local Security Setting" Then ; * <- if "Local Security Setting" ConsoleWrite("> $hGPOedit=special <" & @CRLF) Switch $iSetting Case 0 ;Disabled ControlSend($hGPOedit, "", "Button3", "s") ConsoleWrite("-> Disabled" & @CRLF) Case 1 ;Enabled ControlSend($hGPOedit, "", "Button2", "e") ConsoleWrite("-> Enabled" & @CRLF) Case 3 ;find & exit ConsoleWrite("-> find & exit" & @CRLF) Exit EndSwitch ControlSend($hGPOedit, "", "SysTabControl321", "{ENTER}") Sleep(50) If WinExists("Confirm Setting Change") Then ControlSend("Confirm Setting Change", "", "Button1", "y") ; yes EndIf EndIf EndIf ;--------------------------------------------------------------- ;snap Selected Item $SelectedItem = ControlListView($hGPO, "", $hListView, "GetSelected") ConsoleWrite("- $SelectedItem=" & $SelectedItem & @CRLF) Sleep(50) ;Returns the text of a given Item to ItemTxt[0]=col0, item[1]=col1, ... For $i = 0 To 3 $ItemTxt[$i] = ControlListView($hGPO, "", $hListView, "GetText", Int($SelectedItem), $i) ConsoleWrite("$ItemTxt[" & $i & "]=" & $ItemTxt[$i] & @CRLF) Next ;~ Exit ; <-- **************************************************** Sleep(50) ControlSend($hGPO, "", $hTreeView_1, "{ALT down}{F4}{ALT up}") $hGPO = WinWait("Microsoft Management Console", "", 1) ControlSend($hGPO, "", "Static2", "{N}") Return $sPolicyItem EndFunc ;==>_GroupPolicy ;---------------------------------------------------------------------------------------- edit: I deleted another one WinActivate() That's what I do but it is not change "Require pin for pairing" it change what is above it... and not close the GPO I put in the new code and still the same problem Link to comment Share on other sites More sharing options...
ioa747 Posted March 27, 2023 Share Posted March 27, 2023 main console out: $CmdLine[0]=4 $hGPO=0x000000000021065E --- $sPolicyPath=Local Computer Policy\Computer Configuration\Administrative Templates\Windows Components\Connect --- $sPolicyItem=Require pin for pairing --- $iSetting=1 --- $sOption=WindowsForms10.COMBOBOX.app.0.297b065_r69_ad11;f $tmpPath=Local Computer Policy $tmpPath=Local Computer Policy|Computer Configuration $tmpPath=Local Computer Policy|Computer Configuration|Administrative Templates $tmpPath=Local Computer Policy|Computer Configuration|Administrative Templates|Windows Components $tmpPath=Local Computer Policy|Computer Configuration|Administrative Templates|Windows Components|Connect - $FindItem=1 - $SelectedItem=1 $ItemTxt[0]=Require pin for pairing $ItemTxt[1]=Not configured $ItemTxt[2]=No $ItemTxt[3]= - $hGPOedit=0x00000000000E0D8E > $hGPOedit=normal < -> Enabled - $sOption=WindowsForms10.COMBOBOX.app.0.297b065_r69_ad11;f - $SelectedItem=1 $ItemTxt[0]=Require pin for pairing $ItemTxt[1]=Enabled $ItemTxt[2]=No $ItemTxt[3]= post yours I know that I know nothing 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