Grake Posted August 1, 2005 Posted August 1, 2005 Well as the title mentions, is there a way to auto frag the C:\ automatically, after say the applications are done, but before the restarting command executes?
Yzöwl Posted August 1, 2005 Posted August 1, 2005 Try adding this to your cleanup.cmddefrag %systemdrive% -f
sixpack Posted August 1, 2005 Posted August 1, 2005 or http://www.msfn.org/board/index.php?showto...47&hl=diskeeper
gunsmokingman Posted August 1, 2005 Posted August 1, 2005 Here a vbs script that will defrag all drives on the local computer.Dim Act, Fso, strDrv, DrvsSet Act = CreateObject("Wscript.shell")Set Fso = CreateObject("Scripting.FileSystemObject")Drvs = Array("C:\","D:\","E:\","F:\","G:\","H:\","I:\","J:\","K:\","L:\","M:\","N:\","O:\","P:\",_ "Q:\","R:\","S:\","T:\","U:\","V:\","W:\","X:\","Y:\","Z:\") For Each strDrv In DrvsIf Fso.DriveExists(strDrv) ThenAct.Run("Defrag " & strDrv & " -F"),1,trueEnd IfNext
RogueSpear Posted August 3, 2005 Posted August 3, 2005 (edited) I always recommend to clients that they purchase Raxco's PerfectDisk. Some can afford it, some can't, some just don't care, etc.. but I always try my best to make my scripts accomodating to all scenarios so that I don't have a dozen versions of the same script floating around. This VBScript checks to see if PerfectDisk is installed. If it is installed then that's what is used and also it will delete the executable and shortcut for Sysinternal's PageDefrag. So I have one script that works in all scenarios for me.Option ExplicitDim ws, fs, progfiles, raxco, sysintSet ws = WScript.CreateObject("WScript.Shell")Set fs = CreateObject("Scripting.FileSystemObject")progfiles = ws.ExpandEnvironmentStrings ("%PROGRAMFILES%")raxco = progfiles & "\Raxco\PerfectDisk"sysint = progfiles & "\Utilities\Sysinternals"'** Subroutine; PerfectDiskSub PerfectDisk Dim progs, utl progs = ws.SpecialFolders("AllUsersPrograms") utl = progs & "\Utilities" If fs.FileExists(utl & "\Page Defrag.lnk") Then fs.DeleteFile(utl & "\Page Defrag.lnk"), True If fs.FileExists(sysint & "\pagedfrg.exe") Then fs.DeleteFile(sysint & "\pagedfrg.exe"), True If fs.FileExists(sysint & "\pagedfrg.hlp") Then fs.DeleteFile(sysint & "\pagedfrg.hlp"), True If fs.FileExists(raxco & "\PDcmd.exe") Then ws.Run("""%PROGRAMFILES%\Raxco\PerfectDisk\PDcmd.exe"" /SmartPlacement /WAIT /AllDrives"),0,True If fs.FileExists(raxco & "\PDcmd.exe") Then ws.Run("""%PROGRAMFILES%\Raxco\PerfectDisk\PDcmd.exe"" /SCHEDBOOT /All /AllDrives"),0,TrueEnd Sub'** Subroutine; Windows DefragSub WindowsDefrag ws.Run("defrag %SYSTEMDRIVE% -f"),0,True If fs.FileExists(sysint & "\pagedfrg.exe") Then ws.Run("""%PROGRAMFILES%\Utilities\Sysinternals\pagedfrg.exe"" -o"),0,TrueEnd Sub'** Run TasksIf fs.FolderExists(raxco) Then PerfectDiskElse WindowsDefragEnd IfPlease note that there is line wrapping in this post on some of the longer lines. Edited August 3, 2005 by RogueSpear
midiboy Posted August 4, 2005 Posted August 4, 2005 Hey guys,wow, some vbs experts out there ... :-)I have combined rogue´s and Doug Knox´s defrag.all scripts but I am having a bit of a problem with it:' - Defrag all hard disks -Option ExplicitDim ws, fs, progfiles, raxcoSet ws = WScript.CreateObject("WScript.Shell")Set fs = CreateObject("Scripting.FileSystemObject")progfiles = ws.ExpandEnvironmentStrings ("%PROGRAMFILES%")raxco = progfiles & "\Raxco\PerfectDisk"'** Subroutine; PerfectDiskSub PerfectDiskIf fs.FileExists(raxco & "\PDcmd.exe") Then ws.Run("""%PROGRAMFILES%\Raxco\PerfectDisk\PDcmd.exe"" /SmartPlacement /WAIT /AllDrives"),0,TrueEnd Sub'** Subroutine; Windows DefragSub WindowsDefragDim d, dc Set dc = fs.Drives For Each d in dc If d.DriveType = 2 Then Return = ws.Run("defrag " & d & " -f", 1, TRUE) End If NextEnd Sub'** Run TasksIf fs.FolderExists(raxco) ThenPerfectDiskElseWindowsDefragEnd IfWScript.quitThe things is that if I call this script as an scheduled task, the task wscipt.exe will not end afterwards (don´t have perfect disc installed at the moment). If I call the original vbs script by Doug it will:'defrag_all.vbs - Defrags all hard disks - Can be run as a Scheduled Task'© Doug Knox - 3/29/2002Set WshShell = WScript.CreateObject("WScript.Shell") Dim fso, d, dc Set fso = CreateObject("Scripting.FileSystemObject") Set dc = fso.Drives For Each d in dc If d.DriveType = 2 Then Return = WshShell.Run("defrag " & d & " -f", 1, TRUE) End If NextSet WshShell = NothingAny idea why ? Also I am not sure that all drives in fact get defragmented in the first script by windows defrag (the first script ends much sooner as the second, although I did not change much ... mhh, what could that be ?!? )Thanks for pointing out any errors, I am not very good at scripting :-)Bye,Alex
spazmire11 Posted August 4, 2005 Posted August 4, 2005 is there a way to moniter what drive is being defraged with thos scripts?cause what i was thinking is if someone was watching there computer or accidently left the moniter on wouldent it be nice to have a screensave bouncing around the words "curently defragmenting the X drive." on the screen? maybe there would be a way to make a status indacatere apper below it but i dont know if thats posiblei could code it in vb but i dont know how thos scripts would act:are all the drives defraged at once or is it all linear meaning c drive defrags the d drive then e...if its linear then could i just have a timer control runing the words around the screen taking from the strdrive variable?any help on this would be nice
midiboy Posted August 5, 2005 Posted August 5, 2005 Well,if you use Perfect disc, an icon appears and tells you what PD is doing if you move the mouse over it. Also PD defrags all drives at once.If you use Windows defrag, nothing appears, however, the script calls the cmd version of defrag which means you get a status on each drive formatted in a cmd. This of course only happens if you run the script as the same user that is logged in. I have scheduled it using the SYSTEM account and then I don´t get any visual feedback.By the way, I think I have found the problem with the combined script I posted above. Somehow wscript did not like the word "RETURN" in line 23 saying it was not defined. It did work in the script by Doug though. Strange. dropping that and just using ws.run seems to work:' - Defrag all hard disks -Option ExplicitDim ws, fs, progfiles, raxcoSet ws = WScript.CreateObject("WScript.Shell")Set fs = CreateObject("Scripting.FileSystemObject")progfiles = ws.ExpandEnvironmentStrings ("%PROGRAMFILES%")raxco = progfiles & "\Raxco\PerfectDisk"'** Subroutine; PerfectDiskSub PerfectDiskIf fs.FileExists(raxco & "\PDcmd.exe") Then ws.Run("""%PROGRAMFILES%\Raxco\PerfectDisk\PDcmd.exe"" /SmartPlacement /WAIT /AllDrives"),0,TrueEnd Sub'** Subroutine; Windows DefragSub WindowsDefragDim d, dc Set dc = fs.Drives For Each d in dc If d.DriveType = 2 Then ws.Run("Defrag " & d & " -F"),1,true End If NextEnd Sub'** Run TasksIf fs.FolderExists(raxco) ThenPerfectDiskElseWindowsDefragEnd IfWScript.quit
RogueSpear Posted August 5, 2005 Posted August 5, 2005 PerfectDisk has a file in the install called config.ini in which you can set most if not all of the various program options ahead of the install. You then need to add CONFIG=1 to your msiexec command line statement at the time of install.Also, in the online help for PerfectDisk is a rather complete explanation of all of the commandline options for PDcmd.exe.
lwong Posted August 6, 2005 Posted August 6, 2005 Is there any reason to even bother defragging if you're going to ghost after your unattended install?
Grake Posted August 8, 2005 Author Posted August 8, 2005 (edited) I always recommend to clients that they purchase Raxco's PerfectDisk. Some can afford it, some can't, some just don't care, etc.. but I always try my best to make my scripts accomodating to all scenarios so that I don't have a dozen versions of the same script floating around. This VBScript checks to see if PerfectDisk is installed. If it is installed then that's what is used and also it will delete the executable and shortcut for Sysinternal's PageDefrag. So I have one script that works in all scenarios for me.Thanks for the scripts, but small problem lol.Im a little noobish to vb coding. How do I run this? Edited August 8, 2005 by Grake
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now