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!
Nov 5 2008 4:10PM GMT
Posted by: Jerry Lees
tips and tricks,
VBScript,
working with objects,
memory leaks
One on the things you always want to do when you create objects in your scripts, especially objects from third party companies is, is to always remember to destroy the objects when you are done with them. At the very least, before you exit the script.
Object creation and not destroy the objects can be one source of memory leaks. In order to destroy an object should use the object’s .dispose method. If it does not have a dispose method, you set simply it to a special value of nothing. This will destroy the object and free up it’s memory. An example of using nothing is shown below:
Dim ObjTest
Set ObjTest = GetObject(”winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2″)
ObjTest = nothing
Aug 1 2008 10:00PM GMT
Posted by: Jerry Lees
VBScript,
VBScript Statements,
Objects,
set,
VBScript Objects,
working with objects,
set command,
working with variables
The set statement is used to assign any value to any type of variable. For the most part this command is optional. However, it needs to be used when you are assigning an object reference to a variable, such as when you use a variable to hold the return of a CreateObject function for later reference in your code.
An example of the set command would look like:
Option explicit
Dim objDictionary
Set objDictionary = CreateObject(”Scripting.Dictionary”)
Jul 23 2008 3:10PM GMT
Posted by: Jerry Lees
VBScript,
VBScript Statements,
with,
end with,
with end with,
working with objects
The With … End With statement allows you to execute a section of code on a specific object or class that calls methods or set properties on the object from within VBScript without referencing the object directly in the code written.
It is a way of simplifying your code, and very useful in large scripts.
For example:
(please note, these examples are snippets of code and will not work by themselves in an editor)
with objSomething
.FirstName = “Jerry”
.LastName = “Lees”
.URL = “http://www.gamersigs.net“
.XBoxLiveTag = “CrashSerious”
.Email = “Not-a-chance-spammers”
End with
This would be equivalent to the following standard code:
objSomething.FirstName = “Jerry”
objSomething.LastName = “Lees”
objSomething.URL = “http://www.gamersigs.net“
objSomething.XBoxLiveTag = “JLees”
objSomething.Email = “Not-a-chance-spammers”