Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Problem with VBS Syntax

12 Aug 2014   #1
Nosmas

Microsoft Windows 7 Home Premium 32-bit 7601 Multiprocessor Free Service Pack 1
 
 
Problem with VBS Syntax

I have been experimenting with running Scheduled backups with Macrium Reflect using a generated VB Script which I have successfully modified. I now wish to enhance the VBS to perform the backups only if an external drive exists (i.e. it is switched on), and if there is sufficient space for the backup image. I give below some code which I have extracted from the Macrium Knowledgebase and modified prior to inserting it into the existing script which is working fine.

Option Explicit
Dim FSoObject
Set FSoObject=WScript.CreateObject("Scripting.FileSystemObject")
If FSoObject.DriveExists("D:") Then
wscript.echo "D drive exists"

If GetFreeSpaceGB("D:\OS Partn backups") < 50 Then
wscript.echo "D:\OS Partn backups Space is < 50GB"
wscript.echo "D:\OS Partn backups Free Space is " & GetFreeSpaceGB
wscript.echo GetFreeSpace
End If

Else wscript.echo "D drive does not exist"
End If

Function GetFreeSpaceGB(ByVal drvPath)
Dim objFSo, d
Set objFSo = CreateObject("Scripting.FileSystemObject")
Set d = objFSo.GetDrive(objFSo.GetDriveName (drvPath))
GetFreeSpaceGB = d.FreeSpace/ (1024 * 1024 * 1024)
End Function

The use of "echo" is only temporary until I get the script to work. At present it displays the "D drive exists" and "Space is < 50GB" messages but has a runtime error on the next statement with :- Wrong number of arguments or invalid property assignment 'GetFreeSpaceGB' Code 800A01C2. 'OS Partn backups' is the name of the target folder on the external D: drive.

I would appreciate any suggestions for making this code work.


My System SpecsSystem Spec
.
12 Aug 2014   #2
bbinnard

Win7-64
 
 

The GetFreeSpaceGB function is just that - a function. It is not a variable. So you cannot use it in a statement without a function argument - the argument being the drive for which you want the freespace value.

You tried to do this in the wscript.echo statement which is why you got the error message - VBS expects it to have a function argument.

Fix this by assigning a variable the value returned by GetFreeSpaceGB("D:\OS Partn backups"):

FreeSpace = GetFreeSpaceGB("D:\OS Partn backups")
If FreeSpace < 50 then
wscript.echo "D:\OS Partn backups Space is < 50GB"
wscript.echo "D:\OS Partn backups Free Space is " & FreeSpace
End If
My System SpecsSystem Spec
13 Aug 2014   #3
Nosmas

Microsoft Windows 7 Home Premium 32-bit 7601 Multiprocessor Free Service Pack 1
 
 

Many thanks bbinnard for your prompt reply, and having corrected my code I am pleased to say that it works as expected. I had previously tried something similar but obviously didn't get the coding quite right.

I wonder if I might please pose another coding question to you? When manually deleting a file or folder a message window asking for confirmation of moving to the Recycle Bin appears (and if too large another message asking to confirm permanent deletion appears) and both require the Yes or No buttons to be pressed. Can you provide me with the sort of code necessary to equal manually pressing the Yes button and thus avoid the procedure 'hanging' waiting for that action?
My System SpecsSystem Spec
.

14 Aug 2014   #4
bbinnard

Win7-64
 
 

Sorry, I can't help you with that one because I have never actually used VBS - just various versions of VB and VBA. However, I'd guess there is an optional parameter for the Delete function that lets you specify whether it is a hard (really deleted for good) or soft (deleted to Recycle bin) delete.

If that's not the case then look for another version of the Delete function that says it will bypass the Recycle bin. There are lots of utility programs that let you do either kind of delete so there has to be a way VBS can as well.
My System SpecsSystem Spec
Reply

 Problem with VBS Syntax




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
VB Script syntax problem
Although I am fairly new to VBS I have successfully modified a Macrium Reflect generated script for backups of my system, but now wish to enhance the script and to write (log) entries to a text file. Each time the backup is run I want to create a new text file and to differentiate between files by...
Software
Syntax please help?
Drive C: won't boot up windows7. I have to repair the bootsector, as I discovered that the power cable had come off it - since discarded it as no good. I have been given the syntax below, as it is possible that the PC went looking at another drive in the tower which had XP on it, which I hadn't...
General Discussion
VBA Syntax For Set objfolder
I normally have my sent e-mail saved in the Sent Items folder. However, I often wish to save to my "Follow-Up" folder in the Outlook folder list instead. I have a macro that assigns a Category to the e-mail, but would like to add the Set objfolder command to change from saving the e-mail in the...
Microsoft Office
excel syntax problem for formula... difference in days
if I have 2 columns of dates and I want to find the number of days between the days of D2 and C2, what is the syntax for the formula so that the result in column E is x number of days between the two dates
Microsoft Office
Syntax error.
I keep on getting some kind of Syntax error when I want to download some pictures. I can open them, but get this error when I want to save them. Does anyone have some advice here? Thanks!
General Discussion


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 21:39.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App