Solved

Script to DEFRAG harddrive

Posted on 2007-11-15
9
1,563 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
I guess it is not common knowledge to most Wintel engineers/administrators: If you have an SNMP-based monitoring system in your environment (and it's common to have SNMP or Syslog) it's reasonably easy to enable monitoring of the Windows Event logs,…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

867 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

19 Experts available now in Live!

Get 1:1 Help Now