0

I need to extract certain data from a registry key and output this data to separate files so that I can call another external program to perform functions on the output. I want to do this for all of the registry keys under HKLM\System\ControlSet001\Enum\USBSTOR(Unknown Name)(serial number) I then need it to extract the Friendly Name value.

I need it to do this one key at a time and then send the Serial number and friendly name to separate .txt files for each key so the final output looks something like -

001E0BB89D74BF4160004514&0 Kingston DT4000 G2 USB Device (stored in 1.txt)

50E549C6952EB1A00000002E&0Next Kingston DataTraveler 2.0 USB Device (2.txt)

At the moment I am using -

Reg query HKLM\System\ControlSet001\Enum\USBSTOR /s /v FriendlyName>>%~dp0Report.txt

This lists all the keys as -

HKEY_LOCAL_MACHINE\System\ControlSet001\Enum\USBSTOR\Disk&Ven_Kingston&Prod_DataTraveler_2.0&Rev_1100\50E549C6952EB1A00000002E&0 FriendlyName REG_SZ Kingston DataTraveler 2.0 USB Device

HKEY_LOCAL_MACHINE\System\ControlSet001\Enum\USBSTOR\Disk&Ven_Kingston&Prod_DT4000_G2&Rev_PMAP\001E0BB89D74BF4160004514&0 FriendlyName REG_SZ Kingston DT4000 G2 USB Device

Ive tried a for /f loop and researched elsewhere but no matter what I try I cant get it to work.

Any suggestions greatly appreciated.

Rich
  • 39
  • 2
  • Please show what you have tried! [Edit](http://stackoverflow.com/posts/39358008/edit) your question and post the code there! – aschipfl Sep 06 '16 at 21:23

1 Answers1

0

You have not provided information on the external program which is supposed to be performing functions on the output. You have also not provided the for loop you have tried. What I will provide therefore is an example script which may push you in the right direction, (this will write to a single file along side it):

@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion
For /F "Delims==" %%A In ('Set USB[ 2^>Nul') Do Set "%%A="
Set "n=101"
For /F "EOL=E Tokens=1,2*" %%A In (
    'Reg Query HKLM\System\ControlSet001\Enum\USBSTOR /S /V FriendlyName') Do (
    If "%%~nA" NEq "%%~A" (Call Set "USB[%%n:*1=%%]=%%~nA") Else (
        Call Call Set "USB[%%n:*1=%%]=%%%%USB[%%n:*1=%%]%%%% %%C"
        Set/A n+=1))
If %n% NEq 101 (>"%~dp0AllUSBs.log" 2>Nul Set USB[)
EndLocal
Exit/B
Compo
  • 36,585
  • 5
  • 27
  • 39