Last Update: 26.09.2007. By kerim in tools
Do you remember the good old times when you used to print the results of a simple “DIR” command ? This “feature” has been absent since Windows 95. Of course you still can start the command line and issue the dir command but normally printers are managed by windows these days and do not have to reside on “lpt1:”.
And of course with all those nice guis hanging around it’s not everyones pleasure to run the command line and type. I came upon some sites that actually wanted money for this really -lets call it- “basic” feature. Which prompted me to simply try it out myself and demand a coffee from Azarai as payment.
So here is the simple solution:
a) [as a complete setup program (~350 kB)] (http://codeboje.de/downloads/DirPrintSetup.exe)
b) as a how-to
a)
1) download
2) install
3) using the windows explorer you may select any DIRECTORY, click the RIGHT mouse button and choose DIRPRINT. The directory that you selected will be automatically printed to the standard printer you have defined in your windows system. No extra dialogs, no “do you want to do this or that”.
4) deinstallation is available through an entry in the start menu or via the normal windows add/remove programs dialog
BUGS:
Only one: Deinstallation doesnt remove the registry key “DirPrint”. You either have to remove it manually or wait till i (or someone else ?) solved that problem. The bug is of no real consequence though.
b)
1) Create a batch file. Call ist whatever you want (for example: dirprint)
2) Write the following text:
@echo off
dir %1 /o:gn /-p > “%systemroot%\dirprintfilelist.txt”
start /w notepad /p “%systemroot%\dirprintfilelist.txt”
del “%systemroot%\dirprintfilelist.txt”
exit
Explanation:
The first line will disable all outputs to the console. The second will list the files and directories in a given directory and write that into a file named dirprintfilelist.txt in the windows folder. The third line will start notepad and make it print the file. You may choose to not use start /w (simply delete that part). Its used to start notepad in a seperate process. The last two lines delete the file and exit.
3) Save the file.
4) Now there are two ways to proceed. Manually or automatically using an installer.
Overall what actually needs to be done now is to add an entry for printing directories to the context menu of the windows explorer. This is done by modifying the registry key “HKEY_CLASSES_ROOT\Directory\shell\“. You must create a new key there named “DirPrint\command”. “command” stands for “this comand will be executed once the user clicked on the menu entry”. “DirPrint” is the text that will be displayed in the context menu.
You must set the “(Standard)” value to the path to your batch file (e.g.: “c:\program files\dirprint\dirprint.bat”)
a) If you want to do that manually, just copy the batch file to the folder where you want it to reside, start regedit from the command line and set these values.
b) If you want to have it done and also create an installer for others get an application that allows you to create installers ABLE TO MODIFY THE RESTISTRY. My favorite choice is innosetup. (I explain the rest using that app)
The process is pretty straight forward and a wizard will help you. In the end you should have something like this here:
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
[Setup]
AppName=DirPrint
AppVerName=DirPrint 1.0
AppPublisher=Kerim Mansour
AppPublisherURL=http://codeboje.de
AppSupportURL=http://codeboje.de
AppUpdatesURL=http://codeboje.de
DefaultDirName={pf}\DirPrint
DefaultGroupName=DirPrint
OutputBaseFilename=setup
Compression=lzma
SolidCompression=yes
[Languages]
Name: “english”; MessagesFile: “compiler:Default.isl”
Name: “basque”; MessagesFile: “compiler:Languages\Basque.isl”
Name: “french”; MessagesFile: “compiler:Languages\French.isl”
Name: “german”; MessagesFile: “compiler:Languages\German.isl”
[Files]
Source: “C:\WINNT\Profiles\MANSOURK\Desktop\dirprint.bat”; DestDir: “{app}”; Flags: ignoreversion
; NOTE: Don’t use “Flags: ignoreversion” on any shared system files
[Icons]
Name: “{group}\DirPrint”; Filename: “{app}\dirprint.bat”
Name: “{group}\{cm:UninstallProgram,DirPrint}”; Filename: “{uninstallexe}”
All you need to do now is:
i) Insert:
[Registry]
Root: HKCR; Subkey: “Directory\shell\DirPrint\“; ValueType: string; ValueName: “”; ValueData: “”;
Root: HKCR; Subkey: “Directory\shel\l\DirPrint\command”; ValueType: string; ValueName: “”; ValueData: “{app}\dirprint.bat”;
ii) insert a “;” before
Name: “{group}\DirPrint”; Filename: “{app}\dirprint.bat”, so that it doesn’t show up in the start menu (we only want the deinstallation routine to show up).
iii)Let innosetup create the setup.exe for you and test it.