Kill FireFox

cage
Posts: 18
Joined: Monday 02nd September 2019 5:47am
Location: Phoenix Arizona

Kill FireFox

Post by cage » Saturday 14th September 2019 8:41pm

For some reason after the latest update to FireFox it seems that the browser does not close every time. Thanks to cogier's caps lock example I figured out how to check to see if FireFox is running or not, and to kill it if it is. The program is very simple, if FF is running the program will tell you it is, then the kill button will be enabled. Then just click the Kill FireFox button and the program is shut down completely.
Public Sub Form_Open()

CheckFox

End

Public Sub BuExit_Click()

  Me.Close
  
End

Public Sub BuKillFox_Click()

  Shell "pkill 'firefox'"
  Wait 0.5
  BuKillFox.Enabled = False
  CheckFox
End

Public Sub CheckFox()
  
  Dim sState As String
  sState = Null

Shell "pgrep -x 'firefox'" To sState 
Wait 0.5
If sState = Null Then 
  Label1.text = "FireFox Not Running" 
Else 
  Label1.Text = "FireFox Is Running"
  BuKillFox.Enabled = True
Endif
  
End
You will nee to create a Label and two buttons. I used BuExit, BuKillFox names for
the buttons and Label1 for the text box. Feel free to modify the program to your tastes.

User avatar
Technopeasant
Posts: 15
Joined: Saturday 13th July 2019 6:50pm

Re: Kill FireFox

Post by Technopeasant » Sunday 15th September 2019 12:44am

I mean, sure, you could just use the task manager to do this... but why not do it in Gambas? :lol:
Technical director,
Piga Software
http://icculus.org/piga/

cage
Posts: 18
Joined: Monday 02nd September 2019 5:47am
Location: Phoenix Arizona

Re: Kill FireFox

Post by cage » Sunday 15th September 2019 8:08am

I look at it this way. If you have $2000.00 worth of tools why use a breaker bar to break loose the lug nuts on you car when you can use a impact wrench. I have done it with the task manager, and a script from the command line. But it's more fun making things work with Gambas. :D Gambas is just another tool to make computing life much easier. I use to program with VB1-6, and while it was good tool Gambas is much better tool at doing things.

vuott
Posts: 25
Joined: Wednesday 05th April 2017 6:07pm

Re: Kill FireFox

Post by vuott » Monday 16th September 2019 9:18am

cage wrote:
Saturday 14th September 2019 8:41pm
Feel free to modify the program to your tastes.
...without using Shell:
Private wid As Integer[]


Public Sub Form_Open()
 
CheckFox
 
End


Public Sub BuKillFox_Click()
  
  Dim dw As DesktopWindow
  
  dw = Desktop.Windows.FromHandle(wid[0])
  
  dw.Close()
  Wait 1
  BuKillFox.Enabled = False
  CheckFox
  
End

Public Sub CheckFox()
 
  wid = Desktop.FindWindow("*Firefox*", Null, Null)

  If wid.Count == 0 Then
    Label1.text = "FireFox Not Running" 
  Else 
    Label1.Text = "FireFox Is Running"
    BuKillFox.Enabled = True
  Endif
   
End

cage
Posts: 18
Joined: Monday 02nd September 2019 5:47am
Location: Phoenix Arizona

Re: Kill FireFox

Post by cage » Tuesday 17th September 2019 3:44am

That looks very interesting but I get an error when I run it. Can you tell me how and I need to make it work?

vuott
Posts: 25
Joined: Wednesday 05th April 2017 6:07pm

Re: Kill FireFox

Post by vuott » Tuesday 17th September 2019 6:43am

cage wrote:
Tuesday 17th September 2019 3:44am
... but I get an error when I run it.
Where ?

cage
Posts: 18
Joined: Monday 02nd September 2019 5:47am
Location: Phoenix Arizona

Re: Kill FireFox

Post by cage » Tuesday 17th September 2019 8:00am

Okay got it working but now it always shows Fire Fox as not running. In other words wid.Count always equals zero. Not sure what desktop or Distro your are using but I am using Arch Linux with a XFCE desktop. I never used the gb.desktop before and would really like to learn and understand it. It looks like an interesting way to do things.

vuott
Posts: 25
Joined: Wednesday 05th April 2017 6:07pm

Re: Kill FireFox

Post by vuott » Tuesday 17th September 2019 8:15am

I use Linux Mint 19.2 Tina - Desktop: Cinnamon 4.2.4

However you can also try using the other two parameters of the Desktop.FindWindow() function.

cage
Posts: 18
Joined: Monday 02nd September 2019 5:47am
Location: Phoenix Arizona

Re: Kill FireFox

Post by cage » Tuesday 17th September 2019 7:13pm

Thanks vuott for the information. It's weird but I tried it again today and for some reason it works fine. Really strange. Anyone that uses this way of vuott needs to know that you have to install gb.desktop and gb.image to make it work. I found that when installing those components to save the project and reload it. I think that was my problem as to why it wasn't working correctly. After reloading the project it worked fine.

User avatar
Technopeasant
Posts: 15
Joined: Saturday 13th July 2019 6:50pm

Re: Kill FireFox

Post by Technopeasant » Thursday 19th September 2019 3:33am

cage wrote:
Sunday 15th September 2019 8:08am
I look at it this way. If you have $2000.00 worth of tools why use a breaker bar to break loose the lug nuts on you car when you can use a impact wrench. I have done it with the task manager, and a script from the command line. But it's more fun making things work with Gambas. :D Gambas is just another tool to make computing life much easier. I use to program with VB1-6, and while it was good tool Gambas is much better tool at doing things.
For me, it is often more fun to use the less than ideal tool to get the job done, just to show that it can be done.

"I am endeavoring, ma'am, to construct a mnemonic memory circuit using stone knives and bearskins."

:ugeek:
Technical director,
Piga Software
http://icculus.org/piga/

Post Reply