Categories
Computing

How to determine which application is stealing focus

Recently I've had an issue that every 15 minute whatever app I was working on would loose a focus for a few seconds. Obviously some another process window was stealing the focus but the problem was that this another window was not visible and I got the focus back after few seconds. Additionally this also prevented my laptop from going to sleep and even starting the screensaver.

After googling around a bit I find a post from the Matt Gertz It’s Elementary: Using VB To Get Process Information. It describes a way to create an application which prints out information about the current foreground window and the owning process once the application loses focus.

After creating such a small application and leaving it running for a while I found that my mobile telecom Internet USB stick update program was running every 15 minutes (T-Mobile Internet Manager / LiveUpdate / ouc.exe). After that it was easy to find where the application was being started by using the fantastic Sysinternals Autoruns application and turning it off.

I've attached 32 bit and 64 bit versions of the application. First try to run with 32 bit version and if you get an error that 32 bit application can not read 64 bit process information then run the 64 bit application.

Focus stealer 32 bit
Focus stealer 64 bit

Categories
Computing

Right-click to add watermark/copyright to your image

My wife is making hand-crafted jewellery, bags and similar things (you can see her site Čarapica). One of the problems that we had was that when she placed the images of the things that she created on the internet it would sometimes be 'borrowed' by someone and used for some other purposes. In order to prevent that from happening we decided to add watermark to all images that we will be placing on her web site/facebook/online shop.

There might be some existing tools for doing something like that but since I'm a programmer I wanted to created such a utility by myself. Luckily enough it turned out I did not need to do any programming since there are tools such as ImageMagick which can be used for such a purpose. I've managed to make a working solution by using similar steps that I used when adding functionality to right click on file to add it to windows firewall.

There are several steps to achieve the desired functionality:

Download the ImageMagick package

Its best that you just download the zip package (you can find the version I used here and unpack it to the folder where your 'application' will be located. In my case I downloaded it into c:\Apps\Watermark.

Create a batch file that will perform the actual watermarking of an image

Here is the content of the watermark.bat file which will be used to re-size the image:

c:\Apps\Watermark\convert -size 550x250 -background none -fill #FFFFFF50 -font "Segoe-UI" -pointsize 96 -rotate 25 label:%1 miff:- | c:\Apps\Watermark\composite -tile - "%~n2%~x2" miff:- | c:\Apps\Watermark\convert - -resize 1024x768 "%~n2_w%~x2"

The batch file does several things:

  1. It uses the convert.exe utility to generate a label image which is slightly rotated and semitransparent (text defined by first parameter of the batch file)
  2. It pipes the newly created image to composite.exe utility which takes the original image (defined by seconds parameter of the batch file) and adds the label image on top it
  3. The watermarked image is finally resized to 1024x768 and saved as original_w.extension. This final step can be omitted if you wish to resize the image - just remove the part miff:- | c:\Apps\Watermark\convert - -resize 1024x768 from the command

Here is an example of using the command c:\Apps>c:\Apps\Watermark\watermark.bat "OP" a_view_from_Gradec.jpg on an image from Zagreb (the city where I live):
[onehalf half="1"]Original image: Zagreb [/onehalf][onehalf half="2"]Final image: Watermarked [/onehalf]

Enable right click on file to invoke our new batch file

This is relatively simple. We just need to enter a registry entry which will add a new option when you right click on the file. Inside the registry entry you need to define the actual text that will be used as a watermark. Here is the content of the water-register.reg file which can be used to add necessary registry entry:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\Watermark\command]
@="cmd.exe /c c:\\Apps\\Watermark\\watermark.bat \"-your watermark text-\" \"%1\""

The drawback of the given registry file is that the right click context menu appears for every file type, not just executable. If somebody know how to make it appear for just image file then please send me a note (and no, just changing the registry from HKEY_CLASSES_ROOT\* to HKEY_CLASSES_ROOT\.jpg or something similar does not do it :)).

Categories
Computing

DNS issues with Windows 7

Note: I have transferred this blog from my old blog site: http://dcarapic.blogspot.com/ so I am reposting most of the stuff from there

Recently I've had a problem with my laptop connected to my home network. For some reason DNS was working intermittently .. meaning that it sometimes worked and sometimes didn't. It also seamed that it was susceptible to throttling .. meaning that if I opened several browser windows at once it would not work. I've scoured the net searching for a solution and was not able to find anything that applied to me. Most of the issues were connected to some 3rd party VPN software or similar.

What really annoyed me was that it was only happening with my laptop and only at home. Finally I found a forum comment somewhere (lost the link unfortunately) where the author stated that turning of IP flood protection on his router fixed the issue for him/her. Reading that I remembered that my router was reset lately (I don't know how, it just happened) so I had to reconfigure it again. During my configuration I turned on IP flood detection (it looks like something you would want to have turned on). So I opened the router configuration and turned off IP flood detection and lo and behold ... everything works great.

How I tested my DNS

Initially I downloaded a small tool called DNS Name Speed Benchmark to determine if there was an issue with my DNS provider but I did not get that much information out of it. It either and all DNS providers could be reached and checked or it did not work at all. After that I just used nslookup command in combination with powershell to run the command in loops.

PS C:\Users\dcarapic> for(1..100) { nslookup www.google.com }

This would execute DNS lookup for the given host (using your default DNS server) a hundred times. During my initial run lookup was time outing here and there and once I tried opening the browser and loading lots of pages it was time-outing all the time. Once I removed the IP flood detection the output of the nslookup was clear and without any time-outs at any time!

Categories
Computing

Right click to block programs in windows firewall

Note: I have transferred this blog from my old blog site: http://dcarapic.blogspot.com/ so I am reposting most of the stuff from there

I am using the standard windows firewall and in several cases I wanted to quickly block an application from accessing the internet. Usually this would require me to start up the standard windows firewall configuration utility %windir%\system32\WF.msc and manually add outgoing and/or incoming rules for the application main executable.
This can be a bit tedious so I've been searching for an utility to quickly add rules to the windows firewall. Unfortunately I've not been successful so I've decided to create an utility on my own. My goal was to get a new entry in the right click context menu for an application fiel which would add the blocking firewall rules (in/out). Luckily enough I did not need to do any programming since the required functionality could be achieved by standard windows batch scripting and utilities.

There are 3 parts to achieve the desired functionality:

  1. Creating a batch file that will block the application

Windows 7 already provides a command line utility (netsh.exe) to achieve this and the syntax is the following:

netsh advfirewall firewall add rule name="rule name" dir=in action=block program="some.exe"
netsh advfirewall firewall add rule name="rule name" dir=out action=block program="some.exe"

With this command it is simple to create a batch file which will block the given application executable, lets call it block.bat:

rem block.bat
@set rulename =
@set /p rulename= Rule name (%~n1):
@if '%rulename%' == '' set rulename=%~n1
netsh advfirewall firewall add rule name="%rulename% (in)" dir=in action=block program=%1
netsh advfirewall firewall add rule name="%rulename% (out)" dir=out action=block program=%1

The batch file is simple enough. It is meant to be called with the full path and file name of the executable: block.bat c:\apps\some.exe

After it starts up it asks the user for the name of the rule. If the user just presses ENTER then the name of the executable will be used as a prefix of the name for two rules (incoming and outgoing). So in our case the actual executed commands (if user were to just press ENTER) would be:

netsh advfirewall firewall add rule name="some (in)" dir=in action=block program="c:\apps\some.exe"
netsh advfirewall firewall add rule name="some (out)" dir=out action=block program="c:\apps\some.exe"
  1. Elevating the execution of the batch file

Unfortunately (or fortunately) it is not possible to invoke netsh as a normal user so we need to elevate the execution of the batch file. It should be possible to do this via the standard windows runas command but at home my user does not have a password and runas is not possible if you do not have the password set. Happily enough there are 3rd party utilities which can be used for elevation and the one I use - elevate has the same command line options and cmd.exe so it fits just fine.

  1. Enabling right click on file to invoke our new batch file

This is relatively simple. We just need to enter a registry entry which will add a new option when you right click on the file. New option will invoke the batch file in elevated mode. Batch file will start and asks us for the name of the rule and thats it. Here is the content of the .reg file which can be used to add necessary registry entry (lets call it fw-register.reg:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\Firewall (block)\command]
@="c:\\folder\\elevate.exe /c c:\\folder\\block.bat \"%1\""

This registry file assumes that you have the batch file and the elevate utility in c:\folder. Replace c:\\folder with the path to the actual files (do not forget to escape the folder separator \ characters with \\.

The drawback of the given registry file is that the right click context menu appears for every file type, not just executable. If somebody know how to make it appear for just .exe and .com files then please send me a note (and no, just changing the registry from HKEY_CLASSES_ROOT\* to HKEY_CLASSES_ROOT\.exe does not do it :)).