Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


September 08, 2009

Find Document Handlers for Specific Users

RSS
Subscribe to Windows IT Pro | See More Registry Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

One side effect of improved per-user customization in Windows is that it's difficult to determine what application opens a specific document type for users. This can be crucial if you're attempting to monitor application usage to verify compliance with company policies or licensing restrictions, or predict breakage caused by old user customizations after application migrations.

The central problem with finding the document handler used by an application for a specific user is that the information is stored in a location that isn't normally accessible from any context but that of the user. Windows uses the HKEY_CLASSES_ROOT (HKCR) registry subtree to determine what document handler to use, but this key is synthesized at logon by taking machine-wide settings from the HKEY_LOCAL_MACHINE (HKLM) subtree and overlaying user-specific customizations from the HKEY_CURRENT_USER (HKCU) subtree. Although you can access the registry remotely, what you read will be based on either the HKLM key or your own HKCU key (if your profile was loaded) retrieved by that machine—not the logged-on user's key.

To inspect user-specific registry data, the only realistic solution is to handle the inspection from the user's context. This will always return information that's correct from the user's standpoint. You can use code like that shown in Listing 1 in a logon script to perform this kind of user-based document-handler check.

To make the document-handler check code work properly, you should customize the extension value set in callout A to match the file extension of the handler you need to check. As written, the code will check the document handler for PDF files.

Given the file-type extension, the code in callout B looks up the handler the same way Windows does—by checking the default open command for that file type. Specifically, the code first obtains the name of the class for the file type from the extension's registry key. The code then goes to that class's registry key to obtain the default open command and assigns this document-handler information to the OpenCommand variable. If the extension or the associated file type isn't correctly registered, the code will throw an error. If an error occurs, the code suppresses the error and assigns a value of "undefined" to the OpenCommand variable.

Next, the code collates the extension, username, and document-handler information in a variable named data. In callout C, the code then sets the variable named server to the name of the logon server, then writes the data variable's contents to that server's Application log. The resulting messages will look similar to

user aka opens .pdf documents with:
  "C:\PROGRA~2\FOXITS~1\FOXITR~1
  FOXITR~1.EXE" "%1" on system X51

Events logged from a Windows Script Host (WSH) script always use WSH as the source application.

When you incorporate the code in Listing 1 into a logon script, you can occasionally check the logs to find the default application handling specific documents on a per-user basis on individual client workstations. If you want to find the document handler used by an application for a specific user but you don't want to incorporate the code in Listing 1 into a logon script, you can comment out the code in callout C, uncomment the code in callout D, and run it on the user's machine.

You can download the code in Listing 1 by clicking the Download the Code Here button at the top of the page. I wrote this code for use on Windows XP and later.


Listing 1: Code That Checks for User-Based Document Handlers


End of Article



Reader Comments

You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
WinInfo Short Takes: Week of November 23, 2009

An often irreverent look at some of the week's other news, including some post-PDC some soul searching, a Google Chrome OS announcement and a Microsoft response, Windows 7 off to a supposedly strong start, the Jonas Brothers and Xbox 360, and so much more ...

Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

2009 Windows IT Pro Editors' Best and Community Choice Awards

Picking a favorite product from an impressive crowd of competitive offerings is never an easy task, and such was the case with our Editors' Best and Community Choice awards this year. ...


Related Articles Capture File Paths in 3 Simple Steps

Another Way to Quickly Copy File Paths

Use ADSI Edit to Associate File Extensions

Hidden Option, Free Utility Can Be Real Time-Savers If You Copy File Paths Often

Scripting Whitepapers From Development to Production: Streamlining SharePoint Deployment with DocAve Deployment Manager

Related Events Deep Dive into Windows Server 2008 R2 presented by John Savill

Take Control of Storage & eDiscovery Costs with Unified Content Archiving

7 Ways To Get More From Your SharePoint Deployment Now

Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement