Working With Objects archives - The VBScript Network and Systems Administrator's Cafe

The VBScript Network and Systems Administrator's Cafe:

working with objects

Feb 26 2009   8:00AM GMT

Retrieving the account IIS is using as the anonymous user account with VBScript



Posted by: Jerry Lees
iis, System Administration, Systems Administration, systems management, VBScript Functions, VBScript, web sites, web tools, working with objects

I recently posted a script that retrieved the anonymous user password for a server in IIS. This script I posted, Using the IIS ADSI object to retrieve the anonymous user password for a server via VBScript, came in quite handy in a pinch, but not knowing the anonymous user account the password goes with can also be a pain.Luckily I had that piece of information in the script as well!

So, I’ve wrapped that part of the script into a function for your use as well. Below is a snippet from the script to display the user account.

Function Get_IUSR_Username(ServerName)
Dim IIsObject

Set IIsObject = GetObject (”IIS://” & ServerName & “/w3svc”)
on Error resume Next
Get_IUSR_Username = IIsObject.Get(”AnonymousUserName”)
On Error GoTo 0
End Function

Enjoy!

Feb 20 2009   3:53PM GMT

Using the IIS ADSI object to retrieve the anonymous user password for a server via VBScript



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

Clean up your toys when your done: Fighting memory leaks in your scripts



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

VBScript Statements: Explanation of the Set Statement



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

VBScript Statements: Explanation of the With … End With Statement



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”