Solved

Script to DEFRAG harddrive

Posted on 2007-11-15
9
1,556 Views
Last Modified: 2008-02-01
I want to schedule a weekly DEFRAG on our server's harddrive. I don't have a problem with scheduling the task but need to know the best way to implement this. My last experience with batch files was with DOS 6. I have seen various types of batch jobs for Server 2003 (.BAT, .CMD, .VBS) but don't understand the differences between them and which is the best to use.

What I want to do is stop IIS, run the defrag and then restart IIS. What is the command for the DEFRAG? What reccommedations?
0
Comment
Question by:DerekWatling
9 Comments
 
LVL 58

Expert Comment

by:tigermatt
ID: 20296707
Hi there

You would need to make a batch file (.BAT) with the following commands in it (see attached script)

I'm not quite sure why you want to stop and start the IIS service though.

Hope this helps
-tigermatt


net stop W3SVC

defrag C: /f

net start W3SVC

Open in new window

0
 
LVL 5

Accepted Solution

by:
pavaneeshkumar earned 90 total points
ID: 20296720
put following code in a batch file

REM Stop IIS Server
IISReset /stop

REM Do Defragmentation
defrag c: -v

REM START IIS Server
IISReset /stop
0
 
LVL 5

Expert Comment

by:pavaneeshkumar
ID: 20296727
IISReset is a command line utility shipped with IIS
 For more details on IISReset check this article

http://support.microsoft.com/kb/317584
0
 
LVL 5

Expert Comment

by:pavaneeshkumar
ID: 20296749
tigermatt:
as i understand W3SVC  (www) Service is a component of IIS stooping this is not going to stop the IIS Server.

Please correct if i m wrong.
0
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!

 

Author Comment

by:DerekWatling
ID: 20296926
The site is using a GIS system and MySql. I want to stop IIS so these files can be properly defraged. I will try this over the weekend when the site is quiet.
0
 
LVL 25

Assisted Solution

by:imitchie
imitchie earned 90 total points
ID: 20297268
in that case (mysql+iis), use the code far below. stop iis before mysql, but start it after
(note: net stop w3svc alone won't work, nor will net stop iisadmin, unless you knew all the iisadmin subcomponents to stop in sequence)

also in answer to cmd vs bat vs vbs, cmd and bat are the same and use the command shell, which is NOT the old dos command.com, but close in ways.  .vbs, .js are newer windows scripts using vbscript, javascript languages which can interact with windows objects, like Outlook, Excel, SQL etc.  Windows 2008/Vista come with Monad, which is even more powerful.
REM Stop IIS Server

IISReset /stop

net stop mysql
 

REM Do Defragmentation

defrag c: -v
 

REM START IIS Server

net start mysql

IISReset /stop

Open in new window

0
 
LVL 2

Assisted Solution

by:pinkisthenewblue
pinkisthenewblue earned 20 total points
ID: 20303767
N.B Don't use "chkdsk c: /f" - since this is a boot volume it will just prompt you to schedule one.
0
 
LVL 5

Expert Comment

by:pavaneeshkumar
ID: 20307077
please change  /stop in last line to /start

REM Stop IIS Server
IISReset /stop

REM Do Defragmentation
defrag c: -v

REM START IIS Server
IISReset /start
0
 

Author Comment

by:DerekWatling
ID: 20310643
Hadn't noticed that ;-) but I typed it in rather than copying and pasting so I had it right.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

So you have two Windows Servers and you have a directory/folder/files on one that you'd like to mirror to the other?  You don't really want to deal with DFS or a 3rd party solution like Doubletake. You can use Robocopy from the Windows Server 200…
Learn about cloud computing and its benefits for small business owners.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

20 Experts available now in Live!

Get 1:1 Help Now