SyncToy 2.1 and Windows 7/64

So what gives with SyncToy 2.1 on Windows 7 64-bit? Last night I manually closed Outlook, then after it had exited cleanly I executed my folder sync. As mentioned previously (here, and here, and here) the sync command runs all my “active for sync” folder pairs in SyncToy 2.1, of which there are two. The first backs up c:\users\myname, and the second backs up the singly-rooted folder hierarchy in which I have stored all my stuff since 1987 or so.

I run this before I head upstairs for the night. Twice now I have come down the next morning and found Outlook sitting there with the message “The default storage file cannot be opened,” or something very similar to that. Also, and I had initially disregarded this as coincidence, when Sidebar restarted it only displayed one of three gadgets, and none of it’s windows would activate off of the desktop context menu. In both cases restarting solved the problems, but Outlook complained on restart that the PST file needed to be scanned.

The last point of interest: I keep my Outlook .PST file in that singly-rooted folder structure I mentioned above, not in the default location. Not sure what’s going on here, but I am beginning to think this one is SyncToy’s issue, not Outlook’s.

Redirection: It’s a Shell Game

I got caught in a silly little trap this morning, and it cost me an hour or so of debugging time. Usually I enjoy debugging, when the error I am chasing is legit, meaning a reasonably good programmer could have caused it. But then there are those times when I just screw myself by being stupid, and that’s irritating. The bug in question shouldn’t have taken an hour to fix, but unfortunately the only way to debug this particular program is build-commit-push-run-read log. You get the picture.

Anyway, I was using Process.Start() to spawn a console application from within a job running on a service framework. I wanted to redirect the output of the console application to a log file. You can also redirect console output back to a stream in the spawning code, which is slick, but in this case there is a lot of output, and a log is really the best place for it. From the command line the operation might look like this:

c:\myapp.exe -A arg1 -B arg2 -C arg3 > c:\somedir\myapp.log

Pretty straightforward, and it works great. Having tested this on the command line I translated it into the C# code for our app, and it looked something like this:

Process.Start(“myapp.exe”, “-A arg1 -B arg2 -C arg3 > c:\somedir\myapp.log”);

The first parameter is the executable name, the second is the arguments. When I executed this code the errorlevel indicated myapp.exe didn’t understand the arguments it was passed. What? They’re the same arguments I just passed you on the command line, and they worked fine! Copy the text to the command line. Run it. Yep, it works fine.

But not when spawned using Process.Start(). You smart people probably already see what I did wrong. The problem is that standard output redirection using the > operator is not something myapp.exe knows how to do. It’s something cmd.exe knows how to do. When I ran the program from a command prompt I was running it within an instance of cmd.exe. But when I spawned it using the code above there was no instance of cmd.exe running, and so the redirection operator was just another argument passed to myapp.exe. The correct method is:

Process.Start(“cmd.exe”, “/c myapp.exe -A arg1 -B arg2 -C arg3 > c:\somedir\myapp.log”);

Sometimes, I are not that bright.

The Last Word on Healthcare

My last word, that is. When I set this site up I vowed to myself to focus on the historical, the technical, occasionally the literary, and stay the hell away from the political. But alas it seems strange, here on the eve of perhaps the greatest change in our government since Johnson’s Great Society, to say nothing at all. So here are two coins with very little copper in them, on the subject of healthcare.

First, healthcare is no different than shoes and shingles. If I want a pair of shoes, or I need shingles for my roof, I have to find people who make shoes or shingles, pay them the costs of their labors plus some profit, and carry away my goods. I don’t have a right to shoes and shingles if I don’t have the money to pay for them. Same thing with food and fuel, both of which, by the way, cost me a lot more on a yearly basis than health care. If you think healthcare represents some special category of stuff, more important than food, fuel, shoes, and shingles, then I think the burden is on you to explain that position.

Second, it disturbs me when I hear healthcare described as a right. Healthcare isn’t like life, liberty, and the pursuit of happiness. None of those things are tangible goods. Healthcare is provided by people who invest huge amounts of time and labor into it. Doctors invest eight to ten years of schooling, nurses two to six. Pharma companies invest billions in the creation of new drugs, health management companies billions into the building and maintenance of hospitals. And the problem, the main problem at any rate, is that we don’t want to pay for the results of their labors. We want someone else to pay.

Specifically we want insurance, apparently some sort of magical artifact that allows the wearer to consume, on demand, thousands of dollars worth of expensive, specialized goods and services, while paying little or nothing in return. And because we would feel bad if we were the only ones who possessed the enchanted item, we want everyone to have one just like ours. Then we can all consume as much as we wish. Tragedy of the Commons, anyone?

Third, if you don’t want to pay for something, and you succeed in convincing someone else to pay for it on your behalf, you lose the power of the purse in that relationship. One of the reasons people are so upset with healthcare, apparently, is that employers and insurance companies have too much say in the kind of treatment patients receive. They have a lot of say, because they’re writing the checks. Shocking, I know. Personally I don’t care if you prefer to have your employer pay, or the government, or some insurance company. The only thing that matters to me is that you don’t want it coming out of your pocket.

If you succeed in that, then in the end you’re going to get what you pay for. Costs will continue to rise, but even faster, because demand will have been expanded without addressing supply. Supply will stagnate or decrease, because the incentives to succeed will be bled out of the system. The payers will have even more power, and even more incentive to regulate access and pricing. All of that is already happening, not because we have single-payer government-provided insurance, but simply because we want our employers and insurance companies to pay our bills.

So, fourth and finally, you’re dreaming. Healthcare is a tangible and limited resource. If you think the government can somehow step in, manage the whole mess, and that suddenly you’ll be paying less, getting more, and be more in control over what you spend and get, then all I can say is that I hope you aren’t in a position of any serious responsibility. Of course, lots of people who do believe that are in such positions, so God help us all.

More Outlook

So last night, the actions taken by my script caused a problem with Outlook’s storage file. Just to review, what the script did was: a) execute the Outlook.Application.Quit method to instruct Outlook to shut down; b) wait until outlook.exe dropped off the process list; and then c) execute a SyncToy folder pair that backs up the PST file (among many others.) Since I haven’t been able to get this working from Task Scheduler yet, I’ve been running it right before I turn off the monitor for the night. In the morning I check the log to see what happened.

This morning Outlook was sitting there with a message “The default data file cannot be opened” or something like that. Gulp. I closed it and Outlook exited. Gulp. Repeated this action a couple more times with the same result. Navigated to the storage file folder in explorer and it seemed like someone had a lock on that file, or there was a hung operation. Rebooted, and when Outlook started this time it displayed the message about the storage file not being properly closed, did a quick scan and then opened fine. Whew. I have something like 10 years of stuff in that stupid 1.2 GB file (and a separate .8 GB archive).

Checking the SyncToy log I saw that it reported two failures in that folder, which is what usually shows up when it can’t copy Outlook.pst. That sort of indicates that Outlook didn’t fully close and release its death grip on the file, although the script log did confirm that outlook.exe was not to be found in the process list once the close command had been sent. This was all semi-fun to dig into at first, but it’s sort of become a giant pain in the ass. I ought to be able to back-up my Outlook file without shutting down the program to do it.  SyncToy uses Volume Shadow Copy, and it backs up a lot of other stuff that is in use too.

To be fair SyncToy does fail on some other stuff in the user folder tree, but I am less concerned about that, and I can understand if some of the goings on in AppData cause files to be uncopyable. But why should my email/calendar program have such a headlock on its storage file that it can’t be backed up using VSC? I’m assuming someone out there knows the answer to this question, and many others of deep and lasting import. It all seems to me like an increasingly good argument for online mail/contact/calendar apps that you don’t have to back up yourself. Or maybe I should just migrate to Thunderbird.

Backing Up Outlook, Continued

So a couple of days ago I wrote a post on the subject of Outlook and how it locks its PST file, making it impossible for SyncToy to copy it in my nightly backup. I don’t know what Outlook does to put such a bear hug on this file. Lots of other stuff is running and touches files that get backed up just fine. After all, SyncToy just wants to copy it, not change it. But for whatever reason Outlook opens that file when it starts and puts “No Trespassing” signs all over it.

In response I came up with a script that would close Outlook and then execute the sync job. On that a couple of points. First, I stated that I used the NirCmd utility because it allowed the application to close gracefully, which implied that the taskkill command does not. I was wrong about that. If you don’t use the /F switch then taskkill does something similar to NirCmd, which is find the process main window and post a WM_CLOSE (or WM_QUIT, WM_BYEBYE, WM_GTFO, who does windows messages anymore?) to its message queue. I don’t think they use the exact same method, because they seem to behave slightly differently, but whatever. They’re similar.

Second, there is a third way to close Outlook.exe. That is by using the automation interfaces that all the office applications expose. The ProgId of interest is Outlook.Application.

Type outlookAppType = Type.GetTypeFromProgID("Outlook.Application");
object appInstance = Activator.CreateInstance(outlookAppType);
appInstance.GetType().InvokeMember("Quit", BindingFlags.InvokeMethod, null, appInstance, null);

That little bit of code will (with some error checking) semi-reliably close Outlook. I say semi-reliably because all these methods seem to occasionally fail for less-than-obvious reasons. Last night in a test the method above failed to close Outlook while it was minimized to the tray, but worked once the window had been restored then minimized again. Go figure.

But even if any of these methods was 100% reliable, and the NirCmd approach seems to come closest, it still won’t work from a service like the task scheduler. I figured this out over a couple of evenings of testing and poking around. The explanation lies in the changes to the way services are launched since Vista/Server 2008/Windows 7. Here is an MS article that discusses the issue. The upshot is that services are launched in window session 0, and the first interactive user logs on to window session 1. The messsage queues are tied to the window session, so there is no way for a service to interact with the user desktop, or post windows messages to windows on that desktop.

There is still a way to mark services as interactive by checking the “Allow service to interact with the desktop” box in the service properties dialog. However at least for Task Scheduler I can confirm that doing so doesn’t enable it to see and post messages to Outlook. exe’s message queue. So for the moment, I am working on a different approach that I may post more about later.

Learning Geography

I suspect that children are losing track of where stuff is. Not things like socks and backpacks, which they have never been able to locate reliably, but counties, states, nations, rivers, mountains, hemispheres. I already knew that my own kids have no sense of where stuff is in our locality. How could they? They never leave the house other than to strap themselves into a vehicle for transport to some other network-enabled structure. But when one of them made a statement the other day alluding to Portugal’s proximity to China I was a little surprised. I could quickly show her where Portugal is using Google, Bing, National Geographic, but she wouldn’t be interested. She’s a teenager, and doesn’t believe I have enough brain cells left to tie my own shoes.

I often wear slippers, so she may have a point. In any case, people don’t think much about where stuff is anymore. They don’t need to. Our town is where we are, Portugal is at Newark Airport, and everything else is on the web. But supposing they did want to know? What would be the best way to find out? The answer, you might presume, has already been given: just pop open Google Earth or Bing Maps. But unfortunately both of those tools flat-out suck for answering geographic questions. With the appropriate label layers turned on they do fine for things at the scale of countries, so yes you could answer the Portugal question, but they fall to pieces when it comes to geographic features. Quick, open Google Earth and find me the river Vistula.

No, not the Vistula in Houston, Texas, nor the one in Elkhart, Indiana either. The river. Here’s a hint: it’s in Northern Europe. Just zoom in on that general area and search for “Vistula” again. Wow, “Vistula and Wolczanka” is a very popular something in Poland… but still no river. How about the Elbe? The Oder? The Don? Dnieper? Dniester? Rhine? Ok, dammit, just show me the Danube. You must have the freaking Danube. Actually, no, they don’t. Google Earth is an amazing tool, and it’s primarily good at the daunting task of stitching together different imagery of the planet, and of overlaying roads and towns on that imagery. Mountains? Rivers? Estuaries? Peninsulas? Not so much. So let’s try Bing Maps. That must be better, right?

Yes, a little. In the U.S. at least the new Bing beta mapper does a halfway-decent job of labeling some regions, and some bodies of water. At certain elevations it gets the major rivers, but then you scroll out a little and they disappear. In general Bing suffers from place name overload. Some views present you with a vast dense carpet of place names, and no way to filter them out that I can find. But even so it is better than Google Maps, which is specifically and solely about roads and cities. They don’t even bother labeling the Black Sea or the Mediterranean. Forget mountains, and even if you scroll all the way in they won’t tell you what river that blue line represents.

Of course Google and Bing remain the best way to answer all these questions, and perhaps the only way that matters. If you Google “Danube” you’re going to find out which river it is, and where it is. The information is always out there, but just not in the mapping and visualization tools. So consider this a call to web mapping developers everywhere to make their already neat tools more geography-friendly. Give me accessible means for filtering place names (a population slider would be great). Allow me to layer in other features that I want to see. Let me highlight a mountain range, or all the tributaries of a major river. Let me click on a feature and search for its name. Let me visualize ocean currents and prevailing winds, or highlight all the desert environments or forests.

In short, make it easy for me to find out where stuff is on the planet from within your app. And then get to work on my daughter’s backpacks. I’ve bought seventy-five of them and they are all missing.

Charles Widmore in a Submarine!

If you recorded last night’s episode of Lost on ABC and you haven’t watched it yet, unread that headline. Charles Widmore does not show up at the end cruising in a submarine just off the coast of the Mysterious Island (apologies, Jules). Actually, who cares? If you’re watching Lost then by this time you must have realized that either a) the writers are so freaking brilliant that they have managed to cloak the build-up to a really amazing ending in such complex skeins of obscurity that the ending will be even more amazing when they reveal it; or b) the whole thing has devolved into absurdity because the writers never really had any plan and after six years the plot is completely out of control.

You Know That Thing?

“Have you seen that thing?”

“What thing?”

“That thing that does that thing it does.”

“Oh, that thing. No, sorry.”


thing; noun; from Old English thing, assembly; akin to Old High German ding, thing, assembly; Gothic theihs, time.


I’m not known for brevity. Whether speaking or writing I tend to use a lot of words. Sometimes I even use more words than necessary. Of course, I don’t think they are unnecessary words, but from time to time I feel my listeners or readers probably do. I’m a bit of a throwback. People used to speak, and write, using far more words than they do now. In our hurried times staccato bursts of vernacular whipped with slang seem the rule, and any spoken or written statement longer than five or six words feels burdensome.

The exceptions, of course, are lawyers and legal documents, and by inclusion legislators and bills. They grow wordier in inverse proportion to our terseness, and it’s possible that’s no coincidence. Lawyers know that language is a minefield of ambiguity. They add words in order to reinforce the meaning of the text and anticipate ways in which future readers will attempt to take from it meanings that are at odds with the original intent of the writers. Pursue this goal long enough and what emerges makes for less-than-entertaining reading.

It is, however, precise. I learned to read contracts and legal language long ago, and it has served me well in a number of cases worth real money. I even like writing them, much to the consternation of barristers I have worked with. There is something satisfying about the weighty, measured cadence of legal language thumping onto a page as you write. The words matter in the most practical and immediate sense. They are at the same time statements of currently agreed fact and potential weapons in future disagreements.

Terse language, on the other hand, is often imprecise language. It doesn’t have to be. “Pick up that hammer” is a pretty precise statement. “Grab that” is not, but when accompanied by a nod or hand gesture it can be enough. One sure-fire way to boil the precision out of any statement is to add the word “thing.” It may well be the most useless word in any language. At the very least it’s one of the most irritating. One definition for the word “thing” is: a separate and distinct quality, fact, idea, or usually entity. “Thing” can mean any damned thing, and as a result actually means nothing.

I guess the idea worked well for all those Carpi, Allamani, Tervingi, and Taifali running around central Europe 1500 years ago. They had probably just figured out that there were things in the world, and it is kind of heart-warming to imagine them pointing to a walnut in the Hyrcinian Forest and stating “Ding!” with a confident and knowing air. Yes, Fritigern, that’s a thing you have there. Once you get past that basic philosophical understanding of corporeal entities and their existential selfness the word “thing” is just a hair more useful than the word “noun.”

So while I hesitate to suggest that people go back to writing and speaking in complete sentences that offer fully-developed thoughts,  I do propose that we banish the word “thing” from all polite usage written and spoken. I trust you will get right on that. Meanwhile I have this ding I have to do.


AvalonLife is a pretty complete and full-featured implementation of John Conway’s Game of Life, which I created a couple of years ago as an experiment in WPF programming. I ended up writing a long feature on the creation of the program, which begins here. It has a ton of information on the background of the game, it’s rules, etc., as well as a pretty decent overview of WPF concepts.

The program doesn’t require any installation. Just unzip the package to a folder and run it. You can build and run your own models by clicking to turn cells on or off, or load and experiment with one of the many models included with the program. You can even drag and drop models from the Life Lexicon website and run those.

Downloads: AvalonLife, AvalonLife + Source

Getting Outlook out of SyncToy’s Way

I use Microsoft’s SyncToy for nightly backups. In the past I’ve used many different solutions, from custom xcopy scripts to robocopy to the built-in backup program that started shipping with Windows back in the NT days. I also keep complete disk images for those rare occasions when a full recovery is needed. But for making sure that my daily work is saved I haven’t found a better alternative than SyncToy and a second hard disk.

SyncToy uses the Microsoft Sync Framework 2.0 to manage pairs of folders and keep them in sync according to certain rules. To keep some set of files safe all you do is organize them under one or more folders, then use SyncToy to define named folder pairs that match the original content folders with sync folders on the second drive. There are several modes, but I use the “echo” action, which propagates changes from the source folder to the sync folder. I have a scheduled task that runs every night to tell SyncToy to process all the defined folder pairs.

This setup worked great for months, or at least I thought it did. It’s one of those deals where I set something up, make sure it works, and then forget about it. In this case it turns out that the SyncToy command didn’t quite work as well as I thought. The problem was my Outlook.pst mail file. I have Outlook open all the time, minimized to the system tray, and when Outlook is open SyncToy can’t read the .pst file. When I happened to check the log I saw the read errors and realized that my voluminous mail file had never been backed up.

So, what I needed was a command that would close Outlook, run SyncToy, then restart Outlook. After Googling around and experimenting this is what I came up with:

@echo off
echo Synchronizing folders...
echo Shutting down Outlook.exe...
"c:\Mark Personal\System Tools\NirCmd\nircmd.exe" closeprocess outlook.exe
timeout 2
tasklist /FI "IMAGENAME eq outlook.exe" 2>NUL | find /I /N "outlook.exe">NUL
if "%ERRORLEVEL%"=="0" goto :wait
echo Outlook closed; executing SyncToyCmd...
"C:\Program Files\SyncToy 2.1\SyncToyCmd.exe" -R
echo Sync completed; starting Outlook.exe...
start "" /B /MIN C:\Users\Mark\Desktop\Outlook
echo Outlook.exe started; exiting
@echo on

This script first sends Outlook.exe a shutdown command using a nifty command line tool called NirCmd.exe, from NirSoft. You could also use taskkill, but NirCmd is a gentler method that gives Outlook a chance to properly close its data files, and if you know anything about Outlook, you know you want it to properly close its data files.

After telling Outlook to close the script loops until it can no longer find outlook.exe in the running task list, and then proceeds to run SyncToy for all active folder pairs, and then restart Outlook after it completes. Pretty neat, and I can’t take credit for any of it. Just some stuff cobbled together from bits and pieces of others’ wisdom around the net.