This is something I wrote a while back, thought I’d post it here. It does exactly what the title says. Its basically a port of the following: http://msdn.microsoft.com/en-us/library/aa364695(VS.85).aspx