programatically run Microsoft's DEFRAG utility

J

JohnNews

Folks:


Is there a way to Folks:


Is there a way to programatically (using DOS) run Microsoft's DEFRAG utility
?

I am using a Windows XP platform where in folder (C:\windows\system32\*.*)
the following DEFRAG files are present: DEFRAG.EXE, DFRG.MSC, DFRGNTFS.EXE

I have tried the following syntax without perfect success:

(1) START /wait C:\windows\system32\DFRGntfs.exe
(2) START /wait C:\windows\system32\DFRG.MSC
(3) START /wait C:\windows\system32\DEFRAG.EXE

Option (2) launches the Defrag windows inteface (GUI) but no actual defrag
starts.
Option (3) ... nothing happens even when switches v,a,f are used
Option (1) returns with this error message "command line operation of disk
defrag not supported"


Is there a way to programatically (using DOS) run Microsoft's DEFRAG utility
?
What am i missing in all this ?


?

I am using a Windows XP platform where in folder (C:\windows\system32\*.*)
the following DEFRAG files are present: DEFRAG.EXE, DFRG.MSC, DFRGNTFS.EXE

I have tried the following syntax without perfect success:

(1) START /wait C:\windows\system32\DFRGntfs.exe
(2) START /wait C:\windows\system32\DFRG.MSC
(3) START /wait C:\windows\system32\DEFRAG.EXE

Option (2) launches the Defrag windows inteface (GUI) but no actual defrag
starts.
Option (3) ... nothing happens even when switches v,a,f are used
Option (1) returns with this error message "command line operation of disk
defrag not supported"


Is there a way to programatically (using DOS) run Microsoft's DEFRAG utility
?
What am i missing in all this ?
 
W

Wadester

JohnNews said:
Is there a way to programatically (using DOS) run Microsoft's DEFRAG
utility ?

Here's a VBScript I used to use - you'll probably need to edit it for your
environment so that it selects the right disks to defrag. I haven;t used
this in a long time, so YMMV.

ws

===========================

set WshShell = CreateObject("WScript.Shell")
WshShell.Run "dfrg.msc", 3
WScript.Sleep 1000
While WshShell.AppActivate("Disk Defragmenter") = FALSE
wscript.sleep 1000
Wend
WshShell.AppActivate "Disk Defragmenter"
WScript.Sleep 200
WshShell.SendKeys "{TAB}{DOWN}{DOWN}"
WshShell.SendKeys "%A"
WScript.Sleep 200
WshShell.SendKeys "D"
While WshShell.AppActivate("Defragmentation Complete") = FALSE
wscript.sleep 5000
Wend
WshShell.AppActivate "Defragmentation Complete"
WScript.Sleep 200
WshShell.Sendkeys "{TAB}"
Wscript.Sleep 500
WshShell.Sendkeys "{ENTER}"
Wscript.Sleep 500
WshShell.AppActivate "Disk Defragmenter"
WshShell.Sendkeys "%{F4}"
 
D

Dave Patrick

Be aware that if some other process steals the focus while using sendkeys
programmatically that you may not be happy with the result.

--
Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft MVP [Windows NT/2000 Operating Systems]
http://www.microsoft.com/protect.

:
| Folks:
|
|
| Is there a way to Folks:
|
|
| Is there a way to programatically (using DOS) run Microsoft's DEFRAG
utility
| ?
|
| I am using a Windows XP platform where in folder (C:\windows\system32\*.*)
| the following DEFRAG files are present: DEFRAG.EXE, DFRG.MSC,
DFRGNTFS.EXE
|
| I have tried the following syntax without perfect success:
|
| (1) START /wait C:\windows\system32\DFRGntfs.exe
| (2) START /wait C:\windows\system32\DFRG.MSC
| (3) START /wait C:\windows\system32\DEFRAG.EXE
|
| Option (2) launches the Defrag windows inteface (GUI) but no actual defrag
| starts.
| Option (3) ... nothing happens even when switches v,a,f are used
| Option (1) returns with this error message "command line operation of disk
| defrag not supported"
|
|
| Is there a way to programatically (using DOS) run Microsoft's DEFRAG
utility
| ?
| What am i missing in all this ?
|
|
| ?
|
| I am using a Windows XP platform where in folder (C:\windows\system32\*.*)
| the following DEFRAG files are present: DEFRAG.EXE, DFRG.MSC,
DFRGNTFS.EXE
|
| I have tried the following syntax without perfect success:
|
| (1) START /wait C:\windows\system32\DFRGntfs.exe
| (2) START /wait C:\windows\system32\DFRG.MSC
| (3) START /wait C:\windows\system32\DEFRAG.EXE
|
| Option (2) launches the Defrag windows inteface (GUI) but no actual defrag
| starts.
| Option (3) ... nothing happens even when switches v,a,f are used
| Option (1) returns with this error message "command line operation of disk
| defrag not supported"
|
|
| Is there a way to programatically (using DOS) run Microsoft's DEFRAG
utility
| ?
| What am i missing in all this ?
|
|
|
 
T

Torgeir Bakken (MVP)

JohnNews said:
Is there a way to programatically (using DOS) run Microsoft's DEFRAG utility

Hi

E.g.

defrag.exe <volume> -f

For more help, run defrag.exe -? in a command prompt.


In the link below you will find the following vbscripts (that runs defrag.exe):


defrag_all.vbs - Defrag All Hard Drives - Can be run as a scheduled task
Does not create an error log

defrag_all2.vbs - Defrag All Hard Drives - Can be run as a scheduled task
Creates an error log and displays the error log when complete.

http://www.dougknox.com/utility/scripts_desc/defrag_all.htm
 
P

Paul R. Sadowski

This is what I do as a scheduled task (dfrag.cmd):
@echo off
rem min
echo %DATE% %TIME% >> c:\logs\defrag.log
for %%c in (c d e f) do %WINDIR%\system32\defrag.exe %%c: >>
c:\logs\defrag.log 2>&1
 
J

JohnNews

Paul:


I am familiar with (FOR ... IN ... DO) compound command.

Do you think that the basic DEFRAG command
[[(%WINDIR%\system32\defrag.exe)]] can be launched from a single machine to
run on all machines of my small home network using the
(FOR ... IN ... DO) clause.

If this is possible, what would the syntax be to run the DEFRAG command
across a small windows network using FOR ... IN ... DO.



Thanks again,
John.
 
T

Torgeir Bakken (MVP)

JohnNews said:
Do you think that the basic DEFRAG command
[[(%WINDIR%\system32\defrag.exe)]] can be launched from a single machine to
run on all machines of my small home network using the
(FOR ... IN ... DO) clause.

If this is possible, what would the syntax be to run the DEFRAG command
across a small windows network using FOR ... IN ... DO.

Hi

Defrag.exe does not support remote computers, but you might be able to use
PsExec or Beyondexec to run Defrag.exe on remote computers:

Take a look at PsExec.exe in the free PsTools suite, found at
http://www.sysinternals.com

Another freeware program with similar merits to PsExec is Beyondexec.
http://www.beyondlogic.org/consulting/remoteprocess/BeyondExec.htm

Beyondexec also have multiple computer functionality.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

error when running defrag from W explorer 1
Defrag 3
How do I schedule Disk Defrag? 1
XP defrag gone? 1
Q: Scheduling Defrag (GUI) 3
Defrag Automatic 5
Defrag 4
WinXP Defrag grabbing resources 3

Top