Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


VBS and formatting using bold or colours

VBS and formatting using bold or colours

VBS and formatting using bold or colours

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 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


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)


SET objTextFile = nothing
end sub

RE: VBS and formatting using bold or colours

Er … your code doesn't appear to display a dialog box at all. Just writes to a text file. And, as you yourself observe, you can't apply formats to a pure text file.

RE: VBS and formatting using bold or colours

Hi stongm

When I run this vbs code the dialog window appears. Commenting out the line:
wscript.echo "Report written to " & strReport & vbcrlf & vbcrlf & txt
will just write to a textfile and not display the window... but that is enabled above.

Is it possible to apply formats to the dialog window when the Free(%) column is less than 10%?

RE: VBS and formatting using bold or colours

Ah, sure - but that's not really a dialog box. Or, Ok, yes it is, in the sense that it is a standard Windows dialog window, but from vbscript's point of view it is simply a simple text display The underlying engine - wscript or cscript - provides this (and in cscript's case this would be in a command window rather than a graphical window), but your script has no idea how it is actually being displayed, and has no capability to interact with it. So no, you can't change the colour. You probably need to investigate HTAs. Or writing the output as HTML and displaying in a browser window (which is sort of what an HTA would allow as well)

RE: VBS and formatting using bold or colours

Many thanks to all for helping me in this question. I have just left it as a text file and the prompt that shows is fine for now.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close