Note 1: I posted this same message on the MSFN forum at http://www.msfn.org/board/Request-Scrip … 43413.html , which is the thread from spring 2005 hosting the original HWIDS.CMD script. I posted it there at the request of IcemanND, the author of the INF scanning engine in this script. Thanks for the original, IcemanND!
Note 2: If someone knows how to change IcemanND's script to filter out the tab characters that sometimes got through the original script, then the dependency on SED.EXE will go away.
---
I have taken the HWIDS script and improved it by solving several weaknesses in the original. The main caveat is it now requires SED.EXE, a free/GPL tool from http://gnuwin32.sourceforge.net/packages/sed.htm , to be somewhere on the system path. I used SED to remove the tab characters that Skillz reported in an earlier post. The list of improvements is in the code below.
On the todo list would be automating the following:
1.) running sysprep -bmsd to insert the official MassStorage drivers into sysprep.inf (easy to do in a batch file)
2.) inserting of the output of this HWIDS script into the correct section of sysprep.inf, after the official drivers list, while verifying duplicate entries are not created in case a driver has been added on a previous insertion. (If someone has a good way of doing this, I'd love to hear it.)
HWIDS.CMD (Inf Scanner)
@echo off
:: Core INF scanning and processing engine created by IcemanND and posted on MSFN Forums
:: at http://www.msfn.org/board/lofiversion/index.php/t43413.html
::
:: Note: I (HK) contacted IcemanND on MSFN on 4/7/2008 and asked him if it would be okay to
:: release this modified version under both the GPL and Creative Commons Attribution licenses.
:: His response was 'Feel free.'
::
:: Reposted by Skillz on Driverpacks.net Forums at http://forum.driverpacks.net/viewtopic.php?pid=11604
:: Modified and expanded by Haudy Kazemi:
:: -improved handling of paths with spaces in them (added quotes around '%cd%' in SET STDOUT line)
:: -added error messages rather than silently exiting
:: -added ability to configure filename of output file
:: -added a check to see whether the output file name already exists to prevent accidental overwriting
:: -cleaned up output and added status and progress information
:: -Skillz reported that tab characters are not removed by the script. I worked around this problem
:: with this command: sed -T -e "s/ //" hwids.txt > hwids-tabsremoved.txt
:: (tested and found to work correctly using 'GNU sed version 4.1.5' on Windows XP)
IF "%1"=="" GOTO INFO
IF NOT EXIST %1 GOTO FOLDERNOTFOUND
IF "%2"=="" GOTO NOOUTPUTFILE
IF "%3"=="overwrite" GOTO SKIPOUTPUTFILECHECK
IF EXIST "%2" GOTO OUTPUTFILEEXISTS
:SKIPOUTPUTFILECHECK
:: Check for SED.EXE on path (derived from sample code in viewpath.cmd on http://www.ss64.com/nt/path.html )
:: I (HK) contacted Simon Sheppard of ss64.com on 4/7/2008 about using a derivation of his code and
:: releasing it under both the GPL and Creative Commons Attribution licenses. His response was 'Sure, no problem'.
:: Note: I (HK) have put together a related script called ProgramPath that exposes this search-the-path-for-a-file
:: ability directly on the command line.
::echo the path one line at a time
for %%G in ("%path:;=" "%") do (
::echo %%G\sed.exe
IF EXIST %%G\sed.exe GOTO SEDEXEFOUND
)
GOTO SEDEXENOTFOUND
:SEDEXEFOUND
echo Beginning scan...this may take a few minutes...
SETLOCAL ENABLEDELAYEDEXPANSION
SET STDOUT="%cd%"\%2
SET OUTPUTFILE=%2
TYPE>%STDOUT% 2>NUL
::traverse drivers path
CALL :TRAVERSAL %1
::Use sed to find and remove any tab characters in the output file
::This is a workaround for the problem reported by Skillz
echo Running SED.EXE on %OUTPUTFILE%
sed -T -e "s/ //" %OUTPUTFILE% > %OUTPUTFILE%-tabsremoved.txt
del %OUTPUTFILE%
ren %OUTPUTFILE%-tabsremoved.txt %OUTPUTFILE%
echo Job completed.
GOTO EOF
:TRAVERSAL
echo Processing %1
PUSHD %1
for /f %%f in ('dir /b *.inf') do (
echo Processing %1\%%f
for /f "eol=- tokens=2 delims=," %%i in ('find /i "pci\ven" %%f') do (
for /f "tokens=*" %%j in ("%%i") do (
for /f "tokens=1* delims=_" %%k in ("%%j") do (
if /i "%%k" EQU "PCI\VEN" (
for /f "usebackq tokens=1* delims=; " %%a in ('%%j') do (
echo %%a=%cd%\%%f>>%STDOUT%
)
)
)
)
)
)
FOR /F %%I IN ('DIR /AD /OGN /B') DO (
CALL :TRAVERSAL %CD%\%%I
)
POPD
GOTO EOF
:INFO
echo Inf Scanner 20080407 by Haudy Kazemi
echo Credit is due to IcemanND for the core INF scanning engine, and
echo to Simon Sheppard for his system path parsing example.
echo Dual licensed under the GPL and Creative Commons Attribution License
echo.
echo This script is designed to scan a directory tree containing MassStorage device
echo INFs to find their HWIDs and output them to a file that can then be added into
echo a SYSPREP.INF. This script should work on any INFs, in case you want to
echo gather a collection of HWIDs for other types of hardware.
echo.
echo HWIDS %%1 %%2 %%3
echo %%1 is the path to folder/tree containing DriverPack MassStorage or other INFs
echo (e.g. C:\D\M ).
echo %%2 is the name of an output file to store the HWIDS in (e.g. hwids.txt)
echo %%3 should be the word 'overwrite' if you want to replace an existing output
echo file of the same name
echo.
echo Messages of 'File Not Found' are normal. They are caused by the script's use
echo of 'dir /b *.inf' coming across folders with no INF files in them. These can
echo safely be ignored.
goto EOF
:FOLDERNOTFOUND
echo ERROR: The specified folder was not found.
echo Please specify another folder location.
GOTO EOF
:NOOUTPUTFILE
echo ERROR: No output file specified.
echo Please specify the name of an output file to store the HWIDS in (e.g. hwids.txt).
GOTO EOF
:OUTPUTFILEEXISTS
echo ERROR: File overwrite prevented.
echo You chose an output filename that already exists. Please delete that file,
echo enable overwriting, or choose a different filename.
GOTO EOF
:SEDEXENOTFOUND
echo ERROR: SED.EXE was not found anywhere in the system path.
echo Please make it available on the system path. It is needed to remove
echo extra tabs in the output file.
echo Note: GNU sed version 4.1.5 is known to work correctly on Windows XP
echo and can be obtained from http://gnuwin32.sourceforge.net/packages/sed.htm
GOTO EOF
:EOF
I call HWIDS.CMD with another script named hwidscan.bat. This specifies the folder to scan, the name of the output file, and to force an overwrite of the output file if it already exists:
HWIDSCAN.BAT
:: Put together by Haudy Kazemi on 4/7/2008 to automate the HWIDS.CMD scan and update
hwids.cmd c:\drivers\dp\D\M hwids.txt overwrite
In the process of creating the improvements to HWIDS.CMD, I wrote code to verify that SED was available. Here is that code in a standalone form, called ProgramPath. It's job is to check to see if a program or file is available somewhere on the system path, and report back any locations it finds.
PROGRAMPATH.CMD
@echo off
if "%1"=="" goto INFO
::echo the path one line at a time
for %%G in ("%path:;=" "%") do (
::echo %%G\%1
IF EXIST %%G\%1 echo %%G\%1
)
goto END
:INFO
:: I (HK) contacted Simon Sheppard of ss64.com on 4/7/2008 about using a derivation of his code and
:: releasing it under both the GPL and Creative Commons Attribution licenses. His response was 'Sure, no problem'.
:: Based on Simon Sheppard's viewpath.cmd
:: at http://www.ss64.com/nt/path.html
:: and http://www.ss64.org/dl1/ss64win.zip
echo ProgramPath 20080407 by Haudy Kazemi
echo Credit is due to Simon Sheppard for his system path parsing example.
echo Dual licensed under the GPL and Creative Commons Attribution License
echo.
echo Checks to see if a program or file is available on the system path:
echo PROGRAMPATH %%1
echo where %%1 is the name of the file you want to check for
echo.
:END
Last edited by hkazemi (2008-04-08 06:19:03)