Problem with VBS Syntax

Nosmas

New member
Local time
10:13 PM
Messages
46
Location
Chipstead, Surrey, UK
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 Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dell Optiplex 9030
OS
Microsoft Windows 10 Pro 64-bit Multiprocessor
CPU
Intel(R) Core(TM) i3-4160 CPU @3.60 GHz x 4
Memory
4.00 GB
Monitor(s) Displays
23-inch full-HD WLED
Screen Resolution
1920 x 1080 @ 60 Hz
Hard Drives
1 x 2.5-inch SATA hard drive
PSU
185 Watt
Browser
MS Edge and IE 11
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 Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom built
OS
Win7-64
CPU
Intel i7-3770S
Motherboard
ASUS P8Z77-M
Memory
16GB
Graphics Card(s)
nVidia GT630
Sound Card
onboard
Monitor(s) Displays
dual
Screen Resolution
1920x1200 (primary) 1050x1680 (secondary)
Hard Drives
128GB SSD (boot)
64GB SSD (Temp/My Documents)
500GB (photos/videos)
1TB (rendered video, backups)
PSU
650W
Case
Thermaltake A30
Cooling
Thermaltake
Keyboard
Logitech Lighted
Mouse
Kensington Expert Mouse (trackball)
Internet Speed
FIOS 35/35
Antivirus
MS Security Essentials
Browser
Chrome (beta)
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 Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dell Optiplex 9030
OS
Microsoft Windows 10 Pro 64-bit Multiprocessor
CPU
Intel(R) Core(TM) i3-4160 CPU @3.60 GHz x 4
Memory
4.00 GB
Monitor(s) Displays
23-inch full-HD WLED
Screen Resolution
1920 x 1080 @ 60 Hz
Hard Drives
1 x 2.5-inch SATA hard drive
PSU
185 Watt
Browser
MS Edge and IE 11
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 Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom built
OS
Win7-64
CPU
Intel i7-3770S
Motherboard
ASUS P8Z77-M
Memory
16GB
Graphics Card(s)
nVidia GT630
Sound Card
onboard
Monitor(s) Displays
dual
Screen Resolution
1920x1200 (primary) 1050x1680 (secondary)
Hard Drives
128GB SSD (boot)
64GB SSD (Temp/My Documents)
500GB (photos/videos)
1TB (rendered video, backups)
PSU
650W
Case
Thermaltake A30
Cooling
Thermaltake
Keyboard
Logitech Lighted
Mouse
Kensington Expert Mouse (trackball)
Internet Speed
FIOS 35/35
Antivirus
MS Security Essentials
Browser
Chrome (beta)
Back
Top