Findstr to Scan Text File for String or Compare Two Files

email me

Find a String in Text File

findstr /c:YourStringHere FileNameHere.txt && Echo TRUE || Echo FALSE

* you can change the echos to subroutines, and make this pretty powerful

 

Compare Two Files

The fastest method to diff two files is to use findstr command. It will compare and return the result to a new file.

findstr /vixg:C:\FILE1.txt C:\FILE2.txt > C:\FILE3.txt

Notes

/v : Prints only lines that do not contain a match.
/i : Specifies that the search is not to be case-sensitive.
/x : Prints lines that match exactly.
/g: file : Gets search strings from the specified file.

Remove All Spaces from Variable in Batch File

email me

This makes logic testing much easier

For /f “tokens=1,2 delims==” %%a in (‘findstr “Citrix Receiver Updater 4.2.0” guid.txt’) DO (
SET MyVar=%%b
SET MyVar=!MyVar: =!
ECHO !MyVar!
)

 

Others

Remove quotes:
SET Line=”C:\Program Files\”
SET Line=%Line:”=%
echo %Line% — will output: C:\Program Files\

Remove a trailing backslash:
SET Line=C:\Windows\
IF “%Line:~-1%”==”\” SET Line=%Line:~0,-1%
echo %Line% — will output: C:\Windows

Office KB Uninstalls

email me

My task was to uninstall specific KBs for Office products. I noticed the normal wusa.exe was not working, so I had to come up with another way to remove patches. The “package” info can be found in the registry, under the Uninstall key.

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
or
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall

rem Uninstalls specific KBs for Office Products

rem 2007
if exist “c:\Program Files\Microsoft Office\Office12\Excel.exe” (
Echo 2007
wusa /uninstall /kb:2984942 /quiet /norestart
Msiexec /package {90120000-0030-0000-0000-0000000FF1CE} /uninstall {FB9CFB27-DB51-440C-9225-F958A24555A9} /qn
)
if exist “c:\Program Files (x86)\Microsoft Office\Office12\Excel.exe” (
Echo 2007
wusa /uninstall /kb:2984942 /quiet /norestart
Msiexec /package {90120000-0030-0000-0000-0000000FF1CE} /uninstall {FB9CFB27-DB51-440C-9225-F958A24555A9} /qn
)
rem 2010
if exist “c:\Program Files\Microsoft Office\Office14\Excel.exe” (
Echo 2010
wusa /uninstall /kb:2910902 /quiet /norestart
Msiexec /package {90140000-0011-0000-0000-0000000FF1CE} /uninstall {6A1E6C95-CDE5-4E8C-A712-79C0985DAFE6} /qn
)

if exist “c:\Program Files (x86)\Microsoft Office\Office14\Excel.exe” (
Echo 2010
wusa /uninstall /kb:2910902 /quiet /norestart
Msiexec /package {90140000-0011-0000-0000-0000000FF1CE} /uninstall {6A1E6C95-CDE5-4E8C-A712-79C0985DAFE6} /qn
)
rem 2013
if exist “c:\Program Files\Microsoft Office\Office15\Excel.exe” (
Echo 2013
wusa /uninstall /kb:2910929 /quiet /norestart
Msiexec /package {90150000-0011-0000-1000-0000000FF1CE} /uninstall {5410DCA4-C8FD-4390-BFE9-8D683156803D} /qn
)

if exist “c:\Program Files (x86)\Microsoft Office\Office15\Excel.exe” (
Echo 2013
wusa /uninstall /kb:2910929 /quiet /norestart
Msiexec /package {90150000-0011-0000-1000-0000000FF1CE} /uninstall {5410DCA4-C8FD-4390-BFE9-8D683156803D} /qn
)

 

 

Not Used

rem msiexec /x {90140000-0011-0000-0000-0000000FF1CE} MSIPATCHREMOVE={6A1E6C95-CDE5-4E8C-A712-79C0985DAFE6}

rem HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{90140000-0011-0000-0000-0000000FF1CE}_Office14.PROPLUS_{6A1E6C95-CDE5-4E8C-A712-79C0985DAFE6}
rem HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\00004109110000000000000000F01FEC\Patches\59C6E1A65EDCC8E47A21970C89D5FA6E
rem wmic product where name=’Security Update for Microsoft Excel 2010 (KB2910902) 32-Bit Edition’ call uninstall
rem wmic product where “name like ‘Security Update for Microsoft Excel 2010 (KB2910902) 32-Bit Edition'” call uninstall