Solved

A script for checking C drive disk space before installing software

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Build VS2015 project in bat command 3 80
Show hidden user account 7 55
Command to modify Registry entry 5 98
SSRS troubles 4 20
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
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…
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 is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

895 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

14 Experts available now in Live!

Get 1:1 Help Now