Craig Box's journeys, stories and notes...


Archive for March, 2007

Targeting .NET 1.1 harder than it seems

Wednesday, March 21st, 2007

I'd like my application to be able to run on .NET 1.1, so I've avoided using all the new niceties of .NET 2.0.

Or so I thought.

First, I experimented with MSBee, which lets you build for the .NET 1.1 environment using the VS 2005 tools. After seeing how many errors my code generated in 1.1, while it compiled cleanly in 2.0, I thought "maybe reimplementing this in VS 2003 might be easier".
And while I've specifically avoided some of the .NET 2.0 things that would have been really handy, like the SecurityIdentifier class, which makes handling SID-account mapping easy, there's things I didn't know would be a problem. You can't set a registry key to be a certain type in 1.1. And you can't use half the features that the designer implements for you automatically. And even if you could, you'd have to hack at it, because they separate code and design with partial classes in 2.0.

So, to summarize, looks like .NET was pretty crap prior to 2005. And that means you need to have XP SP2, because it's not supported on SP1.

(/rant)

Searching and replacing attached templates in Word documents

Monday, March 19th, 2007

If you have a document take 5-15 seconds at "Requesting virus scan..." in Microsoft Word, you will think "Pesky virus scanner!". But while this fault is most commonly Norton AntiVirus, it can also manifest in another circumstance: where you have a document with an attached template on a share you can't access any more.

If you are a Windows tech, you have no excuse for not knowing about Sysinternal's Filemon - when you know exactly what an application is accessing, it lets you solve a multitude of problems, including this one. We have a customer with an application that generates Word files based on a template, in the same location as the program is being run from. Long before our involvement they appear to have had a server named "Server" (imaginitive naming) and ran the program from \\Server\Share. There is no Server any more, so the documents from that period all cause a timeout trying to find a share that doesn't exist.
Thankfully, when their current server was installed, a drive mapping was created, so all the documents from that point on are attached to a template on G:\. Therefore the task becomes to search-and-replace the template on all the old Word documents.

There is no easier way to do this than using Word's VBA, which is unfortunate, as you have to script a load of each document, which means each one takes 5-15 seconds to process. There are third party utilities I've seen that handle Word automation, but you may as well just run a macro, which appears in its full splendour below the fold.

I'd be interested to know if there was a library that let you edit Word documents, so we could do this by another method.

Net result however, documents now open speedy, and customer is happy.

(more…)

RegUnloadKey failing with error 5 (Access denied)

Sunday, March 18th, 2007

Trying to unload a registry hive and finding access is denied?

I was loading in a user hive (NTUSER.DAT in the profile), and then opening the key using RegOpenKey (exposed as Registry.Users.OpenSubKey in .NET) to prove it was successful. However, I'd forgot to close this key, so the handle was staying open and thus you couldn't unload the hive.

Oddly, after some time, the handle would clean itself up, so it seemed more like a time or permissions based issue. Simple fix however.

A working release of ProfileTool isn't far away..

Planet NZTech

Wednesday, March 7th, 2007

Planet NZTech has received a facelift recently. As well as a new design, seems that the behind-the-scenes stuff has all been fixed, including the last of the unicode problems (I hope Follower wasn't calling me uncultured. I'll get him back by pointing out that his post was syndicated from his blog to Advogato, and from Advogato to the Planet, so appeared twice in a row!)

Other than the layout, the biggest change is the de-emphasising of who wrote what. It's an interesting concept, probably based around the idea of a magazine that has a single focus, and multiple people writing to that focus. In this case, I think people write for their own purposes (I still don't know what mine is, so I should stop doing it) and it's a bit confusing having everything anonymised. Plus, you don't get to have cool heads. But it's not wrong, it's different.

Free Ubuntu stickers for NZers

Wednesday, March 7th, 2007

Powered by UbuntuThe fine folks at System76, who sell Ubuntu pre-installed on laptops, desktops and servers, have sent me a stash of "Powered by Ubuntu Linux" stickers, perfect for telling the world that even though your laptop, desktop or server might be Designed for Windows Vista, it's powered by the penguin.

To receive four stickers, send a self addressed, stamped envelope, to

Ubuntu Stickers
c/o Ian Beardslee
Catalyst IT
Level 2, Eagle Tech House
150 Willis St
Wellington

(Persons reading this outside NZ are encouraged to check out System76's sticker distributors page)

Update: thank you for all the letters that came in requesting stickers...

Ubuntu sticker request letters (small pic)