1.

Solve : Need Batch file assistance?

Answer»

I am requesting ASSISTANCE with a batch file I can't SEEM to get working on XP or Windows 7. Below is the contents of the batch file. The main goal of the batch file is to delete some items from several different locations whether it be on Windows 7 or XP Pro.
On Windows XP, I get the following result when run from a command prompt:
"Windows XP or prior detected. and was unexpected at this time."
On Windows 7, I get the following result when run from a command prompt:
"Windows 7 detected. in was unexpected at this time."
Thanks for any assistance.

@echo off
IF EXIST "%userprofile%\APPDATA" (
ECHO Windows 7 Detected.
SET ProfileBase=%SystemDrive%\Users
SET AppDirL=APPDATA\Local
) ELSE (
ECHO Windows XP or prior detected.
SET ProfileBase=%SystemDrive%\Documents and Settings
SET AppDirR=All Users\Start Menu\Programs\Startup
)



IF EXIST "%userprofile%\APPDATA" (
FOR /R %ProfileBase%\%%G in (.) DO del "%%G\QuickMate.lnk"
FOR /R %ProfileBase%\%%G in (.) DO del "%%G\CX.ht"
) ELSE (
del "%ProfileBase%\%AppDirR%\QuickMate.lnk"
del "%ProfileBase%\%AppDirR%\CX.ht"
)


FOR /R %ProfileBase%\ %%G in (.) DO del "%%G\QuickMate.lnk"
FOR /R %ProfileBase%\ %%G in (.) DO del "%%G\CX.ht"

Insert a space before %%G

From the FOR help (type FOR /? at the prompt)

FOR /R [[drive:]path] %variable IN (set) DO command [command-parameters]

See the space before %variable? This is compulsory in all FOR variations.


I have not tried this on XP

On Windows 7 the modified script attempts to delete a shortcut called "QuickMate.lnk" from every FOLDER under every user's Appdata and you get hundreds or thousands of messages like these. It didn't get as far as trying to delete all the non-existent CX.ht files because I stopped it.

Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Device Metadata\dmrccache\en-US\b23e9717-e78f-4c14-97b3-6418c327b3b8\Wind
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds\Feeds for United Kingdom~\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds\Microsoft Feeds~\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds\{5588ACFD-6436-411B-A5CE-666AE6A92D3D}~\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds\{5588ACFD-6436-411B-A5CE-666AE6A92D3D}~\WebSlices~\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds Cache\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds Cache\2IA0GS01\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds Cache\51K0ZC2L\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds Cache\6BKUTNB7\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds Cache\BPE2BTL4\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds Cache\DBFSPX48\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds Cache\PO52DLB9\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds Cache\S9635VN1\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\Feeds Cache\Y96IAOW4\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\FORMS\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\IME12\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\IMJP12\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\IMJP8_1\QuickMate.lnk
Could Not Find C:\Users\Rutabaga999\Local Settings\Microsoft\IMJP9_0\QuickMate.lnk



Suggestion:

@echo off
IF EXIST "%userprofile%\APPDATA" (
ECHO Windows 7 Detected.
SET ProfileBase=%SystemDrive%\Users
SET AppDirL=APPDATA\Local
) ELSE (
ECHO Windows XP or prior detected.
SET ProfileBase=%SystemDrive%\Documents and Settings
SET AppDirR=All Users\Start Menu\Programs\Startup
)

Echo PERFORMING task (please wait)

IF EXIST "%userprofile%\APPDATA" (
FOR /R %ProfileBase%\ %%G in (.) DO if exist "%%G\QuickMate.lnk" del "%%G\QuickMate.lnk"
FOR /R %ProfileBase%\ %%G in (.) DO if exist "%%G\CX.ht" del "%%G\CX.ht"
) ELSE (
if exist "%ProfileBase%\%AppDirR%\QuickMate.lnk" del "%ProfileBase%\%AppDirR%\QuickMate.lnk"
if exist "%ProfileBase%\%AppDirR%\CX.ht" del "%ProfileBase%\%AppDirR%\CX.ht"
)

Echo Done

Pause



Discussion

No Comment Found