Archive for the ‘vbscript’ Category

vbscript diskspace report

Sunday, November 25th, 2012
Found a nice little script which will check a system and report drive space.

In case the original link disappears; here it is.

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

wscript.echo without a charriage return.

Saturday, August 25th, 2012

I was writing a small script to obtain and display server network information.   Part of a project to re-ip a network.

One thing I wanted to have was formatted output and found wscript.echo was adding a carriage return to the output. I looked around to see if there was a way to disable it.

wscript.echo does this by design. There is no way to disable it.

The way to get around this is to use : Wscript.StdOut.Write

For example:

Wscript.StdOut.Write (“Enter something: “)

Wscript.StdOut.Write “You entered : ” & Wscript.StdIn.ReadLine

You will have to add is a “vbCrLf” at the end to cause a CR.