Jump to content

Disable Google Incognito Mode


Sapient
 Share

Recommended Posts

Here is the source code for a program to detect and kill any Google Incognito windows that pop-up. This is useful for people who are relying on extensions such as Chrome Nanny to help the users be more productive. To set it up, save the code as "SpyVsSpy.au3" then open the code with SciTE Editor and Build the executabe (Tools->Build), then schedule it through Windows Task Scheduler. (If you think of a better way to run it in the background to prevent non-admin task kill, let me know.)

; author: Patrick Parker <patrick_x99 (email at) hotmail.com>
; this code is provided free for personal use and provided as-is with no warranty or promise of fitness for any purpose

#NoTrayIcon
#include <Misc.au3>

if _Singleton("SpyVsSpy",1) = 0 Then
    Exit ; already running
EndIf
$loop = 1
While $loop
  $wins = WinList("[REGEXPCLASS:Chrome.*; REGEXPTITLE:.* - Google Chrome]")
  For $i = 1 to $wins[0][0]
    $win = $wins[$i][1] ; save the handle
    If IsVisible($win) and IsActive($win) Then
      $dim = WinGetPos($win)
      If IsMaximized($win) Then
        $x = $dim[0] + ($dim[2] - 49)     ; x = window x + (window width - 49)
        $y = $dim[1] + 40                 ; y = window y + (40 if maximized)
      Else
        $x = $dim[0] + ($dim[2] - 45)     ; x = window x + (window width - 45)
        $y = $dim[1] + 48                 ; y = window y + (48 if not maximized)
      EndIf   
      $color = Hex(PixelGetColor( $x , $y , $win), 6)
      If $color = "FFFFFF" Then
;         MsgBox(0, "Details", "Title=" & $wins[$i][0] & @LF & "Handle=" & $win & @LF & "The hex color is " & $color & " at position " & $x & "," & $y)
          WinKill($win)
;         $loop = 0
      EndIf
    EndIf
  Next
Sleep(500) ; 1/2 second
WEnd

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf
EndFunc

Func IsActive($handle)
  If BitAnd( WinGetState($handle), 8 ) Then 
    Return 1
  Else
    Return 0
  EndIf
EndFunc

Func IsMaximized($handle)
  If BitAnd( WinGetState($handle), 32) Then
    Return 1
  Else
    Return 0
  EndIf
EndFunc

{edit: note, a new and improved version of this code has been posted below. continue reading the thread for details }

Edited by Sapient
Link to comment
Share on other sites

This is useful for people who are relying on extensions such as Chrome Nanny to help the users be more productive.

But surely if they had the willpower not to be in Incognito mode whilst using Google Nanny, they wouldn't need this. And if they did need this, they'd still be able to disable it and so we're in a cycle.
Link to comment
Share on other sites

But surely if they had the willpower not to be in Incognito mode whilst using Google Nanny, they wouldn't need this. And if they did need this, they'd still be able to disable it and so we're in a cycle.

If you are someone who uses Chrome Nanny extension then you are aware that the user CAN disable it, but it requires prolonged conscious effort to do so (typing out a long series of keystrokes). However, they can work around the whole thing with one click by entering incognito mode, which makes it take almost no time or conscious thought. This is an attempt to fix that.

If there is no value in such an approach to you, then fine, but I assure you some people (maybe a small minority) who do find it useful and you can read the feedback on that extension for more details. Now I'm no expert on human psychology but I do know that some people find it useful. If you don't, then that's fine, don't download it. Your choice.

Link to comment
Share on other sites

Spy vs. Spy - hmmm an old C64 game...

Br,

UEZ

Spy vs Spy was from MAD magazine, which was made into a computer game, I read the mags and played the game, not on C64 but on ZX Spectrum. :graduated:

http://en.wikipedia.org/wiki/Spy_vs._Spy

Some guy's script + some other guy's script = my script!

Link to comment
Share on other sites

If there is no value in such an approach to you, then fine, but I assure you some people (maybe a small minority) who do find it useful and you can read the feedback on that extension for more details. Now I'm no expert on human psychology but I do know that some people find it useful. If you don't, then that's fine, don't download it. Your choice.

Sorry, I didn't mean to offend you.

The code is nice and does what it's intended to do. But I just see it as another thing to turn off before I can continue my wrong doings on the Internet whilst I should be working.

I really didn't mean to hurt you.

Link to comment
Share on other sites

  • 1 month later...

Thanks a million for making this!! I had avoided using ChromeNanny simply because anytime I would want to "crack" ChomeNanny all I had to do was hit control + shift + n and bam I could circumvent ChromeNanny and then procrastinate all I wanted.

The problem is I'm not hugely programmer savvy... I mean I downloaded the "single file executable called Sc1 (610K)" here

Once downloaded I end up with a file called "Sc223.exe" which opens fine, I can open the "SpyVsSpy.au3" in it which had created by copying your script into Notepad and saving it as "SpyVsSpy.au3" obviously. I also tried saving it in SciTE Editor - (neither notepad nor SciTE have an option to choose .au3 as the file extension though.)

Once I select Tools>Build I get the following:

C:\program files\autoit3\aut2exe\aut2exe.exe /in "C:\Users\Phillip\Downloads\SpyVsSpy.au3"

'C:\program' is not recognized as an internal or external command,

operable program or batch file.

>Exit code: 1

What did I do wrong?? -- Edit: Also sorry for bringing back a thread that was a little over a month old, but I really need help! :x

Edited by snowboarder1087
Link to comment
Share on other sites

I`m sorry, but I feel like I`ve done everything correctly now.

Downloaded SciTE4AutoIt3.exe

Created the SpyVsSpy.au3 file.

Built the SpyVsSpy.exe Application in SciEditor.

Even whitelisted it in my Spyware programs so it wasn`t marked as malware.

Opened Task scheduler, created a task and named it Disable Incognito (configured for Windows 7, Windows Server 2008 R2), Set the trigger for it to run at System Startup. Set the action to be `Start a program` and the program to start being ``C:\Users\Phillip\Documents\SpyVsSpy.exe`` with no Conditions set for it.

But I can still hit Control + Shift + n and get incognito...

Edited by snowboarder1087
Link to comment
Share on other sites

Bump... Anyone know why I can't get this script to work and block my ability to use Chrome incognito?

Hey snowboarder. Sorry I just noticed this reply.

Looks like you've done everything correctly so far, but the Task Scheduler in Windows 7 is a pain to configure correctly (I know because I'm also using Windows 7). My guess is that SpyVsSpy.exe isn't even running.

Try double-clicking SpyVsSpy.exe to run it, so that way you at least know it is running.

Then see if you can launch incognito windows.

This way you can isolate the problem to the script or the task scheduler.

I'm not an expert on the Windows Task Scheduler so I will only be able to give limited advice on it, but there are other resources and forums out there if that is the issue.

I will say to make sure you turn off all conditions that disable the task, for example when on battery power, when idle, etc. I set it to run every five minutes and at logon.

Edited by Sapient
Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...

Hey Sapient, great post. It was exactly what I was looking for, but I'm stuck right now.

The part where you have to Build the .exe file...I get this:

>C:\program files\autoit3\aut2exe\aut2exe.exe /in "C:\Users\Admin\Documents\Vignesh\SpyVsSpy.au3"
'C:\program' is not recognized as an internal or external command,
operable program or batch file.
>Exit code: 1

Could anyone help me on what I'm doing wrong? I'm not much of a programmer or anything..

Link to comment
Share on other sites

Hey Sapient, great post. It was exactly what I was looking for, but I'm stuck right now.

The part where you have to Build the .exe file...I get this:

>C:\program files\autoit3\aut2exe\aut2exe.exe /in "C:\Users\Admin\Documents\Vignesh\SpyVsSpy.au3"
'C:\program' is not recognized as an internal or external command,
operable program or batch file.
>Exit code: 1

Could anyone help me on what I'm doing wrong? I'm not much of a programmer or anything..

if you have AutoIt installed, right click the Source code (SpyVsSpy.au3) and press Compile script.
Link to comment
Share on other sites

The post by rmkbow suggests that it checks the presence of the incognito head. That is not the case at all. It checks how far the address bar stretches to the right side of the window. The address bar width is affected by the presence of any addons, that place buttons next to the wrench. Like this one:

Posted Image

Extensions are by default disabled in incognito mode as seen here:

Posted Image

So, in order for to work:

1. You must have an extension installed that will place a button next to the wrench.

2. The extension must be disabled when the browser enters incognito mode (default).

This breaks when:

1. You disable all extensions (closes the window all the time)

2. You allow extensions to work in incognito mode (never closes the window)

All of this explains the comment in the first post: "useful for people who are relying on extensions such as Chrome Nanny". Because Chrome Nanny adds a similar button.

Proposed solution: Check the presence of the incognito mode head instead.

Edited by Manadar
Link to comment
Share on other sites

Proposed solution: Check the presence of the incognito mode head instead.

Thanks for the feedback. I went with that simplistic approach because I didn't want to worry about all the possible skins out there or potential artistic tweaks to the incognito icon which may be pushed with future google updates.

However, here is version 2.2 below and it does address your concerns (and detects another vulnerability you didn't mention yet).

; SpyVsSpy.au3, version: 2.2
; author: Patrick Parker <patrick_x99 (email at) hotmail.com>
; this code is provided free for personal use and provided as-is with no warranty or promise of fitness for any purpose

#NoTrayIcon
#include <Misc.au3>
#include <Math.au3>

if _Singleton("SpyVsSpy",1) = 0 Then
    Exit ; already running
EndIf
$loop = 1
$hat_fails = 0
$ref_fails = 0
While $loop
  $wins = WinList("[REGEXPCLASS:Chrome.*; REGEXPTITLE:.* - Google Chrome]")
  For $i = 1 to $wins[0][0]
    $win = $wins[$i][1] ; save the handle
    If IsVisible($win) and IsActive($win) Then
      $dim = WinGetPos($win)
      If IsMaximized($win) Then
        $hat_x = 20
        $hat_y = 2
        $ref_x = 75
        $ref_y = 28
      Else
        $hat_x = $dim[0] + 25
        $hat_y = $dim[1] + 15
        $ref_x = $dim[0] + 80
        $ref_y = $dim[1] + 44
      EndIf
    
      $checksum = PixelChecksum($hat_x, $hat_y, $hat_x+8, $hat_y+5, 1, $win)
;     MsgBox(0, "Details", "Title=" & $wins[$i][0] & @LF & "Handle=" & $win & @LF & "The color checksum is " & $checksum)
;     Exit

      If $checksum = 3044775763 Then
        $hat_fails = $hat_fails+1 ; detected checksum of incognito hat, as sampled from Chrome 9.0.597.94
      Else
        $hat_fails = 0
      EndIf

      $colordiff = ColorDiff(PixelGetColor( $ref_x , $ref_y , $win), PixelGetColor( $ref_x , $ref_y+11 , $win))
;     MsgBox(0, "Details", "Title=" & $wins[$i][0] & @LF & "Handle=" & $win & @LF & "The color 0x" & Hex(PixelGetColor($ref_x,$ref_y,$win),6) & " at " & $ref_x & "," & $ref_y & " is " & $colordiff & " shades different from color 0x" & Hex(PixelGetColor($ref_x,$ref_y+11,$win),6) & " at " & $ref_x & "," & ($ref_y+11))
;     Exit

      If $colordiff < 31 Then
        $ref_fails = $ref_fails+1 ; unable to sample pixels because active window is obscured
      Else
        $ref_fails = 0
      EndIf
    
      If $hat_fails > 0 Or $ref_fails > 4 Then
        WinKill($win)
        $hat_fails = 0
        $ref_fails = 0
      EndIf
    EndIf
  Next
  Sleep(500) ; 1/2 second
WEnd

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf
EndFunc

Func IsActive($handle)
  If BitAnd( WinGetState($handle), 8 ) Then 
    Return 1
  Else
    Return 0
  EndIf
EndFunc

Func IsMaximized($handle)
  If BitAnd( WinGetState($handle), 32) Then
    Return 1
  Else
    Return 0
  EndIf
EndFunc

Func ColorDiff($color1, $color2, $min_return = 0)
  If $color1 = $color2 Then
    Return $min_return
  EndIf
    Return ColorDiff(BitShift($color1,8), BitShift($color2,8), _Max($min_return, Abs(BitAnd($color1, 0xFF) - BitAnd($color2, 0xFF))))
EndFunc
Edited by Sapient
Link to comment
Share on other sites

  • 2 months later...

Sapient,

The running the compiled executable closes all chrome windows, regardless if they were incognito or not.

Is this an issue you've heard or seen before? Is there a fix or workaround?

Thanks

~madd

Hi, that could happen for a couple of reasons. You could be using an odd skin that makes it fail the color reference checks. Or your computer is very slow and so it can't sample a valid color reference within the allowed threshold of time. Or your version of chrome renders the browser differently from mine.

The first thing I would try is go back to the default skin and increase the $ref_fails threshold. Find the line where it says $ref_fails > 4 and increase that number to 8, then recomopile.

If that doesn't solve your problem then uncomment both of the MsgBox lines, recompile, and let me know what messages pop up.

Also, remember you have to kill the running SpyVsSpy program and restart it for the changes to take effect.

If it turns out the problem was the skin, please let me know which skin you were using so I can adjust the algorithm. So far it works for all the ones I tested.

Edited by Sapient
Link to comment
Share on other sites

  • 3 months later...

Dont want to spoil your fun or anything, but theres a more Chrome way of doing this.....

http://dev.chromium.org/administrators/policy-list-3#IncognitoEnabled

....so on windows (only tested in xp) you can create a reg entry to disable incognito.

Create a text file called noIncognito.reg and enter this as its text.....

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome]
"IncognitoEnabled"=dword:00000000

....save it and then double click the file to launch it and it should enter the right reg key and then you wont be able to open incognito mode.

Another useful policy for this sort of thing is the force install policy, this is good if you want to runny nanny software and dont want your kids getting past it......

http://dev.chromium.org/administrators/policy-list-3#ExtensionInstallForcelist

...the extension cant be installed before adding this policy, or just uninstall the extension after adding the policy and it will install the extension and they wont be able to uninstall or disable it.

These settings will apply to all instances of chrome regardless of what profile they are using.

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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