1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Batch Script + ResHack + Pskill + Wmic to delete resources

Discussion in 'Programming' started by Cleptography, Sep 6, 2010.

  1. Cleptography

    Cleptography New Member

    Joined:
    Sep 2, 2010
    Messages:
    39
    Likes Received:
    7
    Trophy Points:
    0
    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
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83

Share This Page