Subscribe to Windows IT Pro

 

Get Newsletters

  • Get the Latest News
  • Product Updates
  • Helpful Tricks
  • Productivity Tips

Subscribe Now!

September 08, 2005 12:00 AM

JSI Tip 9715. How can I generate a file association report?

Windows IT Pro
InstantDoc ID #84330
Rating: (0)


Using REG.EXE, built into Windows XP, Windows Server 2003, and later, or installed on Windows 2000 from the Support Tools folder of of the Windows 2000 CD-ROM, I have scripted AssocList.bat to generate a semi-colon delimited file containing:

Assoc;Ftype;Action;CommandString

Where:

Assoc         is the file extension, like .txt. Two special extensions are Directory and Folder.

Ftype         is the registry sub-key in the HKCR key that houses the Action definition, like txtfile.

Action        is the command that appears on the context menu, like Open, Print, and Edit.

CommandString defines the program and parameter(s) required to perform the Action, like %SystemRoot%\system32\NOTEPAD.EXE %1.
The syntax for using AssocList.bat is:

AssocList [ComputerName]

Where ComputerName is optional, defaulting to the local computer.

The output is written to AssocList_<ComputerName>.txt in the current directory.

AssocList.bat contains:

@echo off
setlocal ENABLEDELAYEDEXPANSION
set comp=%1
if "%comp%" EQU "" set comp=%ComputerName%
set comp=%comp:"=%
set comp=%comp:\=%
set file=AssocList_%comp%.txt
if exist %file% del /q %file%
set comp=\\%comp%
set assoc=Directory
set ftype=Directory
set ftk="%comp%\HKLM\Software\Classes\Directory\Shell"
call :quiet1>nul 2>&1
set assoc=Folder
set ftype=Folder
set ftk="%comp%\HKLM\Software\Classes\Folder\Shell"
call :quiet1>nul 2>&1
call :quiet>nul 2>&1
endlocal
goto :EOF
:quiet
for /f "Tokens=4 Delims=\" %%a in ('reg query "%comp%\HKLM\SOFTWARE\Classes"^|find "\."') do (
 set assoc=%%a
 set key=HKLM\SOFTWARE\Classes\%%a
 for /f "Tokens=3*" %%b in ('reg query "%comp%\!key!" /Ve^|find "REG_"') do (
  set ftype=%%c
 )
 set ftk="%comp%\HKLM\Software\Classes\!ftype!\Shell"
 for /f "Tokens=*" %%d in ('reg query !ftk!^|find /i "Shell"') do (
  for /f "Tokens=5* Delims=\" %%x in ('@echo %%d') do (
   set command=%%y
   set ftl="%comp%\HKLM\Software\Classes\!ftype!\Shell\%%y\command"
   for /f "Tokens=3*" %%i in ('reg query !ftl! /Ve^|find "REG_"') do (
    set prog=%%j
    @echo !assoc!;!ftype!;!command!;!prog!>>%file%
   )
  )
 )
)
goto :EOF
:quiet1
for /f "Tokens=*" %%d in ('reg query %ftk%^|find /i "Shell"') do (
 for /f "Tokens=5* Delims=\" %%x in ('@echo %%d') do (
   set command=%%y
   set ftl="%comp%\HKLM\Software\Classes\%ftype%\Shell\%%y\command"
   for /f "Tokens=3*" %%i in ('reg query !ftl! /Ve^|find "REG_"') do (
    set prog=%%j
    @echo %assoc%;%ftype%;!command!;!prog!>>%file%
   )
 )
)



Related Content:

ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

White Papers

Get your Windows 7 deployment off to the right start by implementing PC lockdown. A locked-down environment is easier and cheaper to support since users are less likely to make unnecessary changes to the core system configuration - read more here!

Essential Guides

Is your iSCSI "lossy"? The reality is that most off-the-shelf Ethernet hardware deployed for iSCSI can lose packets, resulting in slow performance or application downtime. Learn how to assess your current iSCSI infrastructure and engineer an advanced iSCSI SAN infrastructure.

Web Seminars

What's the best way to keep your network safe from malware? In this web seminar, security expert Greg Shields suggests an alternative method to the traditional blacklisting approach that is common with anti-virus and anti-malware solutions.

eLearning Series

We bring the experts direct to you to share their real-world perspective and expertise. During each event, three sessions stream in real time, so you can learn, ask questions, and get solutions.
Upcoming event: Getting the Most with Exchange 2010 with Paul Robichaux

Subscribe to Windows IT Pro!

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.