Parse a Text

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
booga73
Posts: 108
Joined: 30 Nov 2011 16:16

Parse a Text

#1 Post by booga73 » 06 Mar 2013 16:52

I have created a batch file that parses a registry key to file. There is though additional text that is parsed in my final results.

I would like to simply get the path with the executable minus any quotes or text surrounding the path and executable.

My initial code:

Code: Select all

@ECHO OFF

reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run > c:\temp1\RegQ.txt

more +3 c:\temp1\RegQ.txt > c:\temp1\RegQ1.txt


setlocal enableDelayedExpansion
>> C:\temp1\OutPut1.txt ( for /f "usebackq tokens=1,* delims= " %%a in ( "c:\temp1\RegQ1.txt" ) do (
      set "$vl=%%~b" &set "$vl=!$vl:* =!"
      echo.!$vl! ) )
exit


The end result of OutPut1.txt shows what I would like, but to clean up the preceding text and any text after the path/executable so that the final results is similiar to:
c:\<path of file>\<executable>

the query of the registry key can be different depending on which computer operating system is run on either a win7 or win8 box.

Is it possible to clean up the text that comes before and after the path?


This is the initial result I get from the output of OutPut1.txt :

C:\Program Files\IDT\WDM\sttray.exe
"C:\Program Files\Common Files\Java\Java Update\jusched.exe"
C:\Program Files\AirTight\SpectraGuard SAFE\WSAUI.exe /ar 1
"C:\Program Files\McAfee\VirusScan\SHSTAT.EXE" /STANDALONE
C:\Program Files\NVIDIA Corporation\nView\nwiz.exe /installquiet
rundll32.exe C:\Windows\system32\nvHotkey.dll,Start
"C:\Program Files\Renesas Electronics\USB 3.0 Host Controller Driver\Application\nusb3mon.exe"
"C:\Program Files\McAfee\Common Framework\udaterui.exe" /StartedFromRunKey
Auditor Tray Icon REG_SZ "C:\Program Files\McAfee\Policy Auditor Agent\PASysTray.exe"
Intrusion Prevention Tray REG_SZ "C:\Program Files\McAfee\Host Intrusion Prevention\FireTray.exe"
C:\Program Files\Intel\Intel(R) Rapid Storage Technology\IAStorIcon.exe
C:\Program Files\STMicroelectronics\AccelerometerP11\FF_Protection.exe
C:\Program Files\DellTPad\Apoint.exe
REG_SZ "C:\Program Files\Common Files\Adobe\ARM\1.0\AdobeARM.exe"
Speed Launcher REG_SZ "C:\Program Files\Adobe\Acrobat 10.0\Acrobat\Acrobat_sl.exe"
8.0 REG_SZ "C:\Program Files\Adobe\Acrobat 10.0\Acrobat\Acrotray.exe"

* =

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Parse a Text

#2 Post by foxidrive » 06 Mar 2013 23:17

This seems to work in Windows 8.

It uses the freeware GNUsed.

Code: Select all

@echo off
reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run | sed -e 1,2d -e "s/.*\(.:.*\.exe\).*/\1/I" >"file.txt"
pause

booga73
Posts: 108
Joined: 30 Nov 2011 16:16

Re: Parse a Text

#3 Post by booga73 » 07 Mar 2013 09:06

Not really familiar with SED. But for testing purposes, I did locate sed for windows and installed sed on win7 box

I ran the script introduced on win7 32-bit, but received the following error:

sed: can't read >file.txt: Invalid argument
Press any key to continue . . .

I'm not sure of sed; I have to install that in order to run the batch script.

v/r Booga73

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Parse a Text

#4 Post by foxidrive » 07 Mar 2013 09:13

Try it now. I had manually added ">file.txt" instead of >"file.txt"

booga73
Posts: 108
Joined: 30 Nov 2011 16:16

Re: Parse a Text

#5 Post by booga73 » 07 Mar 2013 09:56

that's pretty amazing results.

I can get the first line, (Default) REG_SZ , and the last 2 lines parsed, but I see in the output

NVHotkey REG_SZ rundll32.exe C:\Windows\system32\nvHotkey.dll,Start

there are 3 trailing tokens and at the end .. . ,Start

is that correctable with sed?

v/r Booga73

results:


(Default) REG_SZ
C:\Program Files\IDT\WDM\sttray.exe
C:\Program Files\Common Files\Java\Java Update\jusched.exe
C:\Program Files\AirTight\SpectraGuard SAFE\WSAUI.exe
C:\Program Files\McAfee\VirusScan Enterprise\SHSTAT.EXE
C:\Program Files\NVIDIA Corporation\nView\nwiz.exe
NVHotkey REG_SZ rundll32.exe C:\Windows\system32\nvHotkey.dll,Start
C:\Program Files\Renesas Electronics\USB 3.0 Host Controller Driver\Application\nusb3mon.exe
C:\Program Files\McAfee\Common Framework\udaterui.exe
C:\Program Files\McAfee\Policy Auditor Agent\PASysTray.exe
C:\Program Files\McAfee\Host Intrusion Prevention\FireTray.exe
C:\Program Files\Intel\Intel(R) Rapid Storage Technology\IAStorIcon.exe
C:\Program Files\STMicroelectronics\AccelerometerP11\FF_Protection.exe
C:\Program Files\Symantec\Symantec Endpoint Encryption Clients\Client Console\EAFRCliStart.exe
C:\Program Files\DellTPad\Apoint.exe
C:\Program Files\Common Files\Adobe\ARM\1.0\AdobeARM.exe
C:\Program Files\Adobe\Acrobat 10.0\Acrobat\Acrobat_sl.exe
C:\Program Files\Adobe\Acrobat 10.0\Acrobat\Acrotray.exe
C:\Program Files\ActivIdentity\ActivClient\acevents.exe
C:\Program Files\ActivIdentity\ActivClient\accrdsub.exe

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\OptionalComponents

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Parse a Text

#6 Post by foxidrive » 07 Mar 2013 10:15

Do you need to include the NVHotkey lines?

It doesn't have an program executable but calls a system file.

booga73
Posts: 108
Joined: 30 Nov 2011 16:16

Re: Parse a Text

#7 Post by booga73 » 07 Mar 2013 10:19

I agree, is it possible to omit that line using sed? :idea: :?:

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Parse a Text

#8 Post by foxidrive » 07 Mar 2013 10:25

Try this:

Code: Select all

@echo off
reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run | sed -e 1,2d -e /^NVHotkey/d -e "s/.*\(.:.*\.exe\).*/\1/I" >"file.txt"
pause

Post Reply