From: GreyWolf on
I appreciate the input however the comapany I work for I very strict on
running freeware or thrid party apps with out have the EULA's reviewed by
legal. So this option is not a viable one. However thank you and I will put
this into my bag of tricks.

"BigDaddyJim" wrote:

> 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
> .
>
From: GreyWolf on
The hard drives get very fragmented very fast due to some of our in house
programs have been written to cache to the hard drive then erase the data
after the progam is closed, thereby leaving the drive with large amounts of
fragments. I have no control over this and this is why I need to be able to
schedule this defrag. On new computers that are being placed in via lease
replacement it will have already been setup. However there are other
computers 500+ that need to have this schedule as the technicians come across
them via a script that will mask the passwords (security requirement).

"Pegasus [MVP]" wrote:

>
>
> "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: Al Dunbar on


"GreyWolf" <GreyWolf(a)discussions.microsoft.com> wrote in message
news:2312C82B-54E7-4DDC-BF8C-72E4C8D1C300(a)microsoft.com...
> The hard drives get very fragmented very fast due to some of our in house
> programs have been written to cache to the hard drive then erase the data
> after the progam is closed, thereby leaving the drive with large amounts
> of
> fragments. I have no control over this and this is why I need to be able
> to
> schedule this defrag. On new computers that are being placed in via lease
> replacement it will have already been setup. However there are other
> computers 500+ that need to have this schedule as the technicians come
> across
> them via a script that will mask the passwords (security requirement).

I have a batch script (A) that copies a simple batch file (B) that runs
defrag to remote workstations, and then uses schtasks to schedule the
running of this script on a daily basis. The scheduled task runs as "NT
Authority\System" (i.e. /RU), so needs no password. I do not need the /U and
/P parameters to specify the account which is to run the schtasks program,
as I am already logged onto an account that is an administrator on all of
the remote systems I'll be dealing with.

That said, I see a few technical issues with your script as written that
might or might not be the main cause of your problems - see below.

> "Pegasus [MVP]" wrote:
>
>>
>>
>> "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"

Ok, so the variable "schedule" will contain EXACTLY the text shown below
enclosed in [square brackets]:

[SCHTASKS /Create /s strComputername /p strUserPW /sc monthly /TN
disk_defrag /TR ""C:\windows\system32\defrag.exe C: >>
c:\defrag_results.txt"" /RU system]

1. the actual computername SCHTASKS will try to manipulate is
"strComputername", NOT, as you probably want, the value that the user has
entered into a variable whose name is "strComputername". Same problem for
the value passed to the /p switch. To inject the value of these variables
into the command to be run, you need something like:

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"

2. you have now provided the password of the user account, but you have not
provided the name of the user account, so you need something like this:

schedule = "SCHTASKS /Create /s " & strComputername & " /u " &
strUserName & " /p " & strUserPW & " /SC monthly /TN disk_defrag /TR
""c:\windows\system32\defrag.exe c: >> c:\defrag_results.txt"" /RU system"

3. the /TR switch is defined as: "Specifies the path and file name of the
program to be run at the scheduled time. Example:
C:\windows\system32\calc.exe". You have tried to include a redirection by
appending " >> C:\defrag_results.txt" to the actual filename. What I think
will actually happen is that SCHTASKS will try to schedule the running of a
program whose name is not "c:\windows\system32\defrag.exe", but
":\windows\system32\defrag.exe c: >> c:\defrag_results.txt". If so, it will
most likely fail, as there is probably no such file.

4. If SCHTASKS allowed you to specify the program and, say, parameters, the
scheduler would run defrag.exe directly, and defrag.exe would choke on the
attempted redirection, because it know nothing about redirection. In order
for a command to use redirection, CMD.EXE must be involved, so the command
would have had to have been something like:

"cmd.exe /c C:\windows\system32\defrag.exe c: >> c:\defrag_results.txt"

But don't forget that this will not work in your context because of my point
number 3.

For these reasons, I find it much simpler to schedule only tasks that are
given as .cmd scripts. Then any special requirements can be implemented in a
standalone batch script rather than trying to embed the logic in a one-line
command, which is always (ALWAYS) harder to debug.

5. Once you have the nuts and bolts working as you seem to intend, the
"C:\defrag_result.txt" would continually increase in size, giving the
statistics of each defrag run. If you were to ever review these files, the
content of them would not tell you when defrag ran. The timestamp of the
file itself would tell you when it last ran.


/Al

>> > 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
>>
>>
>> .
>>