larksp

Wmi Defrag not working

5 posts in this topic

#1 ·  Posted

i thought this would been done before but i cant find the answer when i search defrag

seems to work on using vb code to defrag with wmi but i get error 11 with autoit witch means unknown error

$WMIService = ObjGet("winmgmts:\\.\root\cimv2")
    $WMIVolumes = $WMIService.ExecQuery("Select * from Win32_Volume WHERE name = 'C:\\'")
    
    If IsObj($WMIVolumes) Then
        For $Volume In $WMIVolumes
;~          $Test = $Volume.DefragAnalysis ; just testing 
            $errR = $Volume.Defrag()
        Next

        If $errR = 0 Then
            MsgBox(0, 'Defrag', "Drive " & $Volume.Name & " Successfully Defragged.")
        Else
            MsgBox(0, 'Defrag', "Error = " & $errR & "  Defrag Failed.")
        EndIf
    EndIf
;~  MsgBox(0, 'Moo', "Drive " & $test)

i have tried with Admin.. this is why im using message box rather than console for the error
next would be check disk with back sectors but 1 thing at a time

(Defrag)
i do know there is a cmd command for this . have also done this by Open gui window then using control clicks so i can see a progress as well but i like to try different ways to learn.. 

Share this post


Link to post
Share on other sites



#3 ·  Posted

yes i did.. this why im using msgbox instead of console as you cant read console while running in admin

Share this post


Link to post
Share on other sites

#5 ·  Posted

i am only trying it local run straight from the desktop on windows 7 no luck on a few windows 7

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now