Solved

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

Posted on 2007-11-26
9
637 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
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
 

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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 500 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

706 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now