tablejumper Posted January 10, 2018 Posted January 10, 2018 For months I've been trying to run a script on user login that defaults Adobe Reader 11 as the default viewer for pdf files. The problem is that every time you reboot or login to an account, Windows 10 forces Edge Browser as the default pdf viewer. There is absolutely no fix for this atm. I've tried Group Policy's File Association XML, .bat, .cmd, .vbs, powershell scripts involving reg edits and file type associations using ftype, but no avail. Windows 10 is a mess. The only real way to switch the default pdf viewer during a login session is via the control panel. And so I turn to AutoIt to automate this on every client machine (more than 100) upon their account login to solve this. I'm halfway through the solution with: #include <MsgBoxConstants.au3> #include <GUIListView.au3> Opt("WinTitleMatchMode", 4) run("explorer.exe shell:::{17cd9488-1228-4b2f-88ce-4298e93e0966} -Microsoft.DefaultPrograms\pageDefaultProgram") sleep(4000) $hWnd = ControlGetHandle("Set Default Programs","","SysListView321") ;need a case, if, or loop to go through the first 10 indexes ;and select the index number matching selection text of "Adobe Reader XI" ;example, select 3rd item in the list (index starts with 0) _GUICtrlListView_SetItemSelected($hWnd, 2) ;only the index number matching the required selection text should be selected sleep(1000) ;lines below not working... need to select button "Set this program as default" $hWnd = ControlGetHandle("Set Default Programs","[CLASS:Button; INSTANCE:1]") ControlClick("Button", "&Set this program as default") The script opens up the "Set Default Programs" windows in Control Panel, then handles the selection item box on the left. I'm able to select items based on their index number, however this is not good to use directly it will be different between each computer. Some computers have Adobe Reader 11 as the third, others as the first. Does anyone know what scripting is required to select an item based upon the text it contains? Maybe via a loop, if statement, or case statement which filters the first 10 index numbers and passes a true value or sets the index value to select for the item containing the desired text. That way the correct item is selected. Lastly, I wasn't able to hit the button "Set this program as default". I'm still very new... Thank you so much.
Earthshine Posted January 10, 2018 Posted January 10, 2018 (edited) in Windows 10 there is a way to set your default applications. you will probably have to rely on Send function to send keystrokes. what version of AutoIt are you using? fixed. i don't know how you tested this but it plain did not compile so I wonder. #include <MsgBoxConstants.au3> #include <GUIListView.au3> Opt("WinTitleMatchMode", 4) run("explorer.exe shell:::{17cd9488-1228-4b2f-88ce-4298e93e0966} -Microsoft.DefaultPrograms\pageDefaultProgram") sleep(4000) $hWnd = ControlGetHandle("Set Default Programs","","SysListView321") ;need a case, if, or loop to go through the first 10 indexes ;and select the index number matching selection text of "Adobe Reader XI" ;example, select 3rd item in the list (index starts with 0) _GUICtrlListView_SetItemSelected($hWnd, 2) ;only the index number matching the required selection text should be selected sleep(1000) ;lines below not working... need to select button "Set this program as default" $hWnd = ControlGetHandle("Set Default Programs","", "[CLASS:Button; INSTANCE:1]") ControlClick($hWnd,"", "[CLASS:Button; INSTANCE:1]") Edited January 10, 2018 by Earthshine My resources are limited. You must ask the right questions
Earthshine Posted January 10, 2018 Posted January 10, 2018 (edited) you need to use your Au3Info tool and talk to this object [CLASS:SysListView32; INSTANCE:1] Edited January 10, 2018 by Earthshine My resources are limited. You must ask the right questions
Earthshine Posted January 10, 2018 Posted January 10, 2018 (edited) snip. see below. still don't know how to get text based entries Edited January 10, 2018 by Earthshine My resources are limited. You must ask the right questions
Earthshine Posted January 10, 2018 Posted January 10, 2018 (edited) nip Edited January 10, 2018 by Earthshine My resources are limited. You must ask the right questions
Earthshine Posted January 10, 2018 Posted January 10, 2018 (edited) I got it working. i use my WaitForControls function #include <MsgBoxConstants.au3> #include <GUIListView.au3> #include "WaitForControls.au3" #include "log4a.au3" ; Enable logging and don't write to stderr _log4a_SetEnable() ; Write to stderr, set min level to warn, customize message format _log4a_SetErrorStream() _log4a_SetMinLevel($LOG4A_LEVEL_INFO) If @Compiled Then _log4a_SetMinLevel($LOG4A_LEVEL_WARN) ; Change the min level if the script is compiled _log4a_SetFormat("${shortdate} | ${host} | ${level} | ${message}") ;~ Opt("WinTitleMatchMode", 4) Run("explorer.exe shell:::{17cd9488-1228-4b2f-88ce-4298e93e0966} -Microsoft.DefaultPrograms\pageDefaultProgram") Sleep(8000) $hWnd = ControlGetHandle("Set Default Programs", "", "SysListView321") ;need a case, if, or loop to go through the first 10 indexes ;and select the index number matching selection text of "Adobe Reader XI" ;example, select 3rd item in the list (index starts with 0) _GUICtrlListView_SetItemSelected($hWnd, 2) ;only the index number matching the required selection text should be selected Sleep(4000) ;lines below not working... need to select button "Set this program as default" $hWnd = ControlGetHandle("Set Default Programs","&Set this program as default", "[CLASS:Button; INSTANCE:1]") ;~ ControlClick($hWnd,"&Set this program as default", "[CLASS:Button; INSTANCE:1]") _checkClickCtrl($hWnd, "Set Default Programs", "[CLASS:Button; INSTANCE:1]", "&Set this program as default") 01\10\2018 | PETER | Info | _checkClickCtrl():Begin 01\10\2018 | PETER | Info | Searching for Formclass: 0x00000000000D07AE 01\10\2018 | PETER | Info | Searching for Text: Set Default Programs 01\10\2018 | PETER | Info | Searching for Control: [CLASS:Button; INSTANCE:1] 01\10\2018 | PETER | Info | Searching for Ctrl Txt: &Set this program as default 01\10\2018 | PETER | Info | Timeout: 0 01\10\2018 | PETER | Info | Time Delay (after click): 0 01\10\2018 | PETER | Info | Control Text Search: &Set this program as default 01\10\2018 | PETER | Info | Control Text Found: &Set this program as default 01\10\2018 | PETER | Info | Found Formclass: 0x00000000000D07AE 01\10\2018 | PETER | Info | Found Text: Set Default Programs 01\10\2018 | PETER | Info | Found Control: [CLASS:Button; INSTANCE:1] 01\10\2018 | PETER | Info | Found Ctrl Txt: &Set this program as default 01\10\2018 | PETER | Info | Timeout: 0 01\10\2018 | PETER | Info | Time Delay (after click): 0 01\10\2018 | PETER | Info | Control [:[CLASS:Button; INSTANCE:1]] Clicked 01\10\2018 | PETER | Info | ExitLoop:Normal - [CLASS:Button; INSTANCE:1] 01\10\2018 | PETER | Info | _checkClickCtrl():End WaitForControls.au3 log4a.au3 Edited January 10, 2018 by Earthshine My resources are limited. You must ask the right questions
tablejumper Posted January 10, 2018 Author Posted January 10, 2018 I'm using SciTE-Lite With just the code I pasted above, I can run it using F5 and the "Set Default Programs" windows pops up, then the 3rd item on the list on the lefthand side is selected. However, I want the specific list item "Adobe Reader XI" to be selected, and not just "Item number 3" listed as Index 2. After that, I just need to script the button press to "Set this program as default" @Earthshine
Earthshine Posted January 10, 2018 Posted January 10, 2018 (edited) i got the button press working. my function waits for it forever unless you specify otherwise. i posted the logs so you could see it find it and press it. you can figure out how the rest works I am sure... HINT https://www.autoitscript.com/autoit3/docs/functions/ControlListView.htm Edited January 10, 2018 by Earthshine My resources are limited. You must ask the right questions
tablejumper Posted January 10, 2018 Author Posted January 10, 2018 Thanks for the help here, but I can't see in the code where each item in SysListView32 is parsed for the title "Adobe Reader XI" which then should find the required index number to be selected. I can't simply select an item via index number as Adobe Reader XI item is not always index number 2 between multiple computers. So first, the name must be searched via a loop or if or case statement, then index number extrapolated and then plugged into for selection. Then lastly the button pressed. @Earthshine
tablejumper Posted January 10, 2018 Author Posted January 10, 2018 Each item does not need to be parsed however as since the list is alphabetical by default, Adobe Reader XI will show within the first 10 entries, or indexes 0-9. So the loop would have to go through each index number searching for "Adobe Reader XI. I just don't know the function for parsing the text =/
Earthshine Posted January 10, 2018 Posted January 10, 2018 (edited) wrong track Edited January 11, 2018 by Earthshine My resources are limited. You must ask the right questions
Earthshine Posted January 11, 2018 Posted January 11, 2018 (edited) snip, wrong stuff, see below Edited January 11, 2018 by Earthshine My resources are limited. You must ask the right questions
Earthshine Posted January 11, 2018 Posted January 11, 2018 (edited) https://www.autoitscript.com/wiki/FAQ#How_can_I_control_.28click.2C_edit_etc.29_an_external_.28html.29_application.3F specifically Edited January 11, 2018 by Earthshine My resources are limited. You must ask the right questions
Earthshine Posted January 11, 2018 Posted January 11, 2018 (edited) OK, using junkew's IUIAutomation I came up with this, and it WORKS!!!! I knew it. Win10 requires this. I used SimpleSpy.au3 that he wrote to get ALL of the code except the very first line I got from the OP! In this example, I click on the Camera app Run("explorer.exe shell:::{17cd9488-1228-4b2f-88ce-4298e93e0966} -Microsoft.DefaultPrograms\pageDefaultProgram") #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) _UIA_setVar("oP1","Title:=Set Default Programs;controltype:=UIA_WindowControlTypeId;class:=CabinetWClass") ;Set Default Programs _UIA_setVar("oP2","Title:=Set Default Programs;controltype:=UIA_PaneControlTypeId;class:=ShellTabWindowClass") ;Set Default Programs _UIA_setVar("oP3","Title:=;controltype:=UIA_PaneControlTypeId;class:=DUIViewWndClassName") ; _UIA_setVar("oP4","Title:=Explorer Pane;controltype:=UIA_PaneControlTypeId;class:=HWNDView") ;Explorer Pane _UIA_setVar("oP5","Title:=Folder Layout Pane;controltype:=UIA_PaneControlTypeId;class:=Element") ;Folder Layout Pane _UIA_setVar("oP6","Title:=;controltype:=UIA_PaneControlTypeId;class:=XElement") ; _UIA_setVar("oP7","Title:=;controltype:=UIA_PaneControlTypeId;class:=XBaby") ; _UIA_setVar("oP8","Title:=Set your default programs;controltype:=UIA_PaneControlTypeId;class:=ProgramsPage") ;Set your default programs _UIA_setVar("oP9","Title:=Set your default programs;controltype:=UIA_PaneControlTypeId;class:=Element") ;Set your default programs _UIA_setVar("oP10","Title:=Programs List;controltype:=UIA_ListControlTypeId;class:=CCListViewEx") ;Programs List _UIA_setVar("oP11","Title:=Camera;controltype:=UIA_ListItemControlTypeId;class:=") ;Camera Local $oUIElement=_UIA_getObjectByFindAll("Camera.mainwindow", "title:=Camera;ControlType:=UIA_TextControlTypeId", $treescope_subtree) ;~ _UIA_setVar("oUIElement","Title:=Camera;controltype:=UIA_ListControlTypeId;class:=CCListViewEx") ;ControlType:=UIA_TextControlTypeId;classname:=") ;~ Actions split away from logical/technical definition above can come from configfiles _UIA_Action("oP11","highlight") _UIA_Action("oP11","click") we can continue now when you are ready. Please test. It works on all my vms and hosts, but it takes a few seconds to click that element. Edited January 11, 2018 by Earthshine My resources are limited. You must ask the right questions
Earthshine Posted January 11, 2018 Posted January 11, 2018 get his UDF https://www.autoitscript.com/forum/applications/core/interface/file/attachment.php?id=55307 get the samples that go along with https://www.autoitscript.com/forum/applications/core/interface/file/attachment.php?id=55308 use SimpleSpy.au3, click on what you want and press Ctrl=W, then go copy the code it captures! My resources are limited. You must ask the right questions
Earthshine Posted January 11, 2018 Posted January 11, 2018 ok, got it to work and press the button using a Send Run("explorer.exe shell:::{17cd9488-1228-4b2f-88ce-4298e93e0966} -Microsoft.DefaultPrograms\pageDefaultProgram") #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) _UIA_setVar("oP1","Title:=Set Default Programs;controltype:=UIA_WindowControlTypeId;class:=CabinetWClass") ;Set Default Programs _UIA_setVar("oP2","Title:=Set Default Programs;controltype:=UIA_PaneControlTypeId;class:=ShellTabWindowClass") ;Set Default Programs _UIA_setVar("oP3","Title:=;controltype:=UIA_PaneControlTypeId;class:=DUIViewWndClassName") ; _UIA_setVar("oP4","Title:=Explorer Pane;controltype:=UIA_PaneControlTypeId;class:=HWNDView") ;Explorer Pane _UIA_setVar("oP5","Title:=Folder Layout Pane;controltype:=UIA_PaneControlTypeId;class:=Element") ;Folder Layout Pane _UIA_setVar("oP6","Title:=;controltype:=UIA_PaneControlTypeId;class:=XElement") ; _UIA_setVar("oP7","Title:=;controltype:=UIA_PaneControlTypeId;class:=XBaby") ; _UIA_setVar("oP8","Title:=Set your default programs;controltype:=UIA_PaneControlTypeId;class:=ProgramsPage") ;Set your default programs _UIA_setVar("oP9","Title:=Set your default programs;controltype:=UIA_PaneControlTypeId;class:=Element") ;Set your default programs _UIA_setVar("oP10","Title:=Programs List;controltype:=UIA_ListControlTypeId;class:=CCListViewEx") ;Programs List _UIA_setVar("oP11","Title:=Camera;controltype:=UIA_ListItemControlTypeId;class:=") ;Camera ;~ Local $oUIElement=_UIA_getObjectByFindAll("Camera.mainwindow", "title:=Camera;ControlType:=UIA_TextControlTypeId", $treescope_subtree) ;~ _UIA_setVar("oUIElement","Title:=Camera;controltype:=UIA_ListControlTypeId;class:=CCListViewEx") ;ControlType:=UIA_TextControlTypeId;classname:=") ;~ Actions split away from logical/technical definition above can come from configfiles ;~ _UIA_Action("oP11","highlight") _UIA_Action("oP11","click") Sleep(2000) Send ("{TAB}") Send ("{TAB}") ;~ Send ("{TAB}") Send ("{ENTER}") You will just need to add Adobe whatever search text you are interested in. My resources are limited. You must ask the right questions
Earthshine Posted January 12, 2018 Posted January 12, 2018 I did this as an Coded UI Test in Visual Studio as well. Both solutions work fine. you can see how I would do it in Coded UI. The AutoIT code I posted above works for Win7 on up CodedUITestProject1.zip My resources are limited. You must ask the right questions
benched42 Posted January 12, 2018 Posted January 12, 2018 Why not just use AutoIt to write to the proper keys in the Windows registry hive HKEY_CLASSES_ROOT ? It should be pretty simple to write to the appropriate keys and force it to go to Adobe Reader. Who lied and told you life would EVER be fair?
Earthshine Posted January 12, 2018 Posted January 12, 2018 (edited) it's way more fun to watch things happen in an animated fashion... lol, yes, more than one way for anything. this is the refined code, though not using a treewalker, that would be even faster and better no doubt but I need to learn how myself first #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) Run("explorer.exe shell:::{17cd9488-1228-4b2f-88ce-4298e93e0966} -Microsoft.DefaultPrograms\pageDefaultProgram") ;~ $oUIElement=_UIA_getObjectByFindAll("Camera.mainwindow", "title:=Camera;ControlType:=UIA_TextControlTypeId", $treescope_subtree) _UIA_setVar("oUIElement","Title:=Camera;controltype:=UIA_TextControlTypeId;class:=") ;ControlType:=UIA_TextControlTypeId;classname:=") ;~ Actions split away from logical/technical definition above can come from configfiles ;~ _UIA_action("oUIElement","highlight") _UIA_action("oUIElement","click") Sleep(2000) Send ("{TAB}") Send ("{TAB}") ;~ Send ("{TAB}") Send ("{ENTER}") Edited January 15, 2018 by Earthshine My resources are limited. You must ask the right questions
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