Link to home
Start Free TrialLog in
Avatar of astar666
astar666Flag for United States of America

asked on

request vbs script to run cleandisk without user intervention

I would run the utility cleandisk from the command line, so I can put it in the scheduler.  vbs looks good, but I do not know how to do the checkboxes, which I want all turned on.
Avatar of Nabeeh ElDardery
Nabeeh ElDardery

what about if you can run this script after user logs on (i hope understood u)
Avatar of astar666

ASKER

Yah, that is fine.  This workstation is approximately always logged on, and anyway, in win2k, the scheduler asks for the user and password it is supposed to run as, so I expect the scheduler can do sort of a login on its own.  Background is I asked about way to do defrag from the command line and someone kindly gave me a whole windows shell script, which works well enough.  I am a programmer but have not worked with windows shell script.  Reading the tutorials, I seem to be missing something in my head to write a windows shell script for cleandisk, because of the checkboxes.  Maybe it needs a lot of tabs to get to the checkboxes, is what I have since decided.
Here is the command you are looking for to automatically run chkdsk with the /f option, and bypassing the prompt if you would like to schedule it for next reboot.


echo y | chkdsk C: /f
To create the scheduled task I would use a command line option as a login script or however else you wish to push it out.  For example, create a batch file called checkdisk.bat in your Windows directory and put in

echo y | chkdsk C: /f

Then I would push out this command to create the scheduled task.

schtasks /create /tn "Checkdisk" /sc daily /st 01:00:00 /ru system /tr "c:\windows\checkdisk.bat""
That is interesting, but not quite responsive.  The problem is that the cleandisk function is cleanmgr.exe, which takes no known command line parameters.  For instance I just tried cleanmgr /? and just got the gui.  So this is why it would seem this needs windows scripting.  On the other hand, the checkboxes issue turned out to be bogus.  Here is a windows script I have now written that seems to work:

set WshShell = CreateObject("WScript.Shell")
WshShell.Run "%SystemRoot%\System32\cleanmgr.exe"
WScript.Sleep 2000

WshShell.SendKeys "{ENTER}"
wscript.sleep 1000

While WshShell.AppActivate("Disk Cleanup for")= FALSE
  wscript.sleep 5000
Wend

wscript.sleep 1000
WshShell.SendKeys "{ENTER}"

wscript.sleep 1000
WshShell.SendKeys "{ENTER}"

While WshShell.AppActivate("Disk Cleanup for")= FALSE
      wscript.sleep 5000
Wend

In other oddies, my best understanding is that on a nfts volume, dfrg.msc performs as part of its activity, the chkdsk function.

Oh, I thought you meant checkdisk and not clean manager.

This is some info on scheduling cleanmgr
http://www.tweakhound.com/xp/tasks/sch_disk_cln.htm
ASKER CERTIFIED SOLUTION
Avatar of Eagle6990
Eagle6990
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial