• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 659
  • Last Modified:

Need a bat file to prep Windows XP Systems for Virus Scans

Hello Experts,

The following bat file is used to remove temp files and prep a hard drive to be scanned for viruses.  I was hoping that it could be looked at to verify that all temp directories are being cleared and automated if possible.
I remember writing a bat file that would clear the contents of a folder automatically but my memory escapes me as it was a long time ago.  

Thank you
@echo off
echo This batch file will prepare the computer for a virus scan.
pause
 
echo Remove unnecessary programs
rem Opens add/remove programs
pause
%systemroot%\system32\appwiz.cpl
echo Programs cleaned
 
cls
 
echo Remove unnecessary startup files
rem Starts msconfig
pause
cd ..
cd "Delete Me"
autoruns.exe
c:
cd %systemroot%\pchealth\helpctr\binaries
msconfig.exe
 
cd %systemroot%\prefetch
del *.*
pause
 
cls
echo Removing temporary files.
explorer %systemroot%\temp
 
explorer C:\Documents and Settings\Administrator\Local Settings\Temp
 
explorer C:\Documents and Settings\Administrator\local settings\temporary internet files\content.ie5
 
explorer C:\Documents and Settings\default user\Local Settings\Temp
 
explorer C:\Documents and Settings\default user\local settings\temporary internet files\content.ie5
 
explorer %userprofile%\Local Settings\Temp
 
explorer %userprofile%\local settings\temporary internet files\content.ie5
 
echo Done Deleting Files?
pause
 
echo Empty the Recycle Bin
pause
 
cls
echo Disable System Restore.
rem Executes clearing of system restore. 
%systemroot%\system32\sysdm.cpl
cls
echo System restore cleared.
 
echo Your computer is now ready for a virus scan.
pause

Open in new window

0
hemightbeagiant
Asked:
hemightbeagiant
1 Solution
 
GregMoseleyCommented:
It looks like you just need to use del *.* /f /a /q swithces to remove files from the folders without prompting unless I am missing the question.

Currently your script is running:
explorer C:\Documents and Settings\Administrator\Local Settings\Temp
which will launch an explorer window - do you then select all and delete?

If so, replace this line with:
del C:\Documents and Settings\Administrator\Local Settings\Temp\*.* /f /a /q
this will delete everything in the folder and subfolders.
0
 
merowingerCommented:
what about this?

@echo off
rd %temp% /s /q
rd %tmp% /s /q
rd "%userprofile%\Lokale Einstellungen\Temporary Internet Files" /s /q
rd "%userprofile%\Lokale Einstellungen\Verlauf" /s /q
rd "%userprofile%\Cookies" /s /q
rd "%userprofile%\Recent" /s /q
0
 
SudburyComputerCommented:
You can also incorporate the windows tool cleanmgr by using its command line interface:

http://support.microsoft.com/kb/315246

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
hemightbeagiantAuthor Commented:
It is close with GregMosely's option.  I also reading Sudbury's idea on Microsoft's website.  I think if the bat file would not give an error finding the file specified or if the cleanup manager option had the proper syntax, either could work.  What I am looking for is not to have to delete the temp files from the folders manually as explorer opens them for me, I was hoping this could be automated.
Here is an example of the change that the system cannot find the files now:
echo Removing temporary files.
del %systemroot%\temp\*.* /f /a /q
 
del C:\Documents and Settings\Administrator\Local Settings\Temp\*.* /f /a /q
 
del C:\Documents and Settings\Administrator\local settings\temporary internet files\content.ie5\*.* /f /a /q
 
del C:\Documents and Settings\default user\Local Settings\Temp\*.* /f /a /q

del C:\Documents and Settings\default user\local settings\temporary internet files\content.ie5\*.* /f /a /q
 
del %userprofile%\Local Settings\Temp\*.* /f /a /q
 
del %userprofile%\local settings\temporary internet files\content.ie5\*.* /f /a /q
 
echo Done Deleting Files?
pause

Cheers,

Scott
0
 
hemightbeagiantAuthor Commented:
To be clear the actual error message is "The system cannot find the path specified"

Thanks in advance.

0
 
GregMoseleyCommented:
Sorry - just found this post at the bottom of my queue.

This will be caused by not wrapping the lines in quotes..

Try this:

echo Removing temporary files.
del %systemroot%\temp\*.* /f /a /q
 
del "C:\Documents and Settings\Administrator\Local Settings\Temp\*.*" /f /a /q
 
del "C:\Documents and Settings\Administrator\local settings\temporary internet files\content.ie5\*.*" /f /a /q
 
del "C:\Documents and Settings\default user\Local Settings\Temp\*.*" /f /a /q
 
del "C:\Documents and Settings\default user\local settings\temporary internet files\content.ie5\*.*" /f /a /q
 
del "%userprofile%\Local Settings\Temp\*.*" /f /a /q
 
del "%userprofile%\local settings\temporary internet files\content.ie5\*.*" /f /a /q
 
echo Done Deleting Files?
pause

Open in new window

0
 
GregMoseleyCommented:
You could also use an IF statement... Example in Code Snippet:

But I have just tested the script above and you don't get any "The system cannot find the path specified" messages, but you will probably get "The process cannot access the file because it is being used by another process." messages for open files.

Also, think of adding @Echo Off to line 2. This will tidy the output screen up for the users.

IF EXIST /I %systemroot%\temp\*.* (
    del %systemroot%\temp\*.* /f /a /q /s
) ELSE (
    echo No Files to remove in %systemroot%\Temp\
)

Open in new window

0
 
John GriffithCommented:
Those getting the error "The system cannot find the path specified"  may have an invalid charachter  (to batch files) in their user name
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now