Batch File - To Find and Uninstall any existance µTorrent.exe on a PC

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
zzaacckk007
Posts: 2
Joined: 02 Feb 2016 10:33

Batch File - To Find and Uninstall any existance µTorrent.exe on a PC

#1 Post by zzaacckk007 » 03 Feb 2016 07:53

I am new here and I am some what of a novice in batch.

I manage about 10,000 PC's via Microsoft InTune and I have found that around 500 of them have uTorrent installed and I need to remove it because of uTorrent's capabilities and security risk.

Basically what I am wanting to do is search the entire C:/ Drive for the "µTorrent.exe", Find it, Uninstall it, Delete any existence that it was ever there and keep looping through until all of the µTorrent related files are deleted. And Possibly remove any entry from the registry if possible.

I can run all of these commands in A CMD window just fine, so I am thinking it is a format error, so when trying to compile them all in batch it doesn't seem to complete after the:

.

Code: Select all

Call %p% /Uninstall /S /Q 
Echo %p%


.

Then it fails.

.

BTW I can not use WMIC to uninstall the software because of where uTorrent installs itself.

.

I am going to post a little info I have found on the subject:

HKCU\Software\uTorrent

HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\µTorrent µTorrent /forceuninstall

Display Name: µTorrent

Version: 3.4.5.41628

Install Location:%APPDATA%\Roaming\uTorrent

Publisher: Bit Torrent Inc.

Uninstall String: "%APPDATA%\Roaming\uTorrent\uTorrent.exe" /UNINSTALL

Registry Location: Computer\HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\µTorrent

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\uTorrent

File location of uTorrent.exe C:\Users\Cricketadmin\AppData\Roaming\uTorrent

Remove for uTorrent client: Delete the exe: delete users\%Users\appdata\roaming\utorrent

C:/%USER%\AppData\Roaming\uTorrent\uTorrent.exe C:\Program Files\uTorrent\utorrent.exe

.

Dir /S C:*µTorrent.exe <--- will display any instance of µTorrent.exe on the entire c:/

.

Below I have posted what I have compiled so far:

.

Code: Select all

@echo OFF
CLS
TITLE Find and Uninstall µTorrent.exe
setlocal ENABLEDELAYEDEXPANSION
setlocal ENABLEEXTENSIONS
REM This Batch Program will Find and Uninstall µTorrent.exe
GoTo :LOOP1
:LOOP1
REM This loop will search all of the C:/ to find the "µTorrent.exe" file, and Uninstall "µTorrent.exe" if found.
For /R C:\ %%A IN (*) Do IF "%%~nxA"=="utorrent.exe" Set p=%%~dpnxA
IF DEFINED p (
   Echo %p%
   Call %p% /Uninstall /S /Q
   Echo %p%
   DEL /F /S /Q %p%
   Echo %p%
   GoTo :LOOP1
) Else (
   Echo File not found & EXIT CMD
   GoTo :LOOP2
)
:LOOP2
REM This loop will end the batch!
IF NOT EXIST %p% (
   Echo %p% File not found & EXIT CMD
) ELSE (
   Echo %p%
)
ENDLocal
EXIST /B
EXIT Errorlevel
END

REM I also need to be able to delete the desktop icon <- this is a reminder to me.

Dir /S C:\*ipscan24.exe


zzaacckk007
Posts: 2
Joined: 02 Feb 2016 10:33

Re: Batch File - To Find and Uninstall any existance µTorrent.exe on a PC

#3 Post by zzaacckk007 » 08 Mar 2016 08:41

This is my Final Draft. Tested and works great.

Code: Select all

    

@Echo Off
CLS
TITLE Find and Uninstall Bad SoftWare
setlocal ENABLEDELAYEDEXPANSION
setlocal ENABLEEXTENSIONS
:Part1
SET "BAD=µTorrent.exe"
SET "Z="
For /f "delims=" %%A IN ('Dir /B /S "C:\*uTorrent.exe" 2^>NUL') Do Set Z=%%A
IF DEFINED Z (
   GoTo :Part2
) Else (
   GoTo :Part2
)
GoTo :Part2
:Part2
IF DEFINED Z (
   "!Z!" /UNINSTALL /S >nul 2>&1
   GoTo :Part1
) ELSE (
   GoTo :Part3
)
GoTo :Part3
:Part3
SET "Z="
For /F "delims=" %%A IN ('Dir /B /S "C:\*Torrent*" 2^>NUL') Do Set Z=%%A
IF DEFINED Z (
   Del /F /S /Q "!Z!" >nul 2>&1
   RD /S /Q "!Z!" >nul 2>&1
   GoTo :Part3
) Else (
   GoTo :Part4
)
GoTo :Part4
:Part4
ChDir /D C:\
For /F "delims=" %%A IN ('Dir /B /S "C:\users\*.TMP*" 2^>NUL') Do (
   Del /F /S /Q "%%A" >nul 2>&1
)
ChDir /D C:\
For /F "delims=" %%A IN ('Dir /B /S "C:\Windows\*.TMP*" 2^>NUL') Do (
   Del /F /S /Q "%%A" >nul 2>&1
)
ChDir /D C:\
For /F "delims=" %%A IN ('Dir /B /S "C:\*.TMP*" 2^>NUL') Do (
   Del /F /S /Q "%%A" >nul 2>&1
)
ChDir /D C:\
For /F "delims=" %%A IN ('Dir /B /S "C:\Windows\Temp\*.*" 2^>NUL') DO (
   Del /F /S /Q "%%A" >nul 2>&1
   RD /S /Q "C:\Windows\Temp\" >nul 2>&1
)
ChDir /D C:\
For /F "delims=" %%A IN ('Dir /B /S "C:\Windows\Prefetch\*.*" 2^>NUL') DO (
   Del /F /S /Q "%%A" >nul 2>&1
   RD /S /Q "C:\Windows\Prefetch\" >nul 2>&1
)
ChDir /D C:\
For /F "delims=" %%A IN ('Dir /B /S ^"C:\Users\%username%\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*^" 2^>NUL') DO (
   Del /F /S /Q "%%A" >nul 2>&1
   RD /S /Q "C:\Users\%username%\AppData\Local\Microsoft\Windows\Temporary Internet Files\" >nul 2>&1
)
ChDir /D C:\
For /F "delims=" %%A IN ('Dir /B /S "C:\%temp%" 2^>NUL') DO (
   Del /F /S /Q "%%A" >nul 2>&1
   RD /S /Q "C:\TEMP\" >nul 2>&1
)
ChDir /D C:\
DEL /F /S /Q %temp%\ >nul 2>&1
ChDir /D C:\
For /F "delims=" %%A IN ('Dir /B /S "C:\*.TMP*" 2^>NUL') DO (
   Del /F /S /Q "%%A" >nul 2>&1
)
ChDir /D C:\
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8 >nul 2>&1
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2 >nul 2>&1
:Part5
SET "R="
For /F "delims=" %%B IN ('Dir /B /S "C:\$Recycle.Bin\*" 2^>NUL') Do Set R=%%B
IF DEFINED R (
   Del /F /S /Q "!R!" >nul 2>&1
   RD /S /Q "!R!" >nul 2>&1
   GoTo :Part5
) Else (
   GoTo :Part6
)
:Part6
Set "RegKey=HKCR"
Set "SearchWord=*Torrent*"
For /F "tokens=*" %%A In ('REG QUERY "%RegKey%" /F "%SearchWord%" /S ^| Find /I "Key" ^| Sort') Do (
    For /F "tokens=* delims= " %%B In ("%%A") Do Set "Name=%%B"
    Set "Name=!Name!"
    For /F "delims=@" %%B In ("!Name!") Do (
      REG DELETE "!Name!" /F >nul 2>&1
    )
)
GoTo :Part7
:Part7
Set "RegKey=HKCU"
Set "SearchWord=*Torrent*"
For /F "tokens=*" %%A In ('REG QUERY "%RegKey%" /F "%SearchWord%" /S ^| Find /I "Key" ^| Sort') Do (
    For /F "tokens=* delims= " %%B In ("%%A") Do Set "Name=%%B"
    Set "Name=!Name!"
    For /F "delims=@" %%B In ("!Name!") Do (
      REG DELETE "!Name!" /F >nul 2>&1
    )
)
GoTo :Part8
:Part8
Set "RegKey=HKLM"
Set "SearchWord=*Torrent*"
For /F "tokens=*" %%A In ('REG QUERY "%RegKey%" /F "%SearchWord%" /S ^| Find /I "Key" ^| Sort') Do (
    For /F "tokens=* delims= " %%B In ("%%A") Do Set "Name=%%B"
    Set "Name=!Name!"
    For /F "delims=@" %%B In ("!Name!") Do (
      REG DELETE "!Name!" /F >nul 2>&1
    )
)
GoTo :Part9
:Part9
Set "RegKey=HKU"
Set "SearchWord=*Torrent*"
For /F "tokens=*" %%A In ('REG QUERY "%RegKey%" /F "%SearchWord%" /S ^| Find /I "Key" ^| Sort') Do (
    For /F "tokens=* delims= " %%B In ("%%A") Do Set "Name=%%B"
    Set "Name=!Name!"
    For /F "delims=@" %%B In ("!Name!") Do (
      REG DELETE "!Name!" /F >nul 2>&1
    )
)
GoTo :Part10
:Part10
Set "RegKey=HKCC"
Set "SearchWord=*Torrent*"
For /F "tokens=*" %%A In ('REG QUERY "%RegKey%" /F "%SearchWord%" /S ^| Find /I "Key" ^| Sort') Do (
    For /F "tokens=* delims= " %%B In ("%%A") Do Set "Name=%%B"
    Set "Name=!Name!"
    For /F "delims=@" %%B In ("!Name!") Do (
      REG DELETE "!Name!" /F >nul 2>&1
    )
)
GoTo :Part11
:Part11
ENDLocal
Exit /b %errorlevel%
END   
   

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

Re: Batch File - To Find and Uninstall any existance µTorrent.exe on a PC

#4 Post by foxidrive » 08 Mar 2016 14:26

I accept you're learning and I am being cheeky when I posted this:

This is an exceptionally thorough method of branching to the part2 label.

zzaacckk007 wrote:

Code: Select all

    
SET "Z="
For /f "delims=" %%A IN ('Dir /B /S "C:\*uTorrent.exe" 2^>NUL') Do Set Z=%%A
IF DEFINED Z (
   GoTo :Part2
) Else (
   GoTo :Part2
)
GoTo :Part2
:Part2




Your code has a number of things that are unwise and I'll try to explain why:

When using *.TMP* with the del command it can catch a number of files that aren't necessarily temporary files - and to give a random example there could be a file called "MSoffice.TMPB.english.exe" which would be deleted.

Here you are attempting to delete system folders - not a good idea.
RD /S /Q "C:\Windows\Temp\" >nul 2>&1
RD /S /Q "C:\Windows\Prefetch\" >nul 2>&1
RD /S /Q "C:\Users\%username%\AppData\Local\Microsoft\Windows\Temporary Internet Files\" >nul 2>&1



With these two lines: the first one is better than the line above where you delete "\Temporary Internet Files\" and it replaces it.
but the second is removing all cookies from the browser - what is the purpose of this?
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8 >nul 2>&1
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2 >nul 2>&1


With the recycle bin - you're attempting to delete a system folder again.
It's unwise to delete files in the recycle bin this way - you may find a system command to clear the recycle bin.


In all the registry editing lines your code has this section:
1) For /F "tokens=* delims= " %%B In ("%%A") Do Set "Name=%%B"
2) Set "Name=!Name!"
3) For /F "delims=@" %%B In ("!Name!") Do (
4) REG DELETE "!Name!" /F >nul 2>&1


Line 1) only removes leading spaces, and your initial for command has "tokens=*" which does that anyway.
So it does nothing.
Line 2) Doesn't change the variable at all.
So it does nothing.
Line 3) Changes the text when using %%B but then you don't use it.
So it does nothing.
Line 4) Can replace all those lines and simply be REG DELETE "%%A" /F >nul 2>&1



This code should essentially do the primary purpose of what your code is doing - to uninstall and delete all the torrent exe files.
You can see that the DIR commands have an added switch to find only files /A-D and folders /AD

But beware: when using *Torrent* you will also delete folders and registry keys with the word "torrential" in them, and other similar terms, so this needs a rethink also.


Code: Select all

@Echo Off
CLS
TITLE Find and Uninstall Bad SoftWare

For /f "delims=" %%A IN ('Dir /B /S /A-D "C:\*uTorrent.exe" 2^>NUL') Do (
   "%%A" /UNINSTALL /S >nul 2>&1
    Del /F /S /Q "%%A" >nul 2>&1
    )

For /F "delims=" %%A IN ('Dir /B /S /AD "C:\*Torrent*" 2^>NUL') Do (
    RD /S /Q "!Z!" >nul 2>&1
    )

REM if you want to delete .tmp files then you can use this to process all of c: drive in one command
REM Del /F /S /Q "c:\*.tmp" >nul 2>&1


Set "SearchWord=*Torrent*"
FOR %%Z in (
 HKCR
 HKCU
 HKLM
 HKU
 HKCC
) do (
    For /F "tokens=*" %%A In ('REG QUERY "%%Z" /F "%SearchWord%" /S ^| Find /I "Key" ^| Sort') Do (
      REG DELETE "%%A" /F >nul 2>&1
    )

sambul35
Posts: 192
Joined: 18 Jan 2012 10:13

Re: Batch File - To Find and Uninstall any existance µTorrent.exe on a PC

#5 Post by sambul35 » 08 Mar 2016 19:24



I'm somewhat new here too, could you explain what's your note purpose? Is it prohibited by forum rules or common practices to post a question on several forums to access broader audience? :wink:

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

Re: Batch File - To Find and Uninstall any existance µTorrent.exe on a PC

#6 Post by foxidrive » 09 Mar 2016 00:35

sambul35 wrote:Is it prohibited by forum rules or common practices to post a question on several forums to access broader audience? :wink:


Nah. It's just rude to post your question everywhere, and then never reply to anyone once you have your solution. <--- This is the most common method of asking for free help.

sambul35
Posts: 192
Joined: 18 Jan 2012 10:13

Re: Batch File - To Find and Uninstall any existance µTorrent.exe on a PC

#7 Post by sambul35 » 09 Mar 2016 08:59

I got it. :D Do agree with you, always frustrating to read something like "Its OK. I already found the solution"... and nothing to explain it. But sometime folks amend their posts later with more details as they become available, and at times they are bound by contracts or other circumstances to keep quiet. In any way, the OP posted an extensive solution to his problem here. Its an interesting psychological phenomena: while more experienced members can offer a "better" solution afterwards, useful for other readers, some OPs will still stay with the solution they originally found themselves, and therefore might not comment on other solutions posted thereafter, since they consider the issue resolved. I think what's suitable here is to find ways to inform others how exactly it was resolved.

Post Reply