Jump to content

Existing script, help required


Recommended Posts

Note 1: I posted this same message on the DriverPacks.net forum at http://forum.driverpacks.net/viewtopic.php?id=1637&p=2 , which is a more recent thread. I am reposting it here 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

Link to comment
Share on other sites


From what I can see there are improvements which can be made, to both Windows NT Command Scripts, but without a fuller explanation of what is required, I cannot effectively update it. I have no idea what any of the input inf files may contain which is/isn't required in order to attempt to bypass SED or any other stream editor. I would also need to know exactly what the TRAVERSAL section is intended to do, with real examples.

Link to comment
Share on other sites

From what I can see there are improvements which can be made, to both Windows NT Command Scripts, but without a fuller explanation of what is required, I cannot effectively update it. I have no idea what any of the input inf files may contain which is/isn't required in order to attempt to bypass SED or any other stream editor. I would also need to know exactly what the TRAVERSAL section is intended to do, with real examples.

This Driverpack MassStorage INF causes the tab troubles that I addressed using SED:

C:\D\M\IT\iteraid.inf

This thread has some old posts highlighting the tab issue that was not addressed in the original version of HWIDS.CMD

http://www.msfn.org/board/Unattended-syspr...ess-t43733.html

The TRAVERSAL section was written by IcemanND. It loops over directory (and its subdirectories) that was specified on the command line, and then loops over every INF file in each of those directories. It then scans the INFs for HWIDS and outputs them to a file. The occaisonal 'File Not Found' error message comes from DIR *.INF not finding any INF in a directory.

Link to comment
Share on other sites

Attached is and archive containing my uninformed attempt at something which I hope does as you wished!

Just run it first without parameters for the INFO or read it below:

Syntax:HwIDs FolderTree OutputFile [-OW]

FolderTree: Path to folder/tree containing DriverPack MassStorage (other INFs)

(e.g. C:DM ). [The path must use quotes if it contains spaces]

OutputFile: The output file name/path in which to store the resultant HwIDS.

(e.g. hwids.txt|C:\MyDir\HwIDs.log)

-OW: [Optional]

Include to replace an existing OutputFile of the same name

Link to comment
Share on other sites

:wacko::crazy:

Never too old to learn. Definitely not a script a beginner is going to figure out.

Except you missed two.

PCI\VEN_1039&DEV_1184=C:\D\M\SIS2\SISRAID4.inf

PCI\VEN_1039&DEV_1185=C:\D\M\SIS2\SISRAID4.inf

Link to comment
Share on other sites

Attached is and archive containing my uninformed attempt at something which I hope does as you wished!

Just run it first without parameters for the INFO or read it below:

Syntax:HwIDs FolderTree OutputFile [-OW]

FolderTree: Path to folder/tree containing DriverPack MassStorage (other INFs)

(e.g. C:DM ). [The path must use quotes if it contains spaces]

OutputFile: The output file name/path in which to store the resultant HwIDS.

(e.g. hwids.txt|C:\MyDir\HwIDs.log)

-OW: [Optional]

Include to replace an existing OutputFile of the same name

Thanks for looking at this. I just downloaded this version and have been testing it. My first impression is I like how concise your code is. Here are my other observations:

1.) when at a command prompt, I prefer that programs do not clear the screen (CLS) because I like to be able to be able to scroll back to previous entries in the scroll buffer. (easily changed in the first line of your script).

2.) why is command 'Pause>Nul&Goto :Eof' used instead of simply jumping to the end of the file and returning to the command prompt?

3.) on a large directory parsing, periodic on-screen updates are useful to let the user know things are still working (this is why I had a message echoed to the screen on every directory in the version I posted)

4.) some INFs result in lines that are duplicates of each other. ichXdev.inf, a part of the Intel chipset drivers definitely does this, as does MassStorage INF dp\D\M\C1\CPQCISSM.inf. Looking at the output file in Excel makes the duplication very clear, although it appears to not happen every time. This problem also affects the version I had posted. One possible solution is to apply the 'sort' command and then the 'uniq' command to the output which will eliminate the duplicates, at the expense of needing 2 more separate programs. Eliminating duplicate lines may speed up the Sysprep process and/or prevent conflicts, depending on how Sysprep behaves when encounters a duplicate MassStorage driver entry.

5.) when I ran it on a folder with a large number of drivers, I saw output like this (didn't happen on a small folder) (maybe some variables overflowed?):

C:\>HwIDs.cmd \drivers hwids.txt

Beginning scan, this may take a while...

PRADEONX1300Series=ati2mtag_RV515" "C:\drivers\shared\video\ati_catalyst_6-11_xp

-2k_dd_37616\$OUTDIR\C2_38857.inf"PRADEONX1300Series=ati2mtag_RV515" "C:\drivers

\shared\video\ati_catalyst_6-11_xp-2k_dd_37616\$OUTDIR\C2_38857.inf"PRADEONX1300

SeriesSecondary=ati2mtag_RV515" "C:\drivers\shared\video\ati_catalyst_6-11_xp-2k

_dd_37616\$OUTDIR\C2_38857.inf"PRADEONX1300SeriesSecondary=ati2mtag_RV515" "C:\d

rivers\shared\video\ati_catalyst_6-11_xp-2k_dd_37616\$OUTDIR\C2_38857.inf"PRADEO

NX1600Series=ati2mtag_RV530" "C:\drivers\shared\video\ati_catalyst_6-11_xp-2k_dd

<many similar lines snipped>

8857.inf"PRO-Secondary=ati2mtag_RV410" "C:\drivers\shared\video\ati_catalyst_6-1

1_xp-2k_dd_37616\$OUTDIR\CX_38857.inf"PRADEON9600SE=ati2mtag_RV350" "C:\drivers\

shared\video\ati_catalyst_6-11_xp-2k_dd_37616\$OUTDIR\CX_38857.inf"PRADEON9600SE

-Secondary=ati2mtag_RV350" "C:\drivers\shared\video\ati_catalyst_6-11_xp-2k_dd_3

7616\$OUTDIR\CX_38857.inf"PRADEON9600XTBRAVO=ati2mtag_RV360" "C:\drivers\shared\

video\ati_catalyst_6-11_xp-2k_dd_37616\$OUTDIR\CX_38857.inf"PRADEON9600XTBRAVO-S

econdary=ati2mtag_RV360" "C:\drivers\shared\video\ati_catalyst_6-11_xp-2k_dd_376

16\$OUTDIR\CX_38857.inf" Job Completed

Press any key to End

Link to comment
Share on other sites

answers:

  1. The CLS is there in order to highlight any error message. I prefer, and it is considered good practice, to see Error messages echoed to the top of the console window.
  2. The pause is used in order to keep the window open so that all users can read any output.
    You may be working directly in the console but most batch files are invoked either directly in the GUI or via another process meaning without the pause the window will close and any important messages missed. Both of the above are only problems to you because of the way you work and my batch was created for general use with little or no input from yourself as to the full requirements, just some links you expected me to read through in order to help you.
  3. I dont like echoing pointless information to the screen, some infs may only have a couple of lines and quickly echoing their names faster than they can be read serves no purpose whatsoever to me. You are told that the process has begun, and informed when it ends. I can see no reason to list the files being parsed during that processing. This is also one of the reasons for both the CLS and PAUSE you didn't like earlier.
  4. Not only does it appear that this is a old unmentioned problem, it was also not part of the original request. It is possible code the removal of duplicates in a batch file, however this file is already using an inappropriate scripting language for the task at hand. As you should be aware, working with output containing poison characters is extremely tricky as it is. To further parse it and check for duplicates is not something I intend to do. I would therefore suggest you use an appropriate commandline utility created specifically for this purpose.
  5. This looks like STDERR output to me, it certainly isn't complete lines being missed. I will take a look at it, but I have no intention of recreating a full working environment using all possible infs in order to test.
    My test bed was to invoke the batch file using, HwIDs C:\WINDOWS\inf "C:\Documents and Settings\Administrator\HwIDs.log"; which is a relatively large directory too and there were no errors at all on a Windows XP System. I will look to see if I can include an STDERR redirection, but if that doesn't work then it must be your infs which contain something which I cannot see. I also note from your output that all of your directories are enclosed in double quotes and don't include PCI/VEN, since they aren't in my output files then the problem is occurring before the end of the script.

I would strongly suggest that unless you really know what you're doing, then DO NOT attempt to make changes to the main code and expect it to work!

<Edit>

I've included a new version which redirects some more STDERR, you can see if it helps with your console output problem.

</Edit>

<Edit2>

Attachment removed due to updated version below.

</Edit2>

Link to comment
Share on other sites

5.) when I ran it on a folder with a large number of drivers, I saw output like this (didn't happen on a small folder) (maybe some variables overflowed?):

C:\>HwIDs.cmd \drivers hwids.txt

Beginning scan, this may take a while...

PRADEONX1300Series=ati2mtag_RV515" "C:\drivers\shared\video\ati_catalyst_6-11_xp

-2k_dd_37616\$OUTDIR\C2_38857.inf"PRADEONX1300Series=ati2mtag_RV515" "C:\drivers

\shared\video\ati_catalyst_6-11_xp-2k_dd_37616\$OUTDIR\C2_38857.inf"PRADEONX1300

SeriesSecondary=ati2mtag_RV515" "C:\drivers\shared\video\ati_catalyst_6-11_xp-2k

_dd_37616\$OUTDIR\C2_38857.inf"PRADEONX1300SeriesSecondary=ati2mtag_RV515" "C:\d

rivers\shared\video\ati_catalyst_6-11_xp-2k_dd_37616\$OUTDIR\C2_38857.inf"PRADEO

NX1600Series=ati2mtag_RV530" "C:\drivers\shared\video\ati_catalyst_6-11_xp-2k_dd

<many similar lines snipped>

8857.inf"PRO-Secondary=ati2mtag_RV410" "C:\drivers\shared\video\ati_catalyst_6-1

1_xp-2k_dd_37616\$OUTDIR\CX_38857.inf"PRADEON9600SE=ati2mtag_RV350" "C:\drivers\

shared\video\ati_catalyst_6-11_xp-2k_dd_37616\$OUTDIR\CX_38857.inf"PRADEON9600SE

-Secondary=ati2mtag_RV350" "C:\drivers\shared\video\ati_catalyst_6-11_xp-2k_dd_3

7616\$OUTDIR\CX_38857.inf"PRADEON9600XTBRAVO=ati2mtag_RV360" "C:\drivers\shared\

video\ati_catalyst_6-11_xp-2k_dd_37616\$OUTDIR\CX_38857.inf"PRADEON9600XTBRAVO-S

econdary=ati2mtag_RV360" "C:\drivers\shared\video\ati_catalyst_6-11_xp-2k_dd_376

16\$OUTDIR\CX_38857.inf" Job Completed

Press any key to End

I ran it against the MSD 8021 pack and had no issues except for the two missing lines that my original script pulled that Yzowl's did not. Having played with ATI drivers in the past and trying to pull info from their INFs I would have to agree with Yzowl that it is something in their INF, you might want to take a look and see if there is something strangely formattted about those INFs, "C:\drivers\shared\video\ati_catalyst_6-1 1_xp-2k_dd_37616\$OUTDIR\CX_38857.inf for instance.

Link to comment
Share on other sites

Except you missed two.

PCI\VEN_1039&DEV_1184=C:\D\M\SIS2\SISRAID4.inf

PCI\VEN_1039&DEV_1185=C:\D\M\SIS2\SISRAID4.inf

The only reason I can see for the missing lines is that SISRAID4.inf is UNICODE (UTF-16LE-BOM) and the others are probably ASCII (CP1252).

This may also be part of the cause of the errors reported by Haudy.

I have found many problems in the past attempting to work with unicode inf files!

<Edit>

Because I'm a nice guy, I've re-hashed the script.

The reason being that my previous attempt had used findstr which doesn't work with UNICODE.

Because it was a relatively simple fix, I decided to add a crude duplicate check in the routine too!

It's still not working without an odd error to console and certainly hasn't undergone any extensive tests but give it a shot and see if it produces workable results!

</Edit>

<Edit2>

I stated earlier in the thread that both Command Scripts could be improved, therefore here's a re-write of the 'other one'

@Echo off&Cls
If %1' EQU ' Goto INFO
For %%# In (%1) Do Echo:%%~$PATH:#
Goto :Eof
:INFO
Echo: Checks to see if a file is located within the system path:
Echo: %~n0 %%1
Echo: where %%1 is the file name to check for.&Echo:&Pause

</Edit2>

HwIDs.zip

Edited by Yzöwl
please see Edit tags!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...