Defrag all harddrives with simpler code!
Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
9 posts
Page 1 of 1
What will i need?
1 button
put this code into the click event basicly this will defrag every drive on a computer, no more is to be said!
JUST CALLS APON THE WINDOWS DEFRAGGER!
1 button
put this code into the click event basicly this will defrag every drive on a computer, no more is to be said!
Code: Select all
Or you can save it as a .vbs if you dont want to make a actual program out of it.Set 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
Next
Set WshShell = Nothing
JUST CALLS APON THE WINDOWS DEFRAGGER!
------------------------------------------------------------------------------
Proprogrammer, not just a Programmer.
Proprogrammer, not just a Programmer.
well what this does is compress and reorders your files to make your computer run faster and use up less space.
------------------------------------------------------------------------------
Proprogrammer, not just a Programmer.
Proprogrammer, not just a Programmer.
Nice one Proprogrammer this could be used as part of a computer maintenance application or something cooll;
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
CodenStuff wrote:Nice one Proprogrammer this could be used as part of a computer maintenance application or something cooll;I agree with that. But still it can be a stand'alone application which works very fast!
Sorry, but heres what I get:
Error 1 Name 'WshShell' is not declared. C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\ObsprO Defragmenter\Form1.vb 8 9 ObsprO Defragmenter
Error 2 Name 'WScript' is not declared. C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\ObsprO Defragmenter\Form1.vb 8 20 ObsprO Defragmenter
Error 3 'Return' statement in a Sub or a Set cannot return a value. C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\ObsprO Defragmenter\Form1.vb 15 4 ObsprO Defragmenter
Error 4 Expression expected. C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\ObsprO Defragmenter\Form1.vb 15 11 ObsprO Defragmenter
Error 5 Name 'WshShell' is not declared. C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\ObsprO Defragmenter\Form1.vb 19 9 ObsprO Defragmenter
And this the total code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WshShell = WScript.CreateObject("WScript.Shell")
Dim fso, d, dc
fso = CreateObject("Scripting.FileSystemObject")
dc = fso.Drives
For Each d In dc
If d.DriveType = 2 Then
Return = WshShell.Run("defrag " & d & " -f", 1, TRUE)
End If
Next
WshShell = Nothing
End Sub
Error 1 Name 'WshShell' is not declared. C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\ObsprO Defragmenter\Form1.vb 8 9 ObsprO Defragmenter
Error 2 Name 'WScript' is not declared. C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\ObsprO Defragmenter\Form1.vb 8 20 ObsprO Defragmenter
Error 3 'Return' statement in a Sub or a Set cannot return a value. C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\ObsprO Defragmenter\Form1.vb 15 4 ObsprO Defragmenter
Error 4 Expression expected. C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\ObsprO Defragmenter\Form1.vb 15 11 ObsprO Defragmenter
Error 5 Name 'WshShell' is not declared. C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\ObsprO Defragmenter\Form1.vb 19 9 ObsprO Defragmenter
And this the total code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WshShell = WScript.CreateObject("WScript.Shell")
Dim fso, d, dc
fso = CreateObject("Scripting.FileSystemObject")
dc = fso.Drives
For Each d In dc
If d.DriveType = 2 Then
Return = WshShell.Run("defrag " & d & " -f", 1, TRUE)
End If
Next
WshShell = Nothing
End Sub
I dont know why that happend maybe it is just for certain Windows systems or something, i dont know.
------------------------------------------------------------------------------
Proprogrammer, not just a Programmer.
Proprogrammer, not just a Programmer.
but... then its just using the system's defrag software wich is actually pointless lol
9 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023