Showing results for Code - The Old New Thing

Aug 23, 2012
Post comments count0
Post likes count0

Wait, you never said that I had to initialize the object before I used it!

Raymond Chen
Raymond Chen

A customer reported that they were having trouble creating slim reader/writer locks at runtime. They simplified the issue to a short program: "What is the correct way of creating an via the operator?" It wasn't long before somebody noted that nowhere in the code is the function called. "Oh, yeah, thanks for catching that. It looks like ...

Code
Aug 20, 2012
Post comments count0
Post likes count0

How do I customize how my application windows are grouped in the Taskbar?

Raymond Chen
Raymond Chen

Benjamin Smedberg wants to know how to customize the icon used in the Taskbar for applications that are grouped, when the application is a runtime for multiple applications. (This is the other scenario I hinted at last time.) Actually, customizing the icon is only part of what you want to happen when your application is a runtime. In that case...

Code
Aug 17, 2012
Post comments count0
Post likes count0

What if my application is really two applications bundled into a single file, and I want them collected into two groups on the taskbar in Windows 7?

Raymond Chen
Raymond Chen

A customer wanted to prevent multiple copies of their program from being grouped on the taskbar. They didn't give an explanation why, but let's assume that they are doing this for honorable purposes rather than as a way to annoy the user. For example, maybe their program is really multiple applications bundled inside a single EXE file for convenie...

Code
Aug 3, 2012
Post comments count0
Post likes count0

FORFILES, for your fancier batch file enumeration needs

Raymond Chen
Raymond Chen

Crack open open the champagne: Batch File Week is finally over! Variations on the will let you repeat an operation on the contents of a directory, possibly even recursively if you add the option, with some basic attribute-level filtering if you add the or /a- flags. For your fancy recursive file operations, there's a tool called which iter...

Code
Aug 2, 2012
Post comments count0
Post likes count0

Exiting a batch file without exiting the command shell -and- batch file subroutines

Raymond Chen
Raymond Chen

Prepare your party hats: Batch File Week is almost over. In your batch file, you may want to exit batch file processing (say, you encountered an error and want to give up), but if you use the command, that will exit the entire command processor. Which is probably not what you intended. Batch file processing ends when execution reaches the end...

Code
Aug 1, 2012
Post comments count0
Post likes count1

How do I find the most recently created file in a directory from a batch file?

Raymond Chen
Raymond Chen

We've reached Hump Day of Batch File Week. Remember, nobody actually likes batch programming. You merely tolerate it. Today, we'll find the most recently-created item in a directory. (For example, we have a server that holds our daily builds, and you might want to write a batch file that automatically installs the latest build.) There may be b...

Code
Jul 31, 2012
Post comments count0
Post likes count3

Reading the output of a command into a batch file variable

Raymond Chen
Raymond Chen

It's Day Two of Batch File Week. Don't worry, it'll be over in a few days. There is no obvious way to read the output of a command into a batch file variable. In unix-style shells, this is done via backquoting. The Windows command processor does not have direct backquoting, but you can fake it by abusing the command. Here's the evolution: ...

Code
Jul 30, 2012
Post comments count0
Post likes count0

Why don't any commands work after I run my batch file? I'm told that they are not recognized as an internal or external command, operable program, or batch file.

Raymond Chen
Raymond Chen

I sort of forgot to celebrate CLR Week last year, so let's say that CLR week is "on hiatus" until next year. To fill the summertime time slot, I'm going to burn off a busted pilot: This week is Batch File Week 2012. Remember, nobody actually enjoys batch programming. It's just something you have to put up with in order to get something done. Batch...

Code
Jul 27, 2012
Post comments count0
Post likes count0

Psychic debugging: Why your IContextMenu::InvokeCommand never gets called

Raymond Chen
Raymond Chen

A customer reported a problem with their shell context menu extension. I have implemented the shell extension, but when the user selects my custom menu item, my is never called. Can anyone please let me know what the problem could be and how to fix it? Since there really isn't much information provided in this request, I was forced to invoke m...

Code
Jul 25, 2012
Post comments count0
Post likes count0

One way to make sure you pass an array of the correct size

Raymond Chen
Raymond Chen

Another entry in the very sporadic series of "very strange code I've seen." The code has been changed to protect the guilty, but the essence has been preserved.

Code