Code Script .co.uk

Home | Scripts | Tutorials | Disclaimer | Sitemap | Contact

   Run Chkdsk
 

Vbscript / General / Run Chkdsk

Run chkdsk via WMI

Chkdsk return codes:

0 - No errors were found.
1 - Errors were found and fixed.
2 - Disk cleanup, such as garbage collection, was performed, or cleanup was not performed because /f was not specified.
3 - Could not check the disk, errors could not be fixed, or errors were not fixed because /f was not specified.

Const FIX_ERRORS = False

strComputer = "Server01"
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!" & strComputer & " ootcimv2")

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

errReturn = objDisk.ChkDsk(FIX_ERRORS)

if errReturn = 0 then
   WScript.Echo "Chkdsk completed successfully."

elseif errReturn = 1 then
   WScript.Echo "Chkdsk scheduled on next reboot."
else
   WScript.Echo "Error running chkdsk: " & errReturn
end if





Please note that a disclaimer applies to any code on this page.
 
   Actions
  Go Back
  Bookmark
  Print Page


   Menu
 
- Links
- Reference
- Script Editors
- Tutorials
- Vbscript
     - Active Directory
     - Exchange
     - Files And Folders
     - General
          - Check Remote Computer Disks
          - Encode Hardcoded Passwords
          - Generate Random Password
          - Get Machine Ip Address
          - Get Machine Ip Address From Name
          - Print All Files In A Folder
          - Run Chkdsk
          - Set All Network Adapters To Dhcp
          - Sql Server Query
          - Vbscript Logging Techniques
     - Ms Office
     - Operating System
     - Processes And Services
     - Text Processing
     - User Interaction
     - Web Servers