Batch Script + ResHack + Pskill + Wmic to delete resources

Cleptography's Avatar author of Batch Script + ResHack + Pskill + Wmic to delete resources
This is an article on Batch Script + ResHack + Pskill + Wmic to delete resources in Programming.
This .bat file utilizes ResHack.exe and Pskill or wmic which ever it can find.
The script deletes all the resources of a specified file. Save as .bat and run from the command line with no arguments to retrieve usage info.

Batch Script + ResHack + Pskill + Wmic to delete resources
--------------------------------------------------------------------
Code:
@echo off
 setlocal

:: Check command args
set arg=%1
if not defined arg goto :Usage

:: Check for resources
:Check for Wmic.exe or PsKill.exe
if exist "%systemroot%\system32\wbem\wmic.exe" (
	set WmiPath=%systemroot%\system32\wbem\wmic.exe
	set WmicExist=1& echo Wmic.exe found on the local users machine.
	goto :CheckResHack
) else (
if exist "wmic.exe" (
	set WmicExist=2& echo Wmic.exe found in the current path.
	goto :CheckResHack
) else (
if exist "pskill.exe" (
	set PsKill=1& echo Pskill.exe found in the current path.
) else (
	echo Wmic.exe nor PsKill.exe could be found.
	echo Unable to terminate services.exe
	echo The script will now execute.& goto :eof
)))
:CheckResHack
if exist "ResHacker.exe" (
	set ResHackExist=1& echo ResHacker.exe found in the current path.
	echo All needed files have been established.
	echo Now starting!!!& goto :RunScript
) else (
	echo ResHacker.exe was not found in the current path.
	echo This file is needed in order for this script to work.
	goto :eof
)

:RunScript
:: Kill services.exe
if [%WmicExist%]==[1] (
%WmiPath% process where name="services.exe" call terminate&& shutdown -a
)
if [%WmicExist%]==[2] (
wmic process where name="services.exe" call terminate&& shutdown -a
) else (
if [%PsKill%]==[1] pskill -t services.exe&& shutdown -a
)
:BeginShiftLoop
:: Delete resources
if [%1]==[] echo Finished!!!& goto :eof
ResHacker.exe -delete %~1, %~1,,,
shift
goto :BeginShiftLoop

:Usage
echo.USAGE:   %0 "Full Path and File Name"
echo.EXAMPLE: %0 "C:\WINDOWS\explorer.exe"
echo.NOTES:   Multiple programs may be specified using
echo.         Double quotes and separated by spaces.
goto :eof
Go4Expert Founder
4Oct2010,10:22   #2
shabbir's Avatar
If you liked this article do nominate this article for Article of the month - Sep 2010 Before 15th of October 2010.