Tech Support Guy banner
Not open for further replies.
1 - 5 of 5 Posts

· Registered
61 Posts
Discussion Starter · #1 ·
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 %EDOSWNAME%=ail00003240053

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?

· Registered
61 Posts
Discussion Starter · #5 ·
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

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

'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

'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...
1 - 5 of 5 Posts
Not open for further replies.