Solved

A script for checking C drive disk space before installing software

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now