Windows Server - Scheduled task to defrag servers

Asked By paulreim
05-Aug-08 10:33 PM
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
Scripting.FileSystemObject
(1)
WScript.CreateObject
(1)
WScript.Shell
(1)
CreateObject
(1)
WshShell
(1)
Windows
(1)
Paulreims
(1)
  Meinolf Weber replied...
05-Aug-08 10:33 PM
Hello paulreims@gmail.com,

See the answer in microsoft.public.windows.group_policy and please do not
multipost, use crossposting.

http://www.blakjak.demon.co.uk/mul_crss.htm

Best regards

Meinolf Weber
Disclaimer: This posting is provided "AS IS" with no warranties, and confers
no rights.
** Please do NOT email, only reply to Newsgroups
** HELP us help YOU!!! http://www.blakjak.demon.co.uk/mul_crss.htm
Create New Account
help
when you made the PRF. ' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ' = = = = = = = = = = = = = = = = = DO NOT EDIT ANYTHING BELOW THIS SECTION = = = = = = = = = = = = = = = = ' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = intTest = 0 Set WshShell = CreateObject("WScript.Shell") Set WshNetwork = CreateObject("WScript.Network") Set objDomain = getObject("LDAP: / / rootDse") DomainString = objDomain.Get("dnsHostName") Set fso = CreateObject("Scripting.FileSystemObject") Set ObjEnv = WshShell.Environment("Process") Set objShell = CreateObject("Shell.Application") Set objSysInfo = CreateObject("ADSystemInfo") Set
forums.techarena.in / server-scripting / 1141820.htm http: / / forums.techarena.in Windows Server Scripting Discussions Scripting.FileSystemObject (1) WScript.CreateObject (1) MyFile.WriteLine (1) WScript.Shell (1) MyFile.Close (1) XP (1) I am no scripting guru, and I've never create an error log and display it '© Doug Knox - 4 / 13 / 2002 Option Explicit Dim WshShell, fso, d, dc, ErrStr(), Return, X, A(), MyFile, I, MyBox, Drive Set WshShell = WScript.CreateObject("WScript.Shell") Set fso = CreateObject("Scripting.FileSystemObject") X = 0 Set dc = fso.Drives
Thank you Windows Server Discussions DriveTypeCDROM (1) DriveTypeRAMDisk (1) DriveTypeRemovable (1) DriveTypeNetwork (1) WeekDayName (1) CreateObject (1) Hello Mr555, Check out this one, on a test machine first, as startup script 1 Const DriveTypeFixed = 2 Const DriveTypeNetwork = 3 Const DriveTypeCDROM = 4 Const DriveTypeRAMDisk = 5 Set FSO = CreateObject("Scripting.FileSystemObject") Set Drives = FSO.Drives For each Drive in Drives if Drive.DriveType = 2 then RunCmd Drive end if Next Sub RunCmd(DriveString) Set WshShell = WScript.CreateObject("WScript.Shell") RunString = "%comspec% / c echo " & WeekDayName(WeekDay(Now), True) & " " & Now & " " & DriveString Return = WshShell.Run(RunString