The Old New Thing

Getting the current selection from an Explorer window

Today's Little Program prints the current selection in all open Explorer windows. (This is an alternative to the C++ version that involves a ridiculous amount of typing.) var shellWindows = new ActiveXObject("Shell.Application").Windows(); for (var i = 0; i < shellWindows.Count; i++) { var w = shellWindows.Item(i); WScript.StdOut....

Why does CoCreateInstance work even though my thread never called CoInitialize? The curse of the implicit MTA

While developing tests, a developer observed erratic behavior with respect to : In my test, I call and it fails with . Fair enough, because my test forgot to call . But then I went and checked the production code: In response to a client request, the production code creates a brand new thread to service the request. The brand new thread ...

How can I figure out which user modified a file?

The function will tell you when a file was last modified, but it won't tell you who did it. Neither will , , or , or . None of these the file system functions will tell you which user modified a file because the file system doesn't keep track of which user modified a file. But there is somebody who does keep track: The security event log...

If you don’t know what you’re going to do with the answer to a question, then there’s not much point in making others work hard to answer it

A customer asked the following question: We've found that on Windows XP, when we call the XYZ function with the Awesome flag, the function fails for no apparent reason. However, it works correctly on Windows 7. Do you have any ideas about this? So far, the customer has described what they have observed, but they haven't actually ...

Using opportunistic locks to get out of the way if somebody wants the file

Opportunistic locks allow you to be notified when somebody else tries to access a file you have open. This is usually done if you want to use a file provided nobody else wants it. For example, you might be a search indexer that wants to extract information from a file, but if somebody opens the file for writing, you don't want them to get ...