Block launching of browser

Ask gaming related questions (AHK v1.1 and older)
Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Block launching of browser

20 Sep 2021, 14:28

I have done some research and there are questions about various browser functions, but unabe to find one about blocking its launch. In many Hidden Object Games menu, there are images and text that collapse game and launch surveys, advertisements and review websites.

I would like AHK to disable the launching of browser, so as to avoid these issues. I am going to take another look Docs,as I might have missed something.

Tried “Process, Close, chrome.exe” but fails :|

Thanks, :morebeard:
Last edited by Evil-e on 20 Sep 2021, 18:49, edited 3 times in total.
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)
User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: Block launching of browser

20 Sep 2021, 17:35

Code: Select all

Loop {
 Process, Wait, chrome.exe
 Process, Close, chrome.exe
}
Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Re: Block launching of browser

20 Sep 2021, 18:33

I don,t know how to remove “solved” hit by mistake :(
Thanks, Mikey :D

It works fine, but only as the first line of script. However, since it loops, the remaining script fails and the exitapp never functions to close AHK :(

I added return to tne end, but no go. Any thoughts?

:morebeard:
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)
User avatar
boiler
Posts: 16706
Joined: 21 Dec 2014, 02:44

Re: Block launching of browser OOPS… NOT SOLVED

20 Sep 2021, 18:40

It is supposed to loop so that it continues to close browser windows as they open. If it were to immediately exit, that defeats the purpose of the script. What makes you think "the remaining script fails"?
Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Re: Block launching of browser

20 Sep 2021, 19:11

:headwall: God I HATE touch screens :headwall:

Code: Select all

                                           sleep, 1000
                                                    send {LButton down}
                                                    sleep, 50
                                                    send {LButton up}
                                                    sleep, 500
                                                    send {LButton down}
                                                    sleep, 50
                                                    send {LButton up}
                                                    sleep, 500
                                                    send {LButton down}
                                                    sleep, 50
                                                    send {LButton up}
                                                    sleep, 5500
                                                    send {LButton down}
                                                    sleep, 50
                                                    send {LButton up}
                                                    sleep, 1500
                                                    send {LButton down}
                                                    sleep, 50
                                                    send {LButton up}
                                                    loop {
                                                    Process, wait, chrome.exe
                                                    Process, close, chrome.exe
                                                    }
                                                    return
#IfWinActive ahk_exe DarkDimensions2_WaxBeauty_CE.exe
WinWait, ahk_exe DarkDimensions2_WaxBeauty_CE.exe
WinWaitClose, ahk_exe DarkDimensions2_WaxBeauty_CE.exe
sleep, 500
run, "D:\Games\Puzzles\Dark Dimensions\Wax Beauty Collector's Edition\Launch Dark Dimensions Wax Beauty Collector's Edition delete cache items.bat"
sleep, 100
Run, "D:\Games\Puzzles\Dark Dimensions\Wax Beauty Collector's Edition\Launch Dark Dimensions Wax Beauty Collector's Edition save folder 1.bat"
sleep, 250
Run, "D:\Games\Puzzles\Dark Dimensions\Wax Beauty Collector's Edition\Launch Dark Dimensions Wax Beauty Collector's Edition save folder 2.bat"
sleep, 250
Process, Close, CMD.exe
sleep, 50
ExitApp
return
$F12::ExitApp
return
This is my script for game. AHK navigates into main menu and works fine with the browser block code. However, when I exit the game, the closing script stopped working so batch files dont launch and AHK continues to run in sys tray :(

:morebeard:

PS> I cannot get the code to hug the LH side on the upper section, so looks wonky
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)
User avatar
boiler
Posts: 16706
Joined: 21 Dec 2014, 02:44

Re: Block launching of browser

20 Sep 2021, 19:29

It would have been important to note that you wanted the web browser window closing to work in the context of an existing script. You can't have it continuously loop and also run what's below it. Either run mikeyww's code as a separate script or implement that functionality in some different way.
User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: Block launching of browser

20 Sep 2021, 19:36

Your script has multiple bugs. Unlabeled code after Return is unreachable and will not execute. You have a faulty use of #IfWinActive, which is used only for hotkeys & hotstrings; see the link.

To wait for two different windows to appear, there are at least four different ways (possibly more).

1. Use a shell hook.
2. Use GroupAdd to define a window group, and act upon the group.
3. Use a SetTimer to check one or more conditions.
4. Use a separate script (boiler's mention).
Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Re: Block launching of browser

20 Sep 2021, 20:01

Thanks Mikey & boiler :)

As Mikey and I have talked prior, I am just not good with rhe AHK code lingo at all. The script works perfect, except when I added Mikeys initial reply, then added the return as experiment when script began to fail. The #WinActive is a hold over from the very first script I copied some 5 years ago and exists on literally over 1300 other games I have that all use AHK. I realize it is not necessary on THIS script, but when I removed it from some other games, I had issues. It does not hurt games that don’t require it, but those that do stop working, so I just leave it in all my scripts :)

Sorry, but I am looking at all 4 of your options and they may as well be in a different language :(

I will research the options given, but make no promisses I wont be back again :oops:

Thanks, :morebeard:
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)
User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: Block launching of browser

20 Sep 2021, 20:15

You can run a separate script without having to adjust anything from your originally working script. A shell-hook demo is below.

Code: Select all

Global close := "chrome"
Gui, +LastFound
DllCall("RegisterShellHookWindow", "UInt", WinExist())
OnMessage(DllCall("RegisterWindowMessage", "Str", "SHELLHOOK"), "ShellMessage")
Send {LButton down}
Sleep, 50
Send {LButton up}
WinWait, ahk_exe notepad.exe
WinWaitClose
MsgBox, Done!
ExitApp

ShellMessage(wParam, lParam) {
 If (wParam != 1)
  Return
 WinGet, pname, ProcessName, % wTitle := "ahk_id " lParam
 SplitPath, pname,,,, fnBare
 If fnBare in %close%
  WinClose, %wTitle%
}
Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Re: Block launching of browser

21 Sep 2021, 02:49

Thanks Mikey, but I don’t understand computer code. I have a HS education that ended in 1983 and AHK docs and your script require a base knowledge of code to understand how and where to incorporate it into my existing script.

When I work with thongs like this, that are beyond my base knowledge, reverse engineering is usually the best way for me to grasp how something works. I get that as one who is offering assistance, it is more than frustrating when someone comes into the forums with… “can someone write a script for me?”. I do my best to avoid such a question, as I have never done so, in so may words, but I can in nearly all cases get a little push, and I wobble away for a second, then gain my balance, just as the child who gets training wheels removed for the first time :)

This script sends the LButton and includes a message box to apparently notify me via Notepad that Chrome was blocked. While that is fine, I don’t understand why it is included and only ends up adding to my difficulty to understand. I have now incorporated your script into my own in multiple different locations and get an AHK error message that has ‘this program will exit” at the bottom for each one.

I am doing my best to not be “that guy”, but looking at your code in the context of which it is presented, is like reading a foreign language. Mikey, you have offered me help in the past and you know me not only to te greatful for help, but WANT to do as much connecting of the dots as I can, for not only a matter of personal pride, but because I don’t want to be “that guy”.

I appreciate yours and boilers assistance, but your script is just too cryptic for me to get my head around :(
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)
User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: Block launching of browser

21 Sep 2021, 05:06

The separate script is always a backup option! I was just showing a demo in case useful. I have inserted the routines in your script below. I just separated it into two routine blocks, separated by your WinWait. I consolidated your click routine, too, but feel free to use the other method if you prefer it.

Code: Select all

Global close := "chrome"
dir := "D:\Games\Puzzles\Dark Dimensions\Wax Beauty Collector's Edition"
              . "\Launch Dark Dimensions Wax Beauty Collector's Edition"
Gui, +LastFound
DllCall("RegisterShellHookWindow", "UInt", WinExist())
OnMessage(DllCall("RegisterWindowMessage", "Str", "SHELLHOOK"), "close")
Gosub, Routine1
WinWait, ahk_exe DarkDimensions2_WaxBeauty_CE.exe
WinWaitClose
Gosub, Routine2
SoundBeep, 1000
ExitApp

#IfWinActive ahk_exe DarkDimensions2_WaxBeauty_CE.exe
F12::ExitApp
#IfWinActive

Routine1:
SetMouseDelay, 50
Sleep, 1000
For each, wait in [500, 500, 5500, 1500, 0] {
 Click
 Sleep, wait
}
Return

Routine2:
Sleep, 500
Run, %dir% delete cache items.bat
Sleep, 100
Run, %dir% save folder 1.bat
Sleep, 250
Run, %dir% save folder 2.bat
Sleep, 250
Process, Close, CMD.exe
Return

close(wParam, lParam) {
 If (wParam != WINDOWCREATED := 1)
  Return
 WinGet, pname, ProcessName, % wTitle := "ahk_id " lParam
 SplitPath, pname,,,, fnBare
 If fnBare in %close%
  WinClose, %wTitle%
}
Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Re: Block launching of browser

21 Sep 2021, 14:51

I have tried about 10 variations of how to incorporate the above into my script. It has these "Routine" & "Gosub" lines that create errors when the AHK.exe file is launched. It seems that there is two possible portions of this script that can be used (maybe not?) and cannot use both. However, it is not intuitively clear where to make such a distinction nor in what part of the script to place it whatever part I decide is the correct one. On multiple occasions, my iterations did NOT cause errors and game launched and exited as normal. But, if LINKS were used, the browser was still launched, so I am very obviously not doing this correctly. This is an exceedingly insignificant issue and we both have spent much more time than it is worth. Not understanding many of the AHK linguistics, makes this entire endeavor a futile exercise for all and is VERY CLEARLY on me!

Looking at the above is akin to ripping a page from the center of a novel and trying to decipher how the book began and will end. I thank you for your assistance in trying to help me, but I am clearly guilty of a lack of computer science skills, so I have no further wish to pursue this issue.

I fully realize you are trying to help, but I only have one other ask. While I don't want to be "that guy" please do a more thorough job of reading the room and try to meet me 1/2 way.

Thanks, Mikey :morebeard:
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)
User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: Block launching of browser

21 Sep 2021, 14:57

OK. I did what I could, which was to use your exact script that you posted, and incorporate the code that meets your need, "I would like AHK to disable the launching of browser". My script accomplishes both. If you actually have a different script rather than the one that you posted, then there is nothing more that I can do with the thread here! In any case, good luck, and perhaps you can apply some of the methods here. If it looks too complicated, OK, you can use the simple four-line script posted in a separate script, and it will get the job done.

Regarding, "It seems that there is two possible portions of this script that can be used (maybe not?) and cannot use both", the script that I posted works in its entirety.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: pacislavek and 44 guests