JustinM Posted October 27, 2016 Posted October 27, 2016 Hello all, I am having a hard time getting chrome to work with my autoit script. Basically I need to open chrome and set the homepage. I am using the following code below to get it done. If FileExists("C:\Program Files (x86)\Google\Chrome\Application\Chrome.exe") Then _RunDos("Start chrome.exe --new-window 127.0.0.1") Sleep(2500) WinWait("http://127.0.0.1/ is not available - Google Chrome") Send("!{e}") Sleep(500) Send("{UP}") Sleep(500) Send("{UP}") Sleep(500) Send("{UP}") Sleep(500) Send("{ENTER}") Sleep(500) Send("{TAB 4}") Sleep(500) Send("{ENTER}") Sleep(500) Send("{TAB}") Sleep(500) Send("www.websitehere.com") Sleep(500) Send("{ENTER}") Sleep(500) Send("{TAB 2}") Sleep(500) Send("{ENTER}") Sleep(500) Send ("!{F4}") Sleep(1000) EndIf It works about 90% of the time, and the other 10% the script randomly freezes -- my assumption is it's getting held up on the "WinWait("http://127.0.0.1/ is not available - Google Chrome")" . The reason I open it up with 127.0.0.1 is because I want to control what window will open so I know what to wait for. Reason for posting this topic -- Is there better way of setting the homepage in chrome? Or how can I open chrome straight into the settings page?
AdamUL Posted October 27, 2016 Posted October 27, 2016 If the PC your trying to set the homepage on is in a domain, you can use Chrome policy settings. You can set them with an ADM/ADMX template with Group Policy, or use registry settings. For more info, read here. If you want to use the registry, try this function. The PC has to be a member of a domain for Chrome to honor these settings. Func _SetHomepageGoogleChrome($sHomepage) Local $s64Bit = "" Local $sWow6432Node = "" Local $sChromePathX86 = EnvGet("PROGRAMFILES(X86)") & "\Google\Chrome\Application\chrome.exe" If @OSArch = "X64" Then $s64Bit = "64" If FileExists($sChromePathX86) Then $sWow6432Node = "Wow6432Node\" EndIf Local Const $sRegKeyGoogleChrome = "HKEY_LOCAL_MACHINE" & $s64Bit & "\SOFTWARE\" & $sWow6432Node & "Policies\Google\Chrome" RegWrite($sRegKeyGoogleChrome, "HomepageLocation", "REG_SZ", $sHomepage) If @error Then Return SetError(1, @error, False) RegWrite($sRegKeyGoogleChrome & "\RestoreOnStartupURLs", "1", "REG_SZ", $sHomepage) If @error Then Return SetError(2, @error, False) Return True EndFunc ;==>_SetHomepageGoogleChrome Adam
JustinM Posted October 27, 2016 Author Posted October 27, 2016 Adam, this script will not be used for computers in domains.
AdamUL Posted October 27, 2016 Posted October 27, 2016 Then you will need to use the master_preferences file. Have a look at Default user preferences. Adam
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