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


Archive for the ‘Work’ Category

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..

Copying file permissions with robocopy

Tuesday, February 13th, 2007

I like using rsync to copy files between PCs, even on Windows. You get all the niceness of copying when the files are in use, and then only doing a small synchronization when they're not, to get a complete copy.Doesn't handle Windows file permissions well though.

Enter Robocopy (available in the Resource Kit). But I've already got the files?

robocopy source dest /s /copy:sou /is

Copies only security, owner and auditing information. Very handy.

MAPI error when sending e-mail from MYOB

Thursday, December 21st, 2006

"Cannot get the function address for MAPILogon from MAPI32.dll. Please check your MAPI installation."

Nothing on the web about this one (one other person with the same problem), but a simple fix. There is a 'fixmapi.exe' in your windows\system32 directory. Run that, and MYOB starts e-mailling fine again!

Microsysinternals releases Process Monitor

Friday, November 10th, 2006

Take Filemon and Regmon, combine them one program (apparently rewriting from scratch), and then change the license to make a previously invaluable sysadmin toolset potentially require payment. Thanks, Microsoft.

Periods in run-parts

Tuesday, October 31st, 2006

Repeat after me, Debian/Ubuntu sysadmins. You cannot use the period (.) character in /etc/foo.d directories. Can't can't can't.

Why? Well, man runparts says:

If the --lsbsysinit option is not given then the names must consist
entirely of upper and lower case letters, digits, underscores, and
hyphens.

So, you can't have files named "vhost.foo.co.nz" in your /etc/logrotate.d directory, and you can't have files named "awstats-foo.co.nz" in your /etc/cron.d directory.

As much of a big deal is made of Halloween, and as many groups of kids I saw walking the streets about 7:45, we only had one person knock on the door trick-or-treating. And we managed to successfully pretend we weren't here, sitting in the lounge watching Torchwood. (I keep waiting for the Doctor to turn up.)

Cheap server

Tuesday, October 31st, 2006

Note: this is long since sold.

IBM X335, $1 reserve.

Obviously, close friends need not enter.

Ubuntu Edgy released, foibles and all

Sunday, October 29th, 2006

I got a birthday present on Friday in the form of a new Ubuntu release, Edgy Eft. I downloaded the 6.10 ISO and promptly burned the 6.06 ISO to CD, only noticing when I got it home. Oh well, several hundred megs of downloads later...

Some notes:

  • Due to a change in Python packaging policy, python2.4-module packages are deprecated in favour of python-module packages that have an X-Python-Version field in their control file.
  • If you get a black screen & crash testing the beta NVIDIA driver, you probably need to edit /etc/modules and remove the eeprom driver. Found on the official NVIDIA Linux forum.

Beryl, the community Compiz fork, is, well, "a little over the top". After figuring out the settings to subdue it a little bit, I've got it usable. The settings dialog could do with a lot of love however, so anyone who is interested in UI and has free time (unfortunately I only currently hit one out of two) might like to volunteer to help.

I leave with a little laugh (courtesy of Jorge Bernal):

Bill Gates recommending Ubuntu

Exipick, and importing Apache certificates into IIS

Thursday, October 12th, 2006

Greig's cool find of the day:

Exim comes with a script called exipick, which lets you see just the parts of the mail queue that match a particular pattern. ie. we want to get notified of messages that are queued on a backup MX, but aren't just bounces to fake addresses that will eventually time out:

exipick '!$local_error_message'

Which makes looking at mail queues much easier:

root@elston:~# exipick | wc -l
96
root@elston:~# exipick '!$local_error_message' | wc -l
0

My find is a little less interesting, and a little more "just googled it", but if you have certificates in Apache crt/key format, and you want to import them into IIS, you can
do so with openssl:

/etc/ssl/site.net.nz# openssl pkcs12 -export -out site.p12 -inkey site.key -in site.crt

Read more at Michael's meanderings, including about the useful SSLDiag utility.

Windows utilities you didn't know about: dsacls.exe

Wednesday, October 11th, 2006

If you set permissions to lock yourself out of an object in Active Directory (or your co-worker does it for you - hi Pete!) then you can use the support tool ADSIEDIT to fix it.

Unless you've done something really difficult, like set DENY permission to "NT AUTHORITY\Authenticated Users".

The error was "An invalid directory name was passed" trying to change the properties on the object, which was also showing as a note, and not a container.

A suggestion to update the schema and clear the cache didn't work; what did work eventually, was this gem of a command line, suggested but not entirely correctly spelt out by knowledge base article 300444:

dsacls "CN=Default Global Address List,CN=All Global Address Lists,CN=Address Lists Container,CN=SITE NAME ,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=DOMAIN" /I:T /R "NT AUTHORITY\Authenticated Users"

And they say Windows isn't a CLI OS.

After using /R to remove the ACL, you can use /S to set it back to its inherited-from-parent ACL.