Runing defrag with a .BAT file

 
Post new topic   Reply to topic    Aprelium Forum Index -> Off Topic Discussions
View previous topic :: View next topic  
Author Message
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Thu Oct 27, 2005 7:17 pm    Post subject: Runing defrag with a .BAT file Reply with quote

Hello,

I wonder if anyone can help me out with this. I want to be able to defrag all the hard drives on my server simply by executing a .BAT file. I have used this for my bat file so far:

Code:
@echo off
echo Defragmentation
rem Remove the pause if wanted

defrag c:
defrag d:


but it goes into a loop of asking me to press any key. It doesnt actually do any defragging.

Can someone please post some code on how to do this? I tried with PHP but my interpreter is set for 30 seconds so when it has past 30 seconds it stops.

What I want is it to defrag drive c: then d: then e: etc but one after each other, not at the same time.

If anyone can help it would be greatly appriciated.
_________________
Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk
Back to top View user's profile Send private message Visit poster's website
Anonymoose
-


Joined: 09 Sep 2003
Posts: 2192

PostPosted: Thu Oct 27, 2005 7:25 pm    Post subject: Reply with quote

Did you happen to name the batch file "defrag.bat"? If you did, when you run it, the precedence will be given to the batch file as it's in the same directory, rather than the built in command defrag - causing the loop.

As an aside, Windows built in defrag sucks for speed. Consider O&O or Diskeeper Lite instead...
_________________

"Invent an idiot proof webserver and they'll invent a better idiot..."
Back to top View user's profile Send private message
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Thu Oct 27, 2005 7:29 pm    Post subject: Reply with quote

Yes I did name the file defrag.bat. I have had no speed issues with the windows defrag and I dont want to be downloading other programs to use.

Any help with getting my method working will be appriciated.
_________________
Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk
Back to top View user's profile Send private message Visit poster's website
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Thu Oct 27, 2005 7:50 pm    Post subject: Reply with quote

OK, forget my last post, im going to try Diskeeper. A friend has persuaded me because he uses it.
_________________
Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk
Back to top View user's profile Send private message Visit poster's website
168pin
-


Joined: 09 Mar 2005
Posts: 33

PostPosted: Thu Oct 27, 2005 7:53 pm    Post subject: Reply with quote

The Inquisitor wrote:
OK, forget my last post, im going to try Diskeeper. A friend has persuaded me because he uses it.


Yeah, I use it because it owns.
_________________
Boycott sigs.
Back to top View user's profile Send private message
Anonymoose
-


Joined: 09 Sep 2003
Posts: 2192

PostPosted: Thu Oct 27, 2005 8:03 pm    Post subject: Reply with quote

The Inquisitor wrote:
Yes I did name the file defrag.bat. I have had no speed issues with the windows defrag and I dont want to be downloading other programs to use.

Any help with getting my method working will be appriciated.


Your method would work just fine after changing the name from defrag.bat to anythingelse.bat - that was what I was explaining. If you name the batch file the same name as a Windows executable you want to run and do not specify a full path to the executable, the command interpreter will assume you want to run the batch file, and go into a loop.
_________________

"Invent an idiot proof webserver and they'll invent a better idiot..."
Back to top View user's profile Send private message
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Thu Oct 27, 2005 8:10 pm    Post subject: Reply with quote

Ah I see. I changed the name and it works. What a stupid thing for it to do though. I just downloaded Diskeeper and Im going to try that.
_________________
Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk
Back to top View user's profile Send private message Visit poster's website
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Thu Oct 27, 2005 8:29 pm    Post subject: Reply with quote

Diskeeper keeps crashing for me so I settled with the .bat method.

If anyone wants the code it is below...

Code:
@echo off
echo Automatic Defragmentation Started
rem Remove the pause if wanted
echo.
echo.

echo ----------------
echo Started C drive
echo ----------------
echo.
defrag c: -f
echo.
echo ----------------
echo Finished C drive
echo ----------------
echo.

echo ----------------
echo Started H drive
echo ----------------
echo.
defrag h: -f
echo.
echo ----------------
echo Finished H drive
echo ----------------
echo.

echo ----------------
echo Started K drive
echo ----------------
echo.
defrag k: -f
echo.
echo ----------------
echo Finished K drive
echo ----------------
echo.

echo.
echo Automatic Defragmentation Finished



A lot of it isnt necessary but it is nicely layed out like this.
_________________
Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk
Back to top View user's profile Send private message Visit poster's website
Anonymoose
-


Joined: 09 Sep 2003
Posts: 2192

PostPosted: Thu Oct 27, 2005 9:50 pm    Post subject: Reply with quote

An interesting time waster is to try and programatically find all existing fixed drives and iterate through defragging each of them rather than explicitly coding in drive letters.

'fsutil fsinfo drives' is an interesting command if you're bored :)

Alternatively, you can just use a VBS someone has already knocked up...

http://www.paulsadowski.com/WSH/defrag.htm
_________________

"Invent an idiot proof webserver and they'll invent a better idiot..."
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> Off Topic Discussions All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group