This is another of those questions that appear from time to time in the forums: how to make a command invisible or disabled, how to make it appear only when some condition is true, etc. The answers are in the QueryStatus / AddNamedCommand methods. Since my MZ-Tools add-in does not use a permanent user interface, I was not very interested in this topic or in the optional parameters of the AddNamedCommand method. Finally I decided to investigate about it and I found that, as usual, commands are tricky (as happens with commandbars and buttons) and that there are a couple of bugs (that I reported here) in the extensibility model regarding this that ruin the experience. Each time I am more and more against the permanent user interface in add-ins, which is a half-designed feature, half-implemented and half-tested. Here you have the details:
HOWTO: Controlling the state of command in a Visual Studio add-in
http://www.mztools.com/articles/2007/MZ025.htm