A1VBCode Forums

Reading the ErrorLevel code from Batch File...


http://a1vbcode.com/vbforums/Topic32386.aspx

By Kimblegray - 3/31/2016

Hi All,



I'm looking example in VB2010 example which able to run chkdsk d: /f and the code will able to read the errorlevel code return from chkdsk.



I'm trying using .exitcode but it is not a errorlevel code return from chkdsk.



Appreciate you can help...



Thanks.



Regards,

Kimbleray
By zack - 4/1/2016

This may help. Check out https://msdn.microsoft.com/en-us/library/windows/desktop/aa384913%28v=vs.85%29.aspx>



The VB code near the bottom returns the error code:



Const FIX_ERRORS = True



strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")



Set objDisk = objWMIService.Get("Win32_LogicalDisk.DeviceID='D:'")



errReturn = objDisk.ChkDsk(FIX_ERRORS) 'Returns error code