Solved

A script for checking C drive disk space before installing software

Posted on 2008-11-03
2
252 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 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

691 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