stantheman Posted December 2, 2018 Posted December 2, 2018 The following code (taken from http://www.wisesoft.co.uk/scripts/vbscript_disk_sp...) displays a dialog window with the results of space of hard drives. Is it possible from this code to make the end column of the dialog window (not the textfile as I know that can't be done) that shows (Free(%)) to be bold or the colour red if the % is below 10% for example? That way you can see visually and quickly that this hard drive is going to be low on space soon? I hope this can be done but I don't know enough about VBS and formatting when dialog windows are displayed. Option Explicit const strComputer = "." const strReport = "c:\diskspace.txt" Dim objWMIService, objItem, colItems Dim strDriveType, strDiskSize, txt Set objWMIService = GetObject("winmgmts:" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk WHERE DriveType=3") txt = "Drive" & vbtab & "Size" & vbtab & "Used" & vbtab & "Free" & vbtab & "Free(%)" & vbcrlf For Each objItem in colItems DIM pctFreeSpace,strFreeSpace,strusedSpace pctFreeSpace = INT((objItem.FreeSpace / objItem.Size) * 1000)/10 strDiskSize = Int(objItem.Size /1073741824) & "Gb" strFreeSpace = Int(objItem.FreeSpace /1073741824) & "Gb" strUsedSpace = Int((objItem.Size-objItem.FreeSpace)/1073741824) & "Gb" txt = txt & objItem.Name & vbtab & strDiskSize & vbtab & strUsedSpace & vbTab & strFreeSpace & vbtab & pctFreeSpace & vbcrlf Next writeTextFile txt, strReport wscript.echo "Report written to " & strReport & vbcrlf & vbcrlf & txt ' Procedure to write output to a text file private sub writeTextFile(byval txt,byval strTextFilePath) Dim objFSO,objTextFile set objFSO = createobject("Scripting.FileSystemObject") set objTextFile = objFSO.CreateTextFile(strTextFilePath) objTextFile.Write(txt) objTextFile.Close SET objTextFile = nothing end sub
altecsole Posted December 2, 2018 Posted December 2, 2018 I would look at using a HTA to do what you're wanting. This would allow you to use html to customise your output. 1
jb2201 Posted December 2, 2018 Posted December 2, 2018 (edited) You could look to PowerShell for this, I created a script that took a list of servers and did exactly this (plus other things like physical drive health from OMSA) then took a HTML template and filled any tags I had specified with the data, ended up being a lot more straight forward than it sounds. Edited December 2, 2018 by jb2201 1
stantheman Posted December 2, 2018 Author Posted December 2, 2018 jb2201 - thanks for the reply. The bad news is that I've not used PowerShell all that much so wouldn't know where to start. Are you able to share the basic that I require? Don't require health of the hard drive just the total, used and remaining and % remaining with a red colour if less than 10% free space? It will be just local hard drives that are connected via SATA. It does sound great if it can be html format thinking about it.
Chris_Cook Posted December 2, 2018 Posted December 2, 2018 You could modify your original script to output html instead. Change the two lines that start "txt =" and add some html code. Then change the file name at the start to c:\diskspace.html Then at the end just before end sub, open it in a web browser with this: CreateObject("WScript.Shell").Run """c:\diskspace.html""" 1
mavhc Posted December 2, 2018 Posted December 2, 2018 (edited) this works in Win10 cmd, but not via cscript: echo ^[[1;33;44m test Where ^[ is ctrl+[, ie ESC control code, ascii 27 wscript.echo chr(27) +"[1;33;44m test" doesn't work. However if you save that as colour.vbs and then as a weird hack: start /wait /b cscript colour.vbs does work Edited December 2, 2018 by mavhc 1
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