Archive for category VBScript

Calling the VBScript InStr function returns error

I am forced to work in classic ASP for some project. I don’t want to, it’s not my idea, but there we have it – the life of a consultant is fraught with peril.

While working on some VBScript code, I wrote some code to check permissions using the InStr function, and ran into this error:

Invalid procedure call or argument: 'InStr'

My call to InStr looked like this:

InStr(0, AllowablePermissions,UserPermissions)

According to w3schools.com , the first parameter, which was optional, defined the starting location. On a whim, I removed the first parameter, so my function call then looked liked this:

InStr(AllowablePermissions,UserPermissions)

And it worked. Go figure.

1 Comment

Error: The “SendUsing” configuration value is invalid

That was the error I was receiving when trying to send an e-mail using CDONTS in a VBS script. But I found a post by Jeff on forums.iis.net that was exactly what I was looking for.

The script was created to be run daily as a scheduled task, and to notify a user when disk space dropped below 15% of the drive’s total storage capacity.

This is the complete script, with comments at the end:
Option Explicit

Dim objFSO
Dim objDrive
Dim TotalSize
Dim AvailableSpace
Dim Percent
Dim objEmail

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objDrive = objFSO.GetDrive("C:")
AvailableSpace = objDrive.AvailableSpace
TotalSize = objDrive.TotalSize
Percent = (AvailableSpace / TotalSize) * 100
If Percent > 15 Then
 Set objEmail = CreateObject("CDO.Message")
 objEmail.From = "myemail@scottsserver.com"
 objEmail.To = "myemail@scottsserver.com"
 objEmail.Subject = "Server ZZZ is running low on disk space"
 objEmail.Textbody = "Server ZZZ is running low on disk space. " & AvailableSpace / 1024 & "MB is remaining of the total disk size of " & TotalSize / 1024 & "MB."
 objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
 objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtpserver.scottsserver.com"
 objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
 objEmail.Configuration.Fields.Update
 objEmail.Send
End If
WScript.Quit

The script originally was created without these lines:

 objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
 objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtpserver.scottsserver.com"
 objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
 objEmail.Configuration.Fields.Update

The error was thrown at the objEmail.Send line. After adding the lines, it worked perfectly.

Leave a comment