?
Solved

A script for checking C drive disk space before installing software

Posted on 2008-11-03
2
Medium Priority
?
253 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 38

Accepted Solution

by:
Shift-3 earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

765 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