From: GreyWolf on
I am trying to write a script that will create a task to defrag a harddrive
on remote computers and prompt and mask the passwords. Here is what I have
done but it is not working correctly.

I do not have access to our GPO to do that way and they are a little touchy
about doing it that way as well.

Set fso = CreateObject("Scripting.FileSystemObject")
strComputerName = InputBox("Enter Computer Name to have task scheduled
on","Schedule Disk Defrag Task")
strUserName = Inputbox("Enter your Network ID in the form of Domain\UserID
please.","Schedule Disk Defrag Task")
Set objPassword = CreateObject("ScriptPW.Password")
WScript.StdOut.Write "Please enter your netword password:"
set strUserPW = objpassword
schedule = "SCHTASKS /Create /s strComputername /p strUserPW /SC monthly /TN
disk_defrag /TR ""c:\windows\system32\defrag.exe c: >>
c:\defrag_results.txt"" /RU system"
return = WshShell.Run(schedule, 1, True)
WScript.echo schedule

If return = 0 Then
WScript.Echo "the task was successfully created"
Else
WScript.Echo "there were problems creating the task"
End If


Any help would be greatly appreciate I am a newbie at this and I am trying
to muttle my way though this and learn at the same time.

From: Pegasus [MVP] on


"GreyWolf" <GreyWolf(a)discussions.microsoft.com> wrote in message
news:80CF7F64-5C85-47B9-816E-B63FDA102840(a)microsoft.com...
> I am trying to write a script that will create a task to defrag a
> harddrive
> on remote computers and prompt and mask the passwords. Here is what I
> have
> done but it is not working correctly.
>
> I do not have access to our GPO to do that way and they are a little
> touchy
> about doing it that way as well.
>
> Set fso = CreateObject("Scripting.FileSystemObject")
> strComputerName = InputBox("Enter Computer Name to have task scheduled
> on","Schedule Disk Defrag Task")
> strUserName = Inputbox("Enter your Network ID in the form of Domain\UserID
> please.","Schedule Disk Defrag Task")
> Set objPassword = CreateObject("ScriptPW.Password")
> WScript.StdOut.Write "Please enter your netword password:"
> set strUserPW = objpassword
> schedule = "SCHTASKS /Create /s strComputername /p strUserPW /SC monthly
> /TN
> disk_defrag /TR ""c:\windows\system32\defrag.exe c: >>
> c:\defrag_results.txt"" /RU system"
> return = WshShell.Run(schedule, 1, True)
> WScript.echo schedule
>
> If return = 0 Then
> WScript.Echo "the task was successfully created"
> Else
> WScript.Echo "there were problems creating the task"
> End If
>
>
> Any help would be greatly appreciate I am a newbie at this and I am trying
> to muttle my way though this and learn at the same time.

I have not tried it but perhaps the link below will help. Note also that
frequent defragging will not make any noticeable difference to the speed of
those PCs. You might spend a lot more time in getting this scheme to work
reliably than the time you save for your users.

http://blogs.technet.com/heyscriptingguy/archive/2005/09/06/how-can-i-remotely-start-an-interactive-process.aspx


From: BigDaddyJim on
On Apr 14, 5:36 pm, "Pegasus [MVP]" <n...(a)microsoft.com> wrote:
> "GreyWolf" <GreyW...(a)discussions.microsoft.com> wrote in message
>
> news:80CF7F64-5C85-47B9-816E-B63FDA102840(a)microsoft.com...
>
>
>
>
>
> > I am trying to write a script that will create a task to defrag a
> > harddrive
> > on remote computers and prompt and mask the passwords.  Here is what I
> > have
> > done but it is not working correctly.
>
> > I do not have access to our GPO to do that way and they are a little
> > touchy
> > about doing it that way as well.
>
> > Set fso = CreateObject("Scripting.FileSystemObject")
> > strComputerName = InputBox("Enter Computer Name to have task scheduled
> > on","Schedule Disk Defrag Task")
> > strUserName = Inputbox("Enter your Network ID in the form of Domain\UserID
> > please.","Schedule Disk Defrag Task")
> > Set objPassword = CreateObject("ScriptPW.Password")
> > WScript.StdOut.Write "Please enter your netword password:"
> > set strUserPW = objpassword
> > schedule = "SCHTASKS /Create /s strComputername /p strUserPW /SC monthly
> > /TN
> > disk_defrag /TR ""c:\windows\system32\defrag.exe c: >>
> > c:\defrag_results.txt"" /RU system"
> > return = WshShell.Run(schedule, 1, True)
> > WScript.echo schedule
>
> > If return = 0 Then
> > WScript.Echo "the task was successfully created"
> > Else
> > WScript.Echo "there were problems creating the task"
> > End If
>
> > Any help would be greatly appreciate I am a newbie at this and I am trying
> > to muttle my way though this and learn at the same time.
>
> I have not tried it but perhaps the link below will help. Note also that
> frequent defragging will not make any noticeable difference to the speed of
> those PCs. You might spend a lot more time in getting this scheme to work
> reliably than the time you save for your users.
>
> http://blogs.technet.com/heyscriptingguy/archive/2005/09/06/how-can-i...- Hide quoted text -
>
> - Show quoted text -

I know that this is a cmd-line solution, but it can be called from
VBScript. I'd do it with Group Policy.

Download JKDefrag and run this:

SCHTASKS /create /sc ONIDLE /I 30 /tn jkdefrag.job /ru "" /tr "\\server
\share\JkDefragCmd.exe -q"

You could also copy the exe file to the local drive, whatever suits
you. This job would run the command-line version on idle with system
credentials.

Regards,

Jim