Solved

A script for checking C drive disk space before installing software

Posted on 2008-11-03
2
249 Views
Last Modified: 2013-11-25
Can someone please share with me a VBscript that will invoke a software installation if there is available disk space (250MB) on the C drive of local server?  I actually wanted to use the script to check OS version, patch level, disk space, etc.  but I figure a sample script would give me started in the right direction.  Thanks for the help.
0
Comment
Question by:shong1997
2 Comments
 
LVL 38

Accepted Solution

by:
Shift-3 earned 500 total points
ID: 22868682
Paste the script below into a text file with a .vbs extension.  Customize the value of the strInstaller variable with the location of the installer to run.  Running the script will echo the operating system and free space on C:, and then run the installer if the free space is greater than or equal to 250 MB.


On Error Resume Next
 
Const intMB = 1048576
 
strComputer = "."
strInstaller = "setup.exe"
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem")
 
For Each objItem In colItems
    strOS = objItem.Caption
Next
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk WHERE Caption = 'C:'")
 
For Each objItem In colItems
    intSpace = Round(objItem.FreeSpace/intMB)
Next
 
WScript.Echo "Operating System: " & strOS
WScript.Echo "Free space on C: drive: " & intSpace & " MB"
 
If intSpace >= 250 Then
    Set objShell = WScript.CreateObject("WScript.Shell")
    objShell.Run strInstaller
End If

Open in new window

0
 

Author Closing Comment

by:shong1997
ID: 31512744
This is exactly what I was looking for.  Thanks.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question