?
Solved

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

Posted on 2007-11-26
9
Medium Priority
?
654 Views
Last Modified: 2009-07-18
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
Comment
Question by:hemightbeagiant
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 5

Expert Comment

by:GregMoseley
ID: 20356680
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
 
LVL 31

Expert Comment

by:merowinger
ID: 20356711
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
 
LVL 4

Expert Comment

by:SudburyComputer
ID: 20360104
You can also incorporate the windows tool cleanmgr by using its command line interface:

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

0
Plug and play, no additional software required!

The ATEN UE3310 USB3.1 Gen1 Extender Cable allows users to extend the distance between the computer and USB devices up to 10 m (33 ft). The UE3310 is a high-quality, cost-effective solution for professional environments such as hospitals, factories and business facilities.

 

Author Comment

by:hemightbeagiant
ID: 20364481
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
 

Author Comment

by:hemightbeagiant
ID: 20364493
To be clear the actual error message is "The system cannot find the path specified"

Thanks in advance.

0
 
LVL 5

Accepted Solution

by:
GregMoseley earned 2000 total points
ID: 20625950
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
 
LVL 5

Expert Comment

by:GregMoseley
ID: 20625961
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
 
LVL 12

Expert Comment

by:John Griffith
ID: 24324557
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a collection of issues that people face from time to time and possible solutions to those issues. I hope you enjoy reading it.
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question