Monitor TaskBar Protection

Just starting out? Need help? Post your questions and find answers here.
LJ
Enthusiast
Enthusiast
Posts: 177
Joined: Wed Apr 30, 2003 4:00 pm

Monitor TaskBar Protection

Post by LJ »

The original code below was created by who I do not know, but let me say they are a genius. I modified their code for a recent project I completed that monitors the task bar and if an instance of the Internet Explorer browser is opened, it immediately closes it. This technique can also be used for software protection such as closing the program Paint (which is often used to capture/rip another programs screen images) if its opened while the program is running.

Paste the code in, then use the command: RefreshList() inside your Repeat/Window event loop.

Code: Select all

;-ini 
Structure info 
  handle.l 
  process.l 
  class$ 
  name$ 
EndStructure 
#PROCESS_ALL_ACCESS=$FFF 

NewList info.info() 
NewList AllHandle() 

Procedure.s GetClassName(handle) 
  class$=Space(1024) 
  GetClassName_(handle,@class$,Len(class$)) 
  ProcedureReturn Left(class$,Len(class$)) 
EndProcedure 
Procedure.s GetTitle(handle) 
  name$=Space(1024) 
  GetWindowText_(handle,@name$,Len(name$)) 
  ProcedureReturn Left(name$,Len(name$)) 
EndProcedure 
Procedure AddInfo(Handle) 
  process=0 
  GetWindowThreadProcessId_(handle,@process) 
  Class$=GetClassName(handle) 
  Name$=GetTitle(handle) 
  
  ResetList(info()) 
  quit=0 
  i=0 
  Repeat 
    If NextElement(info()) 
      If process < info()\process 
        quit=1 
      ElseIf process=info()\process 
        If class$ < info()\class$ 
          quit=1 
        ElseIf UCase(class$)=UCase(info()\class$) 
          If name$ < info()\name$ 
            quit=1 
          ElseIf UCase(name$)=UCase(info()\name$) 
            If handle < info()\handle 
              quit=1 
            ElseIf handle=info()\handle 
              quit=3 
            EndIf 
          EndIf 
        EndIf 
      EndIf 
    Else 
      quit=2 
    EndIf 
  Until quit 
  If quit<3 
    If quit=1 
      If PreviousElement(info())=0: ResetList(info()) :EndIf 
    EndIf 
    AddElement(info()) 
    info()\handle=handle 
    info()\process=process 
    info()\class$=class$ 
    info()\name$=name$ 
    If class$ = "IEFrame" ; This checks for the Internet Explorer class
      postmessage_(info()\handle,#wm_close,0,0) ; This closes Internet Explorer

     EndIf
    
  EndIf 
EndProcedure 

Procedure RefreshList() 
  handle=getwindow_(WindowID(),#GW_HWNDFIRST) 

  quit=0 
  Repeat 
    AddInfo(handle) 
    x=getwindow_(handle,#GW_CHILD) 
    If x 
      AddElement(allhandle()) 
      allhandle()=x 
    EndIf 
    x=getwindow_(handle,#GW_HWNDNEXT) 
    If x 
      handle=x 
    Else 
      If LastElement(allhandle()) 
        handle=allhandle() 
        DeleteElement(allhandle()) 
      Else 
        quit=1 
      EndIf 
    EndIf 
  Until quit 
 
  ResetList(info()) 
  
    
  While NextElement(info()) 
    If oldprocess<>info()\process 
      oldprocess=info()\process 
      a$=Hex(oldprocess) 
    Else 
      a$="              ''" 
    EndIf 
 
  Wend 

EndProcedure 
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Monitor TaskBar Protection

Post by PB »

> Paste the code in, then use the command: RefreshList() inside your
> Repeat/Window event loop.

It doesn't close any IE windows for me (W2K Pro)...
LJ
Enthusiast
Enthusiast
Posts: 177
Joined: Wed Apr 30, 2003 4:00 pm

Post by LJ »

It works on Windows 98, and Windows XP. I created some more detailed code for you, tried to clean it up a bit. This will open a browser control, but while running will close Internet Explorer if it's opened. Change the URL "bisect.ldj" to be an .htm web page of your choice (make sure the .html page is in the same local directory as your PB project file). After your web page is displayed, click on Start, Programs, and try to open the Internet Explorer browser, it should blink for a second and then automatically close.

Code: Select all

;-ini 
Structure info 
  handle.l 
  process.l 
  class$ 
  name$ 
EndStructure 
#PROCESS_ALL_ACCESS=$FFF 

NewList info.info() 
NewList AllHandle() 

Procedure.s GetClassName(handle) 
  class$=Space(1024) 
  GetClassName_(handle,@class$,Len(class$)) 
  ProcedureReturn Left(class$,Len(class$)) 
EndProcedure 
Procedure.s GetTitle(handle) 
  name$=Space(1024) 
  GetWindowText_(handle,@name$,Len(name$)) 
  ProcedureReturn Left(name$,Len(name$)) 
EndProcedure 
Procedure AddInfo(Handle) 
  process=0 
  GetWindowThreadProcessId_(handle,@process) 
  Class$=GetClassName(handle) 
  Name$=GetTitle(handle) 
  
  ResetList(info()) 
  quit=0 
  i=0 
  Repeat 
    If NextElement(info()) 
      If process < info()\process 
        quit=1 
      ElseIf process=info()\process 
        If class$ < info()\class$ 
          quit=1 
        ElseIf UCase(class$)=UCase(info()\class$) 
          If name$ < info()\name$ 
            quit=1 
          ElseIf UCase(name$)=UCase(info()\name$) 
            If handle < info()\handle 
              quit=1 
            ElseIf handle=info()\handle 
              quit=3 
            EndIf 
          EndIf 
        EndIf 
      EndIf 
    Else 
      quit=2 
    EndIf 
  Until quit 
  If quit<3 
    If quit=1 
      If PreviousElement(info())=0: ResetList(info()) :EndIf 
    EndIf 
    AddElement(info()) 
    info()\handle=handle 
    info()\process=process 
    info()\class$=class$ 
    info()\name$=name$ 
    If class$ = "IEFrame"
      postmessage_(info()\handle,#wm_close,0,0)
     EndIf
    
  EndIf 
EndProcedure 

Procedure RefreshList() 
  handle=getwindow_(WindowID(),#GW_HWNDFIRST) 
;  ClearList(allhandle()) 
  quit=0 
  Repeat 
    AddInfo(handle) 
    x=getwindow_(handle,#GW_CHILD) 
    If x 
      AddElement(allhandle()) 
      allhandle()=x 
    EndIf 
    x=getwindow_(handle,#GW_HWNDNEXT) 
    If x 
      handle=x 
    Else 
      If LastElement(allhandle()) 
        handle=allhandle() 
        DeleteElement(allhandle()) 
      Else 
        quit=1 
      EndIf 
    EndIf 
  Until quit 
 
  ResetList(info()) 
  
    
  While NextElement(info()) 
    If oldprocess<>info()\process 
      oldprocess=info()\process 
      a$=Hex(oldprocess) 
    Else 
      a$="              ''" 
    EndIf 
 ;   AddGadgetItem(0,-1,a$+Chr(10)+info()\class$+Chr(10)+info()\name$+Chr(10)+Hex(info()\handle)) 

  Wend 
  

EndProcedure 
Procedure ResizeWebWindow()
  ResizeGadget(10, -1, -1, WindowWidth(), WindowHeight()-52)
 
EndProcedure

OpenWindow(0, 0, 0, 797, 550, #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget, "Browser")

  CreateGadgetList(WindowID(0))
    
   
  appdir$=Space(255) : GetCurrentDirectory_(255,@appdir$) : If Right(appdir$,1)<>"\" : appdir$+"\" : EndIf 
  url$=appdir$+"bisect.ldj" 
 
 If WebGadget(10, 0, 31, 0, 0, url$) = 0 : MessageRequester("Error", "ATL.dll not found", 0) : End : EndIf
  
  ;AddKeyboardShortcut(0, #PB_Shortcut_Return, 0)
  ResizeWebWindow()
    
 
 RefreshList() 
  
  Repeat
  RefreshList()
    Event = WaitWindowEvent()
    
    Select Event
      Case #PB_Event_Gadget
      
        Select EventGadgetID()
       
            
        EndSelect      
          
    EndSelect
      
  Until Event = #PB_Event_CloseWindow

RefreshList()
End

PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> Change the URL "bisect.ldj" to be an .htm web page of your choice
> After your web page is displayed, click on Start, Programs, and try to
> open the Internet Explorer browser, it should blink for a second and
> then automatically close.

EDITED: I know I said this tip works, but I just tried it again today because
I wanted to see if I could stop other windows, but the tip no longer works.
I can open new IE instances even when following the above instructions.
Don't know why it worked before. Using Win 2K Pro.
Post Reply