Microsoft Windows and all that goes with it

Chain of Fools

Microsoft always took pride in maintaining compatibility. One guy decided to test just how upgradeable Windows were going from Windows 1.01 to Windows 7.

P.S. Do notice that there is no Windows ME. Repressed memory perhaps?

Do Not Analyze Me

I like using Google Analytics for tracking statistics. Those statistics read like porn to guy who loves numbers. There is only one problem with them - they count every visitor. That would also mean that my administrative tasks are skewing numbers. We cannot have that!

In order to disable logging own visits we need to check what exactly Analytics’ code does:

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-4401313-2']);
  _gaq.push(['_trackPageview']);
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script> 

Code is pretty simple and only place where any action can possibly happen is in line 7 where we see ga.js script. Depending on whether our page is http or https those URL’s are http://www.google-analytics.com/ga.js and https://ssl.google-analytics.com/ga.js respectively. As soon as we disable those two servers our own visits will not be logged.

Since we cannot disable servers as such we need to do next best thing and disable them in our part of universe. There is nice file called “hosts” situated in “C:\Windows\System32\drivers\etc” (or in “/etc” for *nix systems). In this file we can override any DNS resolution and assign any IP address to any host name.

File format is quite simple and I will not explain it here. It is enough to say that we just need to append two lines (after adding write permissions, by default this file is not writable by normal user):

···
127.0.0.1	www.google-analytics.com
127.0.0.1	ssl.google-analytics.com

These lines are just forwarding any call to Analytics servers to our own computer. Since we do not have Google’s infrastructure it is pretty safe to assume that all requests will go nowhere. And that also means that computer with this “fix” will not be recorded by Google Analytics.

P.S. Modifications to “hosts” file are great way to annoy somebody in office who left computer unlocked.

Keyboard Enlargement

Illustration

I got new monitor for my Windows Media Center machine and I stumbled upon curious issue.

I control this machine via on-screen keyboard and on new monitor it’s window was too small and of course there was no way of resizing it. That is, there was no GUI way of resizing it. I could always try to resize it programatically with a little help of SetWindowsPos function.

It was as simple as running on-screen keyboard, getting monitor it is on (in order to calculate size, it is not really a must) and then resizing it to desired size:

var process = new Process();
process.StartInfo.FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "osk.exe");
process.StartInfo.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
process.Start();

process.WaitForInputIdle();

var win32Rect = new NativeMethods.tagRECT();
NativeMethods.GetWindowRect(process.MainWindowHandle, out win32Rect);
var originalRect = new Rectangle(win32Rect.left, win32Rect.top, win32Rect.right - win32Rect.left + 1, win32Rect.bottom - win32Rect.top + 1);

var screen = Screen.FromRectangle(originalRect);
var newWidth = (int)(screen.WorkingArea.Width / 2.5);
var newHeight = (int)(newWidth / 2.5);

NativeMethods.SetWindowPos(process.MainWindowHandle, IntPtr.Zero, 0, 0, newWidth, newHeight, NativeMethods.SWP_NOMOVE | NativeMethods.SWP_NOZORDER);

As far as size is concerned I opted for 40% of screen width (width / 2.5) and 40% of that was to be assigned as height. Exact numbers are not really important but those were ones that I liked the most. It was enough to run this program only once since Microsoft’s On-screen Keyboard will remember previous size upon exit.

If you need bigger on-screen keyboard for Windows XP, try it.

Too Aggressive for My Taste

Illustration

Last night I had some videos to encode. I prepared everything upfront and I left my computer to do work overnight. At morning I was greeted with logon screen. My Windows decided to install updates. It didn’t matter to them that some other program was running. Kill and burn was their motto.

Yes, I know that I can turn on “Download updates but let me choose whether to install them”. However, when I do that, Action center starts complaining about non-optimal settings. If I turn this warning off, I just turned off all messages regarding Windows Update. If I leave it on, it leaves tray icon and I may miss other important messages.

There is just no right solution for this and it annoys me quite a bit…

P.S. I know that tray area is called notification area these days. I just prefer old naming.

Repairing Hibernated Windows XP Mode.

Illustration

I like Windows XP Mode a lot. As soon as I need to test something in XP, it is there. As soon as I am done, it just gets hibernated and waits for next chance to be used.

After upgrading my BIOS I could not get it to start anymore. It just said “‘Windows XP Mode’ could not be restored because either host processor type mismatch or lack of hardware-assisted virtualization support in the system.” I just love those messages that pinpoint issue to few unconnected solutions…

Fortunately (since I already used that Virtual machine and since Windows XP mode does not require hardware-assisted virtualization support anymore) I could quite easily scratch one error cause and focus my attention only to host processor type mismatch.

My BIOS error got Virtual PC into thinking that restoration would not be wise move. Since I had no idea myself whether this would be good move or not, I decided just to delete hibernation files and reboot machine.

First I had to find configuration file. I had not need for one that ends in .wmcx since there is absolutely nothing of any significance there. I needed one that ends in .vmc and it is usually next to virtual disk (mine was at C:\Users\Josip\AppData\Local\Microsoft\Windows Virtual PC\Virtual Machines\Windows XP Mode.vmc). There is lot of data in it but I was interested only in section.

...
  <settings>
    <configuration>
      <next_id type="integer">1</next_id>
        <saved_state>
          <path>
            <absolute type="string">C:\Users\Josip\AppData\Local\Microsoft\Windows Virtual PC\Virtual Machines\Windows XP Mode.vsv</absolute>
            <relative type="string">.\Windows XP Mode.vsv</relative>
          </path>
        </saved_state>
      </configuration>
    ...
  </settings>
...

In this section there was data that defines where hibernation support files can be found. To make machine forget that it was hibernated, I only had to DELETE this section. Once that is done I could start machine once more.

P.S. This same recipe should be valid for any other hibernated Virtual PC machine.

What a Loop!

As I tried to install Ubuntu 10.04 inside of Windows Virtual PC, I kept getting message:

(initramfs)mount:mounting/dev/loop0 on //filesystem.squashfs failed: Input/output error
can not mount/dev/loop0 (/cdrom/casper/filesystem.squashfs) on//filesystem.squashfs

Since I knew that anything with *nix in it’s name will be a problem for Virtual PC, I tried every switch there is and result was either this message or machine would turn itself off.

It took me a while to notice that my ISO file was only 200 MB. Since Ubuntu CD should be almost 700 MB, culprit was found. It was simple case of corrupt CD.

It always amazes me how quick I am to search for deeper issues without checking simplest reason for failure first.

P.S. Great guide on installing Ubuntu can be found at Scott Hanselman’s blog.

Process Explorer in 64-Bit World

Illustration

Process Explorer is one of tools that get installed on any computer I get my hands on. One click on “Options”/“Replace Task Manager” and Ctrl+Esc shortcut becomes owned by it.

That is, it will replace task manager but only if you have 32-bit system. On 64-bit system it will seem to work until you exit it. As soon as you are out of program, system seems to forget that there is any task manager.

Using another great Sysinternals utility - Process Monitor - I found issue. Process Explorer hosts 64-bit version inside of it’s 32-bit process (procexp.exe). If it detects that it is running on 64-bit system it tries to unpacks procexp64.exe into current folder. If that folder is not writable, it extracts file to temporary folder and runs it from there. Process Explorer that you see is running from procexp64.exe.

When replacing task manager, it will point system to search for it’s currently executing copy. Unfortunately when you exit program it procexp.exe will delete that copy in attempt of cleaning after it self. Ctrl+Esc does not work since registry points to, freshly deleted, non-existing procexp64.exe file.

Solution that worked for me was to grant write rights to Process Explorer directory (to both Administrators and Users groups), start it and, while it is running, make copy of procexp64.exe. Once I secured copy of program, I went to “Options”/“Replace Task Manager”. All that is left to do then is exiting program (be sure it is not left in tray area).

Process Explorer will delete procexp64.exe upon exit. To overcome this I just rename program’s copy (made while Process Explorer was running) back to procexp64.exe. Now Ctrl+Esc can be used once more.

Slightly annoying aspect of this is fact that procexp.exe must not be started again to avoid triggering delete. You can solve this by deleting procexp.exe - procexp64.exe is all you need.

Slightly annoying fix, but it does work. And Process Explorer is easily worth all this trouble.

What Else I Didn't Notice?

I accidentally did click’n’drag on tray notification are in Windows 7. I was quite surprised when icon actually moved.

Yes, Windows 7 allows notification icons to be moved around. And to make it better all icons will stick to that place - no matter in which order you start applications that create them.

I wonder what else I don’t know about Windows 7… I should probably start reading manuals. :)

Connectify

Illustration

I was on business trip for few weeks and that meant that my home wireless network was missing my devices. More importantly, my devices were missing my network. Hotel did have wired Internet, but that solved only laptop connection. My phone was still Internet-less.

Fortunately, few months before that trip, I installed Connectify. It was small router program that requires Windows 7, it was in beta, I had no use for it - naturally I installed it and even updated it regularly. All that without even testing whether it works. Sometimes I surprise my self.

Program’s interface is quite simplistic. Almost every configurable setting is visible on main program screen. Mostly you just need to select password and which device has Internet to share and you are good-to-go. It is quite surprising that you can share your active wireless connection. Performance will go down a little (since your card will need to serve both as wireless client and wireless router) but it will work.

Security settings are limited to WPA2/PSK. No weak WEP but also no RADIUS authentication or anything more advanced. Since this would be probably overkill for most of uses, I cannot hold that against it.

What I miss the most here are statistics. You only get information which devices are connected and on which IP address. There is no information about their current resource spending. I was connected to Internet over 3G USB stick and I shared this connection with two friends. We had limited bandwidth and we were downloading way to much data. It was pain-in-the-ass to find which computer was “leaking” data.

As final conclusion I can only recommend this program. Once you set it up (not a big task to do) you can just forget about it. Prerequisites are not quite clear - Windows 7 and “better” wireless network card (although almost all newer Intel or Broadcom cards will do). But if it works once, it will work every time.

P.S. If you were wondering what black magic are they doing in order for this to work, you can check Virtual Router source code. It is open-source project based on same API functions that became available with rise of Windows 7.

Safely Remove Hardware

Illustration

I hate when new version of program removes one feature that I use, no matter how insignificant it may seem. Once you get used to something, it is always hard to let it go.

When you go to “Safely remove” your USB disk in Windows XP this will also close any Explorer window that has drive listed.

Then Windows Vista came. In Windows Vista you will get an error if any program is currently accessing drive that is being removed. This includes also simple viewing of content. I can understand reasoning - this was “proper” way to do things - no special behavior for any program.

It came to me as a surprise that Windows 7 brought “old” behavior back. It just feels much more humane when computer does obvious things for you. And it definitely shows problem with Windows Vista - lot of small annoying things.