Delete defined subfolders with exceptions

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
david.lynch
Posts: 13
Joined: 08 Jul 2012 21:00

Delete defined subfolders with exceptions

#1 Post by david.lynch » 09 Aug 2012 17:43

Hello everyone! :)

I have a script to install a custom Windows Live Messenger after cleaning many data leftovers, eliminating related issues.

This script searches for occurrences of folders 'Contacts', 'Windows Live Contacts' and 'MSN Messenger' and deletes them, taking the 'Documents and Settings' as base folder. I could use %USERPROFILE% environment variable here, but how get a directory before that? usually leftovers are on many profiles.

Also, the way it is, it is searching inside the 'My documents' folder too, which should be an exception. How accomplish that since 'My documents' can have any name? Probably get that info from registry or using a tool written by some of you, but how exactly?

Please, if you have any suggestions to improve this script, let me know!

Best regards & Image


Code: Select all

@echo off
setlocal
pushd "%~dp0"

taskkill /f /im msnmsgr.exe /im wlcomm.exe

sleep 1

msizap.exe TW! {ED00D08A-3C5F-488D-93A0-A04F21F23956}
msizap.exe TW! {B5ED7AB0-3838-4389-8549-7C8E22DD48F4}
msizap.exe TW! {22B775E7-6C42-4FC5-8E10-9A5E3257BD94}
msizap.exe TW! {A1F66FC9-11EE-4F2F-98C9-16F8D1E69FB7}

if /i %processor_architecture% equ x86 (set wlp="%ProgramFiles%\Windows Live") else (set wlp="%SystemDrive%\Program files (x86)\Windows Live")

attrib -r -h -s %wlp% /d /s
rd /s /q %wlp%

set ds=C:\Documents and Settings
for /f "tokens=*" %%g in ('dir /b /a /ad /s "%ds%\Contacts"') do attrib -r -h -s "%%g" /d /s
for /f "tokens=*" %%g in ('dir /b /a /ad /s "%ds%\Contacts"') do rd "%%g" /s /q
for /f "tokens=*" %%g in ('dir /b /a /ad /s "%ds%\Windows Live Contacts"') do attrib -r -h -s "%%g" /d /s
for /f "tokens=*" %%g in ('dir /b /a /ad /s "%ds%\Windows Live Contacts"') do rd "%%g" /s /q
for /f "tokens=*" %%g in ('dir /b /a /ad /s "%ds%\Messenger"') do attrib -r -h -s "%%g" /d /s
for /f "tokens=*" %%g in ('dir /b /a /ad /s "%ds%\Messenger"') do rd "%%g" /s /q
for /f "tokens=*" %%g in ('dir /b /a /ad /s "%ds%\MSN Messenger"') do attrib -r -h -s "%%g" /d /s
for /f "tokens=*" %%g in ('dir /b /a /ad /s "%ds%\MSN Messenger"') do rd "%%g" /s /q

start /wait .\setup\crt.msi
start /wait .\setup\dw20shared.msi
start /wait .\setup\Contacts.msi
start /wait .\setup\SegoeFont.msi
start /wait .\setup\Messenger.msi

pause

popd
exit

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

Re: Delete defined subfolders with exceptions

#2 Post by foxidrive » 09 Aug 2012 18:16

Can you query the registry entries for the program and find the definite locations from there?

david.lynch
Posts: 13
Joined: 08 Jul 2012 21:00

Re: Delete defined subfolders with exceptions

#3 Post by david.lynch » 10 Aug 2012 16:42

This is a nice solution for the current registry settings, but (many!) leftovers from previous versions can exist without any registry relation.

Each Windows Live Messenger version has his own folders locations and names; so a folder search really must be done.

Post Reply