Jump to content

Recommended Posts

Posted

hi everybody, i'm codding a test script to run a default web browser in hidden mode then show it and this is my code :

 

Func _GetDefBrowser()
    Local Static $s_reg = RegRead("HKCRhttpshellopencommand", "")
    Return StringRegExpReplace($s_reg, "(.*?x22)(.*?[/])*(.*?)(x22.*?z)", "$3")
    EndFunc
Hidshow()
Func Hidshow()
    shellexecute(_GetDefBrowser(),'-new-window "www.autoitscript.fr"',"","",@SW_HIDE)
    ; Wait 1 seconds for the Target link window to appear.
    Local $hWnd = WinWait("[CLASS:MozillaWindowClass]", "", 10)
    Local $hWnd = WinWait("[CLASS:Chrome_WidgetWin_1]", "", 10)
        Local $hWnd = WinWait("[CLASS:IEFrame]", "", 10)
        ; Wait for 5 seconds
    Sleep(50000)
    ; Set the state of the Target link window to "show".
   WinSetState($hWnd, "", @SW_SHOW)
    ; Wait for 2 seconds.
    Sleep(2000)
    ; Close the Target link window using the handle returned by WinWait.
    WinClose($hWnd)
EndFunc   ;==>end

 

this code works with Firefox but it fails with chrome it didn't hide the GUI any idea

thank you in advance for youur help

Posted

i think there is a bug in Autoit even this code doesn't run google chrome in hidden

 

 ShellExecute("C:UsersMypcAppDataLocalGoogleChromeApplicationchrome.exe " , " http:/www.google.fr",  "", "", @SW_HIDE)
 

 

43 views with no answers

Posted (edited)

If someone want to just to read is a problem for you? It's not a bug of autoit, chrome spawn more then one process.

This work for me:

_Start_Minimized_Chrome()
Sleep(2000)
_Maximize_Chrome()

Func _Start_Minimized_Chrome()
    Run(@ScriptDir & "\chrome.exe")
    WinWait("[CLASS:Chrome_WidgetWin_1]", "")
    Local $WinList = WinList()
    For $i = 1 To $WinList[0][0]
        If $WinList[$i][0] <> "" And StringInStr($WinList[$i][0], " - Google Chrome", 1) Then WinSetState($WinList[$i][1], "", @SW_MINIMIZE)
    Next
EndFunc   ;==>_Start_Minimized_Chrome

Func _Maximize_Chrome()
    WinSetState("[CLASS:Chrome_WidgetWin_1]", "", @SW_MAXIMIZE)
EndFunc   ;==>_Maximize_Chrome

Replace minimize and maximize with what you need

EDIT: Don't "bump" your post multiple time in a day or Melba will be angry ;)

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Posted (edited)

 

Terenz

 

If someone want to just to read is a problem for you? It's not a bug of autoit, chrome spawn more then one process.

This work for me:

 

thank you for your answer ,but it doesn't work for me this is my code:

 

#include<_GetDefBrowser.au3>

_Start_Minimized_Chrome()

Sleep(2000)

Func _Start_Minimized_Chrome()

    shellexecute(_GetDefBrowser(),' "www.autoitscript.fr"',"","",@SW_HIDE)

    WinWait("[CLASS:Chrome_WidgetWin_1]", "")

    Local $WinList = WinList()

    For $i = 1 To $WinList[0][0]

        If $WinList[$i][0] <> "" And StringInStr($WinList[$i][0], " - Google Chrome", 1) Then WinSetState($WinList[$i][1], "", @SW_HIDE)

    Next

EndFunc   ;==>_Start_Minimized_Chrome

 

i did Replace minimize and maximize with what you need ( @SW_HIDE) and it didn't work and chrome still run normal

Edited by camilla
Posted (edited)

Is strange. Try with this "debug" code:

_Start_Minimized_Chrome()

Func _Start_Minimized_Chrome()
    ShellExecute(@ScriptDir & "\chrome.exe", ' "www.autoitscript.fr"')
    WinWait("[CLASS:Chrome_WidgetWin_1]", "")
    Local $WinList = WinList()
    For $i = 1 To $WinList[0][0]
        If $WinList[$i][0] <> "" And IsVisible($WinList[$i][0]) Then
            ConsoleWrite("Title=" & $WinList[$i][0] & @LF & "Handle=" & $WinList[$i][1] & @CRLF)
            $case = MsgBox(4+262144, "Details", "Do you want to hide this window? " & @CRLF & "Title=" & $WinList[$i][0] & @LF & "Handle=" & $WinList[$i][1])
            Switch $case
                Case 6 ; Yes
                    WinSetState($WinList[$i][1], "", @SW_HIDE)
                    ExitLoop
                Case 7 ;No
                    ContinueLoop
            EndSwitch
        EndIf
    Next
EndFunc   ;==>_Start_Minimized_Chrome

Func IsVisible($handle)
    If BitAND(WinGetState($handle), 2) Then Return 1
    Return 0
EndFunc   ;==>IsVisible

If i click Yes for this window:

Title=No Title - Google Chrome
Handle=0x001D031A

It will be correcty hidden, for this reason i have used StringInStr with " - Google Chrome", the handle is always different

Check what name work for you

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Posted (edited)

I don't know about hiding the window, but if you want to visit a site with default browser then, it's as simple as...

ShellExecute("http://domain.ext")

The way you appear to be trying it, you might have better luck starting hidden with Run() function.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Posted

camilla lol do you think i don't have try it before post? Both work on my system and sure i have chrome installed.

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Posted

lol, i'm using win7 x86 and they are not work  chrome run in normal mode

using your first script or second one even if i clicked on yes on your second code chrome still run normal and it is not hide

Posted (edited)

Maybe you can use this brute trick to get the title of the future window before launching the browser

#include <WinAPIShellEx.au3>

;Opt("WinTitleMatchMode", 2)
;HttpSetUserAgent("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)")
$txt = BinaryToString(InetRead("http://www.google.fr", 4))
;$txt = BinaryToString(InetRead("http://www.autoitscript.fr", 4))
$title = StringRegExpReplace($txt, '(?s).+<title>([\w\h]+).+', "$1")

_WinAPI_ShellExecute(_GetDefBrowser(), " http://www.google.fr", "", "", @SW_HIDE)
;_WinAPI_ShellExecute(_GetDefBrowser(), " http://www.autoitscript.fr", "", "", @SW_HIDE)

$hWnd = WinWait($title)
msgbox(0,"", "the window " & $title & " is hidden")
Sleep(2000)
msgbox(0,"", "and now show it" )
WinSetState($hWnd, "", @SW_SHOW)

Func _GetDefBrowser()
    Local Static $s_reg = RegRead("HKCR\http\shell\open\command", "")
    Return StringRegExpReplace($s_reg, "(.*?\x22)(.*?[\\/])*(.*?)(\x22.*?\z)", "$3")
EndFunc

BTW here ShellExecute doesn't work with @SW_HIDE but _WinAPI_ShellExecute does :)

Edited by mikell
Posted

 

mikell

thank you for your help,but i'm unlucky it oesn't work for me too

 

Yeah, that was my solution to this problem. if the default browser is chrome than try to run firefox if it is not installed try to run in explorer IE

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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