Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Script: Scheduled task to defrag machines

Reply
 
Old 08-05-2008   #1 (permalink)
paulreims


 
 

Script: Scheduled task to defrag machines

Hello,
I am using this small script to automatically created scheduled tasks
via Group Policy on each one of our servers:

Set WshShell = WScript.CreateObject("WScript.Shell")
Dim fso, d, dc, i, Command
i=0
Set fso = CreateObject("Scripting.FileSystemObject")
Set dc = fso.Drives
For Each d in dc
i=i+1
If d.DriveType = 2 Then
Return = WshShell.Run("echo ""N""|schtasks.exe /create /SC WEEKLY /D
MON /TN Defrag" &i& " /TR ""defrag.exe "&d &" -f"" /ST 15:50:00 /SD
04/08/2008 /RU SYSTEM", 1, TRUE)
End If
Next
Set WshShell = Nothing

The echo ""N"" is necessary because on the second restart, Windows
asks to overwrite the scheduled task. If I omit this, the GPO works
fine the first time, but the after the second reboot, it prompts to
overwrite the task, so I manually have to confirm.....


When I run the script now with the echo ""N""|, I get an error "The
system cannot find the file specified".

My question is now, what's wrong with the "Wshshell.run"-command or is
there any possibility like a "/N" to confirm that I do not want to
overwrite the scheduled task....

Best regards
PR

My System SpecsSystem Spec
Old 08-05-2008   #2 (permalink)
Pegasus \(MVP\)


 
 

Re: Script: Scheduled task to defrag machines

Check the many replies to your post in the Server newsgroup
and have a look here about the merits of cross-posting:
http://www.blakjak.demon.co.uk/mul_crss.htm


<paulreims@xxxxxx> wrote in message
news:98e63574-395f-4b0d-8cb8-11ddc5b407d9@xxxxxx
Quote:

> Hello,
> I am using this small script to automatically created scheduled tasks
> via Group Policy on each one of our servers:
>
> Set WshShell = WScript.CreateObject("WScript.Shell")
> Dim fso, d, dc, i, Command
> i=0
> Set fso = CreateObject("Scripting.FileSystemObject")
> Set dc = fso.Drives
> For Each d in dc
> i=i+1
> If d.DriveType = 2 Then
> Return = WshShell.Run("echo ""N""|schtasks.exe /create /SC WEEKLY /D
> MON /TN Defrag" &i& " /TR ""defrag.exe "&d &" -f"" /ST 15:50:00 /SD
> 04/08/2008 /RU SYSTEM", 1, TRUE)
> End If
> Next
> Set WshShell = Nothing
>
> The echo ""N"" is necessary because on the second restart, Windows
> asks to overwrite the scheduled task. If I omit this, the GPO works
> fine the first time, but the after the second reboot, it prompts to
> overwrite the task, so I manually have to confirm.....
>
>
> When I run the script now with the echo ""N""|, I get an error "The
> system cannot find the file specified".
>
> My question is now, what's wrong with the "Wshshell.run"-command or is
> there any possibility like a "/N" to confirm that I do not want to
> overwrite the scheduled task....
>
> Best regards
> PR

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Scheduled Task - States Task Ran - No Results Software
XP Defrag won't run, scheduled chkdsk .NET General
Scheduled defrag Vista performance & maintenance
Scheduled defrag Vista General
Scheduled programs, defrag. etc. auto run at 3:00 a.m.? Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46