larksp Posted May 3, 2017 Posted May 3, 2017 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..
jguinch Posted May 3, 2017 Posted May 3, 2017 Did you try with #RequireAdmin at the beginning of the script ? Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
larksp Posted May 3, 2017 Author Posted May 3, 2017 yes i did.. this why im using msgbox instead of console as you cant read console while running in admin
jguinch Posted May 3, 2017 Posted May 3, 2017 I have the same issue when I run the script in a remote desktop session. It works with the console session (local session) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
larksp Posted May 4, 2017 Author Posted May 4, 2017 i am only trying it local run straight from the desktop on windows 7 no luck on a few windows 7
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now