Mar 10 2009 2:01AM GMT
Posted by: Jerry Lees
undocumented windows,
SAPI.SpVoice,
Sound,
Speech API,
Office Agent,
VBScipt,
VBScript Objects
I’ve been looking for ways to make a script speak the information it needs to relay to the user just for fun and, unfortunately the only scripts I could find out there were extremely elaborate onces that use the Microsoft Office Agents. While they fit the bill they were annoying and required Microsoft office components to be installed… that just wouldn’t do.
Then I found the Windows Sound API. It doesn’t require anything at all to be installed and it works fine. The script below is simple and easy to implement in your code. Check it out:
strText = “Hello, there…. can you write code?”
Set objVoice = CreateObject(”SAPI.SpVoice”)
objVoice.Speak strText
Feb 20 2009 3:53PM GMT
Posted by: Jerry Lees
iis,
System Administration,
Systems Administration,
Toolkit,
VBScipt,
VBScript Functions,
VBScript,
working with objects
I recently had to change the anonymous user account for a change request for a site in IIS, but unfortunately the change did not work and we had to roll it back. However, I didn’t have and wouldn’t have known the account’s password since IIS and windows changes it periodically.
So, out came the scripting tool belt and I found that I had a script written previously that let me get the anonymous user account and password through the IIS ADSI object.
Below is a snippet from the script to display the password.
Function Get_IUSR_Password(ServerName)
Dim IIsObject
Set IIsObject = GetObject (”IIS://” & ServerName & “/w3svc”)
on Error resume Next
Get_IUSR_Password = IIsObject.Get(”AnonymousUserPass”)
On Error GoTo 0
End Function
Enjoy!
Feb 13 2009 6:40PM GMT
Posted by: Jerry Lees
GUID,
Scriptlet.TypeLib,
VBScipt
Today I answered a question in the ITKE unanswered questions for Word VBA on how to be certain a filename was unique across several users using it. The answer I gave answered the question, but I knew there was a way to create GUID’s within VBScript but couldn’t recall how.
GUID’s are cryptic to look at, but they are pretty much guaranteed to be unique. After some research I found the library that provides this functionality… Scriptlet.TypeLib! Below is a short script that gives you an idea of how to use it in your scripts to generate unique strings for when you need a guaranteed unique name or identifier.
Option Explicit
Dim GUID
Set TypeLib = CreateObject(”Scriptlet.TypeLib”)
GUID = TypeLib.Guid
Enjoy!
Feb 10 2009 6:11PM GMT
Posted by: Jerry Lees
VBScipt,
DATEDIFF,
date,
Dates,
Date Comparison,
VBScript Functions
On occasion you need to compare two dates in your scripts, this can be a real challenge when you approach the date as if it were a string and/or compare the date parts to one another. Then finding the difference can be a whole other set of challenges if your dates span several months, days, or years.
Luckily, there is a function right into VBScript that helps you compare two dates to one another and returns the difference in a unit of time that you specify! That function is the datediff function!
Below is an example that returns the number of seconds, minutes, hours, days, and years between now and February 25, 1973.
Option Explicit
Dim DateThen, DateNow
DateThen = “2/25/1973″
DateNow = Now
WScript.Echo DateDiff(”s”,DateThen, DateNow)
WScript.Echo DateDiff(”n”,DateThen, DateNow)
WScript.Echo DateDiff(”h”,DateThen, DateNow)
WScript.Echo DateDiff(”d”,DateThen, DateNow)
WScript.Echo DateDiff(”yyyy”,DateThen, DateNow)
Enjoy!
Dec 29 2008 3:21PM GMT
Posted by: Jerry Lees
strings,
String manipulation,
string,
working with variables,
Special Characters,
ASCII,
VBScipt
I just realized I’ve been using Visual Basic String constants in my scripts with little to no explanation. We’ll rectify that situation right now!
When dealing with strings in VBScript, you occasionally need to add formatting characters to a string, so that when it is displayed on the screen or in a file it looks correct. If you know your ASCII chart you can certainly preform this with a “& chr(X) &”.However, if you don’t know what ASCII value a tab is (it’s 9) then you can simply use Visual Basic’s string constants in your scripts and have the added benefit if making it easier to read!
The constants and their meanings are listed below:
| VBTab |
A Tab character [Chr(9)] |
| VBCr |
A carriage return [Chr(13)] |
| VBCrLf |
A carriage return and line feed [Chr(13) + Chr(10)] |
| vbBack |
A backspace character [Chr(8)] |
| vbLf |
A linefeed [Chr(10)] |
| vbNewLine |
A platform-specific new line character, either [Chr(13) + Chr(10)] or [Chr(13)] |
| vbNullChar |
A null character of value 0 [Chr(0)] |
| vbNullString |
A string of value 0 [no Chr code]; note that this is not the same as “” |