Error when opening Word documents

OS: Windows 7 64-bit
Office: 2010 Premium

When double-clicking a .doc/x file in Windows Explorer, or launching it via a different explorer, such as FreeCommander, you may see this error message:

Many, many people have seen this issue. I tried several solution, including deleting the word Data key, as recommended by Microsoft, checking that ‘Run this program as an administrator’ is not checked and renaming normal.dotm, but all failed to fix the error. Finally, here’s what fixed it for me:

  1. Right-click a .doc/x file -> Open With -> Choose program
  2. Select Word 2007 and hit OK.

After doing that, I could open word documents from outside word successfully.

Interop.ComAdmin exception when using IIS on a 64-bit OS

If you install IIS on a 64-bit operating system, you may get the following error when navigating to your website locally:

Could not load file or assembly ‘Interop.COMAdmin’ or one of its dependencies. An attempt was made to load a program with an incorrect format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.BadImageFormatException: Could not load file or assembly ‘Interop.COMAdmin’ or one of its dependencies. An attempt was made to load a program with an incorrect format.

The clue here is the BadImageFormatException, which hints that this is a 32/64 bit issue. To fix it, in IIS Services Manager, go to Application Pools, select the application pool under which your website/application is running, and choose ‘Advanced Settings’. Change ‘Enable 32-bit Applications’ from False (the default) to True. Recycle your app pool, and reload your browser page, no more error!

PicasaPhotoViewer.exe staying in memory

Google’s Picasa Photo Viewer is one of the best photo preview applications, it loads quickly, and is easy to exit. Unfortunately, Google introduced a bug recently that causes the PicasaPhotoViewer.exe process to remain in memory even after you close the application. Several posts on google forums and elsewhere have reported this:

Why does PicasaPhotoViewer.exe stay resident in memory
Multiple picasaphotoviewer.exe ghosts in Task Manager
Memory Loss from orphaned PhotoViewer Processes
PicasaPhotoViewer Process Doesn’t Terminate

This appears to only occur when you open a photo on a network location, such as a network drive. This is a pretty normal usage scenario, such as storage of photos on a RAID server or NAS, and is actually pretty nasty, because it means you can’t rename/delete/move any directory in which you viewed an image including any parent directory (due to the still-running PicasaPhotoViewer.exe locking the directory). It doesn’t take long for this to get seriously annoying when you find yourself having to open Process Explorer/Task Manager to kill off all the orphaned PicasaPhotoViewer.exe processes when you are working with directories.

Orphaned PicasaPhotoViewer.exe processes.

Until Google fixes this, I solved this with a small C# application. It monitors for orphaned instances of PicasaPhotoViewer.exe (i.e. those that are running but have no window) and kills them. This is the complete code:

static void Main(string[] args)
{
   while (true)
   {
      var picasaProcesses =
         (from p in Process.GetProcessesByName("PicasaPhotoViewer")
          where p.MainWindowHandle == IntPtr.Zero && !p.HasExited
          select p);

      foreach (var process in picasaProcesses)
      {
         process.WaitForInputIdle();
         if (process.MainWindowHandle == IntPtr.Zero)
         {
            process.Kill();
            process.WaitForExit();
         }
      }

      Thread.Sleep(1000);
   }
}

Feel free to download the utility, and launch it on Windows startup using a logon script such as described here. Note: The program requires admin rights to run, so you can’t just place a shortcut to it in your ‘Startup’ folder if you are using Vista/7 with UAC switched on.

Update: Ok, it appears this issue has been fixed by Google in Picasa build > 117.38. Updating to the latest version (build 117.43 at the time of writing) fixed the issue for me, so my program should no longer be needed 🙂

Update 2: According to the comment below, the issue may still be occurring for some people. So I have made the program to fix this available for download again.

A2DP on Windows 7

When I bought a pair of bluetooth stereo headphones, I wanted to make sure they would work on Windows 7, however when I searched for A2DP (Advanced Audio Distribution Profile – the protocol for streaming stereo audio to a bluetooth device), I mostly found posts relating to how A2DP support was missing from Windows 7 RTM.

So when I bought a bluetooth dongle, I went ahead and immediately installed the ancient version of BlueSoleil that came with it. This is an awful piece of software, but it does get your headphones working. However, I started getting random blue-screens which identified BlueSoleil as the culprit. So I investigated my options:

– Install the latest version of BlueSoleil, and provided no further blue-screens occur within the trial period, buy it 🙁
– Install the Toshiba bluetooth stack, and buy if it does the job.
– Remove all 3rd party bluetooth software and try the Microsoft one.

I tried the toshiba bluetooth stack and the audio randomly cut out every few 1 or 2 seconds. So don’t bother with that.
Not wanting to pay for crap software, and spurred on by seeing mention that an update for A2DP support in Windows 7 was pushed out, I decided to give the Microsoft stack a go. Uninstalled Toshiba and Bluesoleil software, then after re-enabling the ‘Bluetooth Support Service’, my headphones were promptly discovered and connected. Audio quality is perfect (no drop-outs), and no need for any 3rd party software.

So, if you’re using Windows 7, don’t bother with BlueSoleil or Toshiba, stick with the Microsoft bluetooth stack.

‘Bluetooth Settings’ link missing in Windows 7 Control Panel

When attempting to add (pair) a new bluetooth device, if no devices are detected it may be that the ‘Bluetooth Support Service‘ is disabled or stopped. Check this by going to:

Start->Run->compmgmt.msc->Services and Applications->Services

Make sure the status for service ‘Bluetooth Support Service’ is ‘Started’ and the startup type is ‘Automatic’. After starting this service, you should now be able to add bluetooth devices to Windows. Starting this service also enables display of the bluetooth settings dialog, which the Windows help points out should be visible in the Control Panel when you search for ‘bluetooth’. Another symptom that this service is not running is that when you right-click the bluetooth system tray icon and choose ‘settings’, nothing happens (i.e. no dialog appears).

To Microsoft: Surely it would have been simple to check whether this service is running before doing bluetooth device discovery or opening the settings dialog, and at least report to the user that they need to start the service (or do it for them ideally) rather than just failing silently.

Muting Bluetooth Headphones

After much research, I recently purchased a pair of Sony BT-50 Bluetooth headphones. They are AWESOME!!!! The only problem is, there’s no way to mute them! In fact, there’s no way to mute any bluetooth headphones except from the ‘mute’ button on the bluetooth device. If you’re listening to music on a PC, volume up/down keys work (from a multimedia keyboard), but not mute. So I’ve written a utility that enables muting of your headphones with a global hotkey, and you can download it for free here.

Note: The program will only work on Windows 7, and you’ll need .Net 4 installed. So you know you’re on the bleeding edge of technology using this. Who knew a feature such as mute was so high-tech 😀

The program uses the CoreAudioAPI library by Ray Molenkamp, and the global hotkey class by Max Bolingbroke. They made this possible.

Btw, the BT-50 headphones don’t come with a USB Bluetooth adaptor, so if you want to use with with a PC (as opposed to a bluetooth-enabled phone), you’ll need to purchase one. I’d advise against going with the $1.00 bluetooth adaptors from China (even with free shipping, wtf?), and instead do your research and find an adaptor that has drivers for Windows 7 and A2DP support.

For Aussies, I can confirm that the Dick Smith Bluetooth 100M USB adapter (not listed on the Dick Smith website, but I found them in the Macquarie park store in Sydney) will work with these headphones, after you wrestle a bit with BlueSoliel (worst usability in software I’ve seen in a while – see below for how to automate connection of the Advanced Audio Service). And you’ll need to swap out the American power supply with an Aussie one – again Dick Smith has the goods. Just make sure the polarity is right: The engraving “CEN” on the jack with the yellow tip should be on the positive side of the connector.

Update: To avoid using BlueSoliel every time you switch on your headphones, you can save the connection as a shortcut. It is placed on your desktop without telling you:

Display file diffs in the foreground

A great shortcut for viewing pending changes in Visual Studio is to hold SHIFT and then double-click the file in the Pending Changes window.  Unfortunately most of the time, the resulting diff program’s window (assuming you are using an external diff program) is shown behind the Visual Studio window, requiring you to click it’s icon in the taskbar in order to bring it to the foreground.  This happens about 3 in 4 times, and totally negates the speedup of SHIFT double-clicking. It also happens when using beyond compare with git’s difftool command.

So I have written a small utility to solve this, called ActivateDiff, which you can download from here.

Usage for Git (git difftool command)

Use the following in your global gitconfig file:

[diff]
guitool = beyondcompare3
tool = ad
[difftool "ad"]
path = c:/pathto/activatediff.exe
cmd = \"c:/pathto/activatediff.exe\" \"c:/Program Files (x86)/Beyond Compare 3/bcomp.com\" \"$LOCAL\" \"$REMOTE\"

Usage for Visual Studio:

  1. Open Visual Studio->Tools->Options->Source Control->Visual Studio Team Foundation Server->Configure User Tools.
  2. Copy the operation’s command, paste it at start of the arguments field and enclose it in double quotes.
  3. Change the operation’s command to point to ActivateDiff.exe.
  4. Ok-on-out.

Happy diffing!

Starting programs with administrator rights at login

With the introduction of UAC in Vista, launching a program that requires administrative rights on Windows startup (when you first log in) has become more difficult. One solution that has been doing the rounds is to use the Task Scheduler as a workaround. What a mess! Provided you are not running a 'home' edition of Windows Vista/7, I have found what I believe is the cleanest and easiest way to achieve this (for all users only):

1. Start->Run-> "gpedit.msc"

2. User Configuration->Windows Settings->Scripts (Logon/Logoff)

3. Double-click 'Logon', and add entries for each of the applications you want launched.

Group Policy Logon

The applications you define in here will be launched with administrator rights when anyone logs on without any UAC dialogs being displayed.  

Note: This method cannot be used for specific users, it applies to all users. 

FreeCommander + SuperCopier2

As fun as file systems are, you really don’t want to be spending longer than you have to when it comes to copying / moving / viewing files and navigating folders. I was saved years of grief fumbling about with Windows Explorer thanks to a mate’s advice to switch to TotalCommander back in 2003 (I still remember his look of horror when when I said ‘Total-what?’). When it comes to speed and efficiently, the keyboard is king, and TotalCommander and all the other *commander variants take advantage of that.

Last year I switched to FreeCommander, and am very happy. The main benefits for me are:

  • a more modern / nicer UI
  • ‘type to navigate’
  • plenty of customisation options
  • it’s free 🙂

Unfortunately there are some serious drawbacks:

  • The file-copy/move dialog is the Windows built-in one (which is down-right horrible)
  • The file-delete dialog is the Windows built-in one, and it’s modal to the application
  • The FTP client has a terrible time-out issue and is generally buggy

I’d like to solve all three of these, but I’m starting with the first.

Luckily, FreeCommander allows you to use an external copy/move program via an INI setting. I tried the free TeraCopy for a while, but when I discovered SuperCopier 2, it was perfect! It really is lightning quick at what it does, it doesn’t get in your way, and has all the options you need (pause, error handling etc.). The only problem is, as of v2.2, the copy interception code was re-written, and it could no longer be fully integrated with FreeCommander. To solve this problem, I have written a small executable in C++ called SC2Integration.exe that uses the API provided by SuperCopier 2 (available on their sourceforge site) to re-unite FreeCommander with this excellent file-copy replacement.

Simply drop SC2Integration.exe into your FreeCommander installation folder (or anywhere else you would like to store it) and add the following two lines under the [Form] section of your FreeCommander.ini file:


FileCopyPrg=%FcSrcPath%\SC2Integration.exe Copy "%ActivSelAsFile%" "%InactivDir%"
FileMovePrg=%FcSrcPath%\SC2Integration.exe Move "%ActivSelAsFile%" "%InactivDir%"

If you didn’t copy SC2Integration.exe into your FreeCommander installation directory, replace %FcSrcPath% with the full correct path (no quotes). On Windows 7 your FreeCommander.ini file is here by default:

C:\Users\username\AppData\Roaming\FreeCommander\FreeCommander.ini

Download the SC2Integration utility for free here.

UPDATE: If you get an error ‘Parsing arguments…’, make sure you add double quotes around %ActivSelAsFile% and %InactivDir% in your FreeCommander.ini.

Windows 7 disconnected network drives

Mapped network drives have always been a buggy area in Windows, probably at least in part because they are still linked to a DOS namespace. From MSDN:

On Windows Server 2003 and Windows XP, the WNet functions create and delete network drive letters in the MS-DOS device namespace associated with a logon session…

Whatever the reason, it is commonly reported that mapped network drives appear as ‘disconnected’ in Windows Explorer (or ‘unavailable’ via net use), and that programs that attempt to use these drive mappings will fail until the user physically clicks on the drive letter in Windows Explorer. Only this user-initiated action will restore the connection and allow other programs to successfully read from the drive letter.

The dreaded disconnected network drive balloon.

This is a BIG problem!

I initially thought that the mapping of the network drives was being done before some required services had started (such as the Workstation and Server services), so I wrote a program to run on startup that attempted to map a drive and logged all the currently running services if it failed. It would keep trying to map a drive until it succeeded. I hoped it would show me which services needed to be running in order to map a drive, after which I would write a program to wait for those services before attempting to map anything. But, much to my amazement, I found that when the initial drive mapping failed and a subsequent attempt succeeded, the set of running services had not changed! So I could only conclude that there was another element in the equation. After thinking about this for a while, and reading this post, which indicates that Microsoft is apparently trying to address this, I decided ‘stuff it’, I’ll just write something that I know will work and is simple.

So I’ve written a small executable called MapDrive.exe to ‘work around’ this problem, described on the following dialog:

About MapDrive

Now as you may know since Vista, there is the concept of a split user token, and mapped network drives apply to only one token, so if you map drives as a standard user and then run an elevated process, those network drives are not available to the elevated process. This behaviour is documented by Microsoft, however the solution they offer is both unsupported and unsafe. Other solutions have been proposed here. If you don’t wish to use any of these solutions, you can do this:

1. Run MapDrive.exe as a shortcut from your Startup folder. This will map drives for the standard user token.
2. Run MapDrive.exe as a local group policy logon script using gpedit.msc. This will map drives for the administrator token.

Note: After using this program, you may still see the above balloon popup, simply click the spanner icon, and select ‘Hide icon and notifications’ for ‘Windows Explorer’.

Download the utility for free here.

UPDATE: A few people have asked how to use this program. As stated above, there are two ways, depending on whether you need drives mapped for standard users or admins. If you don’t know what you need, you probably just need to do this for standard users. Here are the steps for both:

1. Copy MapDrive.exe to somewhere on your local hard drive.

Standard Users:
2. Right-click MapDrive.exe and choose ‘Create Shortcut’. This will create a file called ‘MapDrive.exe – Shortcut’ next to MapDrive.exe. Now go Start->All Programs, right-click the ‘Startup’ folder and choose ‘Open’. Now copy the shortcut file you made before to this folder. Now right-click the shortcut file and choose ‘Properties’. Add the drive letter and network share as argument to the end of the ‘Target’ field e.g. “C:\Users\joeblogs\Documents\MapDrive.exe s: \\server\share 20”. You are done, next time you reboot, your s: should be mapped successfully for standard users.

Admin Users:
3. Press Win+R, type gpedit.msc, go User Configuration->Windows Settings->Scripts. Double-click Logon, click ‘Add’ and enter script name (no quotes): “C:\Users\joeblogs\Documents\MapDrive.exe” and script parameters (no quotes): “s: \\server\share 20”, ok, ok, done. You are done, next time you reboot, your s: should be mapped successfully for admin users (i.e. elevated programs).