?
Solved

Script to DEFRAG harddrive

Posted on 2007-11-15
9
Medium Priority
?
1,571 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
[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 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 360 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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
 

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Recently, I had the need to build a standalone system to run a point-of-sale system. I’m running this on a low-voltage Atom processor, so I wanted a light-weight operating system, but still needed Windows. I chose to use Microsoft Windows Server 200…
A quick step-by-step overview of installing and configuring Carbonite Server Backup.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

764 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