If you are getting errors like “Plugin blah or one of its dependencies could not be resolved” you may find this useful.

There is an issue with Maven 3.0.3 (and I assume earlier) in that plug-in repositories need to be separately configured from the normal repository. The maven settings file must contain something like this:


With 3.0.4, maven will pick up the plugin repository information from the repositories configuration.


Reg Edit – take ownership – create explorer meny

Found these reg settings that are very useful and didn't know where to put them for future reference.  So here they are.

Windows Registry Editor Version 5.00

@="Take Ownership"

@="cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F"
"IsolatedCommand"="cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F"

@="Take Ownership"

@="cmd.exe /c takeown /f \"%1\" /r /d y && icacls \"%1\" /grant administrators:F /t"
"IsolatedCommand"="cmd.exe /c takeown /f \"%1\" /r /d y && icacls \"%1\" /grant administrators:F /t"

WPF Screen Resolution in Pixels

I needed my WPF controls size in pixels to retrieve the correct sized image from a web service.  The answer hit me one night and it’s very simple:

Create a known size image (say 100 x 100 pixels), put it in a image control on some bit of WPF screen (Hidden not collapsed), ensure no stretching by putting Stretch=None and a non-stretch value for both Horizontal and Vertical alignment and make the calculation from the Image controls actual width and height.

This bit of xaml shows what I did:

    <Image x:Name="A100x100ImageControl" 
    Source="/images/100x100.jpg" Stretch="None" 
        HorizontalAlignment="Left" VerticalAlignment="Top" 
    <Image x:Name="ImageControl" Stretch="Uniform"/>

A calculation with look something like this:

(In my case I wrapped it up in a UserControl with SizeTarget, a bound property, being a specific interface with just width and height that can be implemented elsewhere.)

SizeTarget.PixelWidth = (int)Math.Truncate(ActualWidth * 100 / 

Getting listening ports and addresses programmatically

My problem: A program was using (an alias for to make a local connection on a specific port. However, one Windows 2003 server box was configured so that this port was being listened to on a specific network adapter (and hence a specific IP address). Hence, my local connection failed even though the port was open for listening.

Background: Type “netstat -p tcp -a -n” at the command prompt to get details of listening ports. The “Local Address” is adapter specific; “” means it’s listening on all adapters (thus allowing connections to In the case of this 2003 box, the port I wanted was specific to a particular IP address (adapter).

So, my program needed to connect to the adapter specific IP address and not This is how to get the IP addresses and ports they’re listening on:

void DoItAgain()
   DWORD err;
   DWORD size = 0;
   // first get the size of the buffer required
   if((err=GetTcpTable (0,&size,FALSE))!=ERROR_INSUFFICIENT_BUFFER)
      std::cerr << "Error " << err <<
         " getting tcp table size." << std::endl;
   // next get the table
   std::vector buf(size);
   MIB_TCPTABLE *tbl = reinterpret_cast(&(*buf.begin()));
      std::cerr << "Error " << err <<
         " getting tcp table." << std::endl;
   // iterate through the entries
   for (DWORD dw = 0; dw < tbl->dwNumEntries; ++dw)
      if(tbl->table[dw].dwState == MIB_TCP_STATE_LISTEN)
         in_addr ad;
         ad.S_un.S_addr = tbl->table[dw].dwLocalAddr;
         std::cout << "Listening " << inet_ntoa(ad) <<
            ", port " << ntohs(tbl->table[dw].dwLocalPort) << std::endl;

System.Drawing.Icon and embedded rersources

To use an icon resource embedded into your assemply: 

1) Add icon to project and make it an “Embedded Resource” type (no need to copy to output directory).

2) Construct your System.Drawing.Icon like this:

new Icon(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("MyShinyApp.hammer.ico"));

Where MyShinyApp is the value specified in “Default namespace” property of your project (Application tab of project properties) and hammer.ico is the name of your icon.

Minimize to tray icon in WPF

I had to do a bit of searching so, here’s how to minimize your WPF app to a tray icon.  Assume your window is called Window1 for the code below.  Trap Closing, StateChanged and IsVisibleChanged (see xaml). 


<window x:Class="MyApp.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  Title="WCFAppVisualHost" Height="383" Width="680" Closing="OnClose" StateChanged="OnStateChanged" IsVisibleChanged="OnIsVisibleChanged"

Associated cs:

private System.Windows.Forms.NotifyIcon m_notifyIcon;

public Window1()
    // initialise code here
    m_notifyIcon = new System.Windows.Forms.NotifyIcon();
    m_notifyIcon.BalloonTipText = "The app has been minimised. Click the tray icon to show.";
    m_notifyIcon.BalloonTipTitle = "The App";
    m_notifyIcon.Text = "The App";
    m_notifyIcon.Icon = new System.Drawing.Icon("TheAppIcon.ico");
    m_notifyIcon.Click += new EventHandler(m_notifyIcon_Click);

void OnClose(object sender, CancelEventArgs args)
    m_notifyIcon = null;

private WindowState m_storedWindowState = WindowState.Normal;
void OnStateChanged(object sender, EventArgs args)
    if (WindowState == WindowState.Minimized)
        if(m_notifyIcon != null)
        m_storedWindowState = WindowState;
void OnIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs args)

void m_notifyIcon_Click(object sender, EventArgs e)
    WindowState = m_storedWindowState;
void CheckTrayIcon()

void ShowTrayIcon(bool show)
    if (m_notifyIcon != null)
        m_notifyIcon.Visible = show;

“Loss of information”

I’ve always wondered (and again two days ago) what “irreversible loss of information” is being referd to when you reset a local user password from the “Computer Management” console.  Independantly, I’ve been tracking down a bug reported by one PMG Connect user in which the connection routine fails.

These things are linked.  The bug was a call to cryptography API CryptAquireContext failing with error NTE_BAD_KEY_STATE.  (Ok, I admit, if the software was reporting faults better, this could have been determined ages ago.)  In short, it was attempting to open a key container that existed but couldn’t be used because the user had reset the password.  Checkin the web, this occurs with a lot of software (one suggested work-around was to create a new user account!).

So, that’s some of what loss of information occurs.  To fix this problem, the software attempts to open key containers with different names when that error is encounted.