Win7 Library Tool

Posted in Software, Windows 7 on November 3rd, 2009 by Mr. Bungle – 310 Comments

Windows 7 libraries are a really useful feature of Windows 7, however unfortunately they arrive in a slighly cut-down form out of the box.  Microsoft decided against exposing some really useful capabilities to users, like adding network locations, pretty much the first thing I tried to do.  You get this message:

windows7libraryerror

Luckily, you can add network locations (and any other un-indexed locations), but it must be done programatically.  MS supply a command line utility slutil.exe, candidate for the worst named executable in history.  Pretty sure it stands for shell_library_util.  Anyway, I decided to write a tool to make it easy to add network locations, and added a few other features as well:

  • Add network (UNC or mapped drive) and any other un-indexed folders to libraries.
  • Backup library configuration, such that a saved set of libraries can be instantly restored at any point (like after a re-install of the OS or for transfer between multiple computers).
  • Create a mirror of all libraries (using symbolic links) in [SystemDrive]:\libraries.  This means you can reference all your files using a much shorter path, and also provides another entry-point to your files in many places in the Operating System (e.g. file open/save dialogs).
  • Change a library’s icon.

Hopefully it’s easy enough to use, so I don’t have to explain it :)

You can download it for free below.  (Note: This will only run on >= Windows 7.)

Download Installer | Source Code

I must give credit to Josh Smith for his TreeView CodeProject article, upon which this solution is modelled.

The application uses the Microsoft API CodePack to manipulate libraries, which I encourage you to check out if you are writing software to integrate / take advantage of new features in Windows 7.

If you want to learn why and how libraries were introduced in Windows 7, including diving into the .library-ms file format, you can read this MSDN article.

Now featured on Tekzilla!

Using TuneLink with Meridian on Android

Posted in Android, Bluetooth, Music on December 6th, 2011 by Mr. Bungle – Be the first to comment

I tried some of those cheap FM-transmitters to allow me to play music from my Android in my non-bluetooth enabled car stereo, and no suprises, you get what you pay for. The major problem was the fact that when you get into your car, you have to find your phone, connect it and hit play etc. TuneLink Auto automatically connects to your phone via bluetooth, wherever it is in the car, and then the TuneLink app on the phone starts the music player once connected. So there’s nothing for you to do, but just turn on your ignition and go. It works pretty well, but I had a problem where I didn’t want to use the standard music player on my phone anymore, instead I wanted to use Meridian due to its capability to browse folders (not all my music has ID3 tags that are accurate). In order to make TuneLink activate Meridian to play, it sends the Android headset command (AVRPC), and you have to enable a setting in Meridian to register for receipt of this command. Steps:

  1. Open Meridian
  2. Press Menu, then Preferences
  3. Go to Music and check the Headset Buttons option.

Now TuneLink will trigger Meridian to play automatically.

Magic command to install Asp.Net 4 for IIS 7.5

Posted in Networking, Programming on November 20th, 2011 by Mr. Bungle – Be the first to comment

After creating an ASP.NET web application in Visual Studio, to host it in a freshly installed IIS 7.5, you need to do two things that are not immediately obvious:

  1. Create a new app pool or change the default app pool to target .NET 4 (see IIS->Application Pools).
  2. Run this from the command line:
    %windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i

MSDN has more info on aspnet_regiis command line options here.
Just putting this on my blog so I can remember this magic command line.

On-screen performance monitoring for acceptance tests

Posted in Programming, Software, Testing on November 15th, 2011 by Mr. Bungle – Be the first to comment

If you record videos of your automated acceptance tests (we are using CamStudio), an excellent addition is to install the free Prism HUD utility. This will give you on-screen (but transparent to mouse actions) CPU / disk / network and memory statistics which can be very useful when reviewing these videos. It appears to be the only application that allows reporting of metrics of any process that exceeds a certain (configurable) delta, or is over a certain (configurable) threshold. This means you get much more useful information than just a summary metric (e.g. total CPU utilization), but you don’t clutter your screen with the metrics for all processes, just those ‘that matter’ at any point in time, automatically!!

Go get it here.

Random Programming Quote

Posted in Programming, Software on November 2nd, 2011 by Mr. Bungle – 2 Comments

I’ve hand-collected > 100 great programming quotes and stuffed them in a tiny console application, which, when run, will randomly print one to the console. Use it as a footer for your nightly build email, or anywhere you have some drabby generated document / email.

Also can be used if you are just bored on a Friday afternoon. ;)

Download it here.

Instantiating a custom view in Android

Posted in Android, Programming, User Interface on October 31st, 2011 by Mr. Bungle – Be the first to comment

Creating a custom view/control in Android is fairly simple – here are the steps I used:

  1. Create a new class which extends from the ‘View’ abstract base class. E.g.
    public class MyCustomControl extends View
  2. Provide constructor overloads for ALL of the following prototypes, where initView() is a method in which you perform initialization of things such as Paint objects:
    public MyCustomControl(Context context)
    	{
    		super(context);
    		initView();
    	}
    
    	public MyCustomControl(Context context, AttributeSet attrs)
    	{
    		super(context, attrs);
    		initView();
    	}
    
    	public MyCustomControl(Context context, AttributeSet attrs, int defStyle)
    	{
    		super(context, attrs, defStyle);
    		initView();
    	}
    
  3. Override onMeasure() in order to scale your control to the parent drawing area, such as shown in this good example.
  4. Do your canvas drawing operations in onDraw on the supplied Canvas object.
  5. Instantiate your custom view in a layout xml file (e.g. main.xml), for example:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    	<com.android.samples.MyCustomControl
    		android:id="@+id/myCustomControl"
        	android:layout_width="fill_parent"
        	android:layout_height="fill_parent"
        />
    </LinearLayout>

I found that if I didn’t add the 2nd and 3rd constructors, I got an exception when calling setContentView(R.layout.main) from onCreate() of the main Activity. You can instead construct an instance of the view manually in onCreate() of the main Activity, and then call setContentView(yourCustomViewInstance) if you don’t want to use XML layout.

Fastest way to delete a directory tree in Windows

Posted in Data Management, Programming on October 31st, 2011 by Mr. Bungle – 1 Comment

Our nightly build was taking > 30 minutes to delete our source tree before getting latest (Windows is not quick to delete a large number of small files), which was comparable to the time taken to actually compile the source. There are stackoverflow and superuser articles that discuss the fastest way to do deletes, however there’s no magic solution. If you find you are regularly needing to delete large amounts of files (e.g. as part of the nightly build process), your best option is to create a new partition on your HDD (or install a new HDD) and store all the files you will be deleting on there. Then you can erase them all in about 2 seconds by doing a quick format of the drive! The only trick is how to programatically format a drive, since there is no (documented) API for this in Windows. There’s Win32_Volume.Format (WMI) but it’s only available in server OSs, and then there’s SHFormatDrive, which shows a dialog.

However, provided your partition (in this case Z:) has no label, you can do this:

echo Y | format Z: /FS:NTFS /X /Q
An inferior alternative to this is to use a VBScript that uses SendKeys like this:

set WshShell = CreateObject("WScript.Shell")
wshShell.run "c:\windows\system32\format.com Z: /FS:NTFS /V:QuickWipeDrive /X /Q"
wscript.sleep 1000
wshshell.sendkeys "QuickWipeDrive" & "{ENTER}"
wscript.sleep 1000
wshshell.sendkeys "Y" & "{ENTER}"
wscript.sleep 5000

The downside of this script is that it will only work when the computer is not locked since SendKeys requires a console session that is logged in an active.

Bluetooth Service Connector

Posted in Bluetooth, Software, Windows 7 on October 20th, 2011 by Mr. Bungle – Be the first to comment

Bluetooth is still a relatively new technology when it comes to Windows. Although Windows 7 now has a reasonably decent bluetooth stack baked-in, it’s certainly not bug-free. It is not straightforward to control connection of bluetooth services, such as AudioSink, HeadSet, RemoteControl etc. And depending on how ‘dumb’ your bluetooth device is, your only option to get it connected to Windows in some cases (e.g. your device was last connected to a different host, such as your phone) is to completely uninstall and re-discover the device, as discussed on this thread. Weeeak.

I’ve written a small utility that may help with issue (it works for me, but I’ve only tested on my own bluetooth headphones – Sony DR-BT50). It works in conjunction with another utility I recently posted (that allows a program to set the default audio device), and provides control over connecting / disconnecting the available bluetooth services for all your paired bluetooth devices in Windows. It also provides a shortcut specifically for bluetooth audio devices which automates the process of getting a frustratingly silent pair of headphones / speaker to spring into life with a single click.

Download the utility here. I hope it works for you!

Setting default audio device in Windows

Posted in Programming, Software, Windows 7 on October 17th, 2011 by Mr. Bungle – 3 Comments

Since the audio revamp in Windows Vista, many things that were possible to do in code in the past (i.e. XP) are now difficult or impossible. One of those tasks that was easy in XP was setting the default audio device for playback. In XP this just required a registry change, but in Vista & Windows 7, Microsoft decided that developers should not have access to change the default audio device, so they locked down the registry and provided no documented API to achieve this. Their reasoning was that if two programs both wanted to set the default audio device, they would end up fighting each other for it, which of course is bad. But I believe this is a very short-sighted decision, since there are plenty of legitimate cases where a program needs to do this. These are discussed on this amazingly long-living thread (started in 2006 and still going).

The end result is that, no thanks to Microsoft, we finally have a way to do this, and I’ve created a console application in case others would like to control this as well:

Usage: SetDefaultAudioDevice.exe [deviceID] [role]
Where:
[deviceID] is a GUID including braces
[role] is either ‘console’, ‘multimedia’ or ‘communications’.

Example: SetDefaultAudioDevice {24dfc80a-680f-4748-8627-c340cb14f187} multimedia

Your audio device IDs can be found in the registry under HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render.

Feel free to download this utility here, source code is in my SVN repo.

Thank-you to EreTIk and Jonny Best and everyone else on the above forum post!

Upgrading your Android SD card

Posted in Android on September 30th, 2011 by Mr. Bungle – Be the first to comment

Short version:

To move data between SD cards in your Android phone, just copy it to a computer (with the phone plugged in – via enabling USB mass storage mode from the phone), power down the phone, insert new SD card, boot up, and copy data from computer back to new SD card in the phone. Easy.

Detailed version:

My Android (LG Optimus One) came with a 2Gb micro SD card, which did the job for about 6 months. Now I use my phone for listening to music in the car and elsewhere, and the apps I installed started to consume space as well, so I needed upgrade the SD card to something bigger. The biggest the most phones support right now is 32Gb, so I bought a Lexar 32 Gb micro SD card (class 10) for $AU100 (retail). I was a little concerned about the exact procedure to move the data from the 2Gb to the 32Gb card, but it turns out it was really simple (assuming you have not partitioned your SD card):

1. Connect phone to PC via USB (with old SD card install still inserted), and copy everything off the SD card into a folder on your HDD. I got a few errors trying to copy some ThinkFree Office files, probably due to the path length being too long, so I just skipped those files (they didn’t look too important anyway).

2. Power off phone, insert new SD card, boot up phone.

3. Connect phone to PC via USB, copy everything from the folder in step 1 to phone’s SD card, and disconnect USB.

That’s it.

Unknown Build Error RG1000

Posted in Programming, Software on June 29th, 2011 by Mr. Bungle – Be the first to comment

After manually merging a set of source changes to a .csproj file, my project would no longer build, giving this error:

Common.targets(588,5): error RG1000: Unknown build error, ‘An item with the same key has already been added.’

Not particularly helpful, especially if there are a large number of changes in the .csproj file. To get more information in such a case, in VS2010 you can go to Tools->Options->Projects and Solutions->Build and Run and set the MSBuild output verbosity to ‘Diagnostic’. After attempting to build again, the error now becomes much more useful:

Error 2 The item “Views\FeedbackView.xaml.cs” was specified more than once in the “Sources” parameter. Duplicate items are not supported by the “Sources” parameter. C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.CSharp.targets 160 9 MyCompany.MyProduct.WebClient

Interestingly, after I reset the verbosity level back to Minimal (without making any code changes), the more detailed error still appeared. Weird.