Solved

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

Posted on 2007-11-26
9
652 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
Don't Miss ATEN at InfoComm 2017!

Visit booth #2167 to see the  new ATEN VM3200 32 x 32 Modular Matrix Switch. Other highlights include the VE8950 4K HDMI Over IP Extender, VS1912 12-Port DP Video Wall Media Player  and VK2100 ATEN Control System. Register now with Free Pass Code ATEN288!

 

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

This article summaries thoughts and ideas from two years of sustained use. It provides good reasoning to make the jump to Windows 10.
An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
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…

719 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