Solved

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

Posted on 2007-11-26
9
648 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 

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

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!

Question has a verified solution.

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

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.
When you try to extract and to view the contents of a Microsoft Update Standalone Package (MSU) for Windows Vista, you cannot extract the files from the MSU. Here we are going to explain how to extract those hotfix details without using any third pa…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

749 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