# defrag.bat



## paradox365 (Nov 5, 2003)

I am having difficulty with these batch files so I was wondering if 
I can get some help.
I am trying to create three different batch files that will do the following.

I have a .vbs script that will defrag 30 computers remotely and 
would like it to copy the .vbs script and run on each individual pc.
using the at command. Within this batch file I want to also create a at command that will allow each defrag job to run interactively.

I have another batch file that I want the at command to run command line defrag utility with the analyze option and export the results to log file.

I have the third batch file to run command line defrag utiltiy with analyze option and export results to log file 2.


so it goes like this-defrag.bat will include the actual job that will be ran on the remote PC's, this is what I have so far...

@echo off
rem this batch file program defrags users hard drives on remote desktops.
rem It is named defrag.bat
Rem ail00003240053
set %AT RUNTIME%= TIME TO RUN DEFRAG
SET %EDOSWNAME%=ail00003240053
REM COPY DEFRAG.VBS \\%EDOWSNAME%\ %SYSTEMDRIVE%


C:\>defrag c: -a -v > defrag.log


C:\>at \\ail000003240053 12:02 /INTERACTIVE %systemdrive%\defrag.vbs Added a new job with job ID = 1

Can anyone tell me what I am doing wrong with the syntax in this first batch job?

Also how do I write the batch job for the other two jobs
I want to create?

Can anyone help me?


----------



## mobo (Feb 23, 2003)

http://techrepublic.com.com/5129-6288-10246303.html


----------



## paradox365 (Nov 5, 2003)

Unfortuately that batch job has to have admin privileges for it to
work...any other suggestions?


----------



## mobo (Feb 23, 2003)

More Batch files here  as well as one for defragging.


----------



## paradox365 (Nov 5, 2003)

thanks for the information, I have a question I have the script
that will allow me to run a defrag below without admin rights I am just confused with syntax that goes with it to configure the batch file.

I have a file called defrag.vbs that will run on a remote computer
in conjunction with the "AT" command.

Shell script

'This script launches defrag and sends keys to the UI in order to automate the defrag
'process.

set WshShell = CreateObject("WScript.Shell")

'Launch Defrag from the command line and wait for a second
WshShell.Run "dfrg.msc"
WScript.Sleep 1000

'Wait until the application has loaded - Check every second
While WshShell.AppActivate("Disk Defragmenter") = FALSE
wscript.sleep 1000
Wend

'Bring the application to the foreground
WshShell.AppActivate "Disk Defragmenter"
WScript.Sleep 200

'Send an ALT-A key to bring down the degrag menu
WshShell.SendKeys "%A"
WScript.Sleep 200

'Send a D to start the defrag
WshShell.SendKeys "D"

'Wait until the defrag is completed - Check for window every 5 seconds
While WshShell.AppActivate("Defragmentation Complete") = FALSE
wscript.sleep 5000
Wend

'Bring the msgbox to the foreground
WshShell.AppActivate "Defragmentation Complete"
WScript.Sleep 200

'Send a tab key to move the focus from View Report button to the Close Button
WshShell.Sendkeys "{TAB}"
Wscript.Sleep 500

'Send key to Close the Defragmentation Complete window
WshShell.Sendkeys "{ENTER}"
Wscript.Sleep 500

'Send and ALT-F4 to Close the Defrag program
WshShell.Sendkeys "%{F4}"

Now if you use this in conjunction with this command

C:\>at \\ail000003240001 8:35 /interactive %systemdrive%\defrag.vbs

it will work, I just need to have the at command line put into a batch to run remotely.

Thanks for the help...


----------

