All posts by --Anand--

I am located at Silicon Valley working as IT Infrastructure Architect.

Simple Web Site Monitoring Script – written for Outlook Web Access server monitoring

I wanted to monitor our Exchange Front-End server and OWA URL at ISA server (in DMZ). There are tons of tools/scripts available to monitor web sites. But, I usually create a script by myself to fit my own needs.

This script is really really simple and gets the job done. Once it called with a web site URL, it will check the availability. If the web site is not reachable, it will send emails to specified administrators. Hope somebody make use of this simple script.

1. Copy and Paste the following script in Notepad. Save this script as "WebSiteMon.vbs" (type with quotes in File->Save dialog)
2. Search for "<<<<<" in this script and change the values like SMTP server name, Mail TO addresses
3. Create Batch file (somename.bat) and call this script by CScript WebSiteMon.vbs from the batch file.
4. Schedule to run this batch file every 15 minutes
5. Any Questions…leave a reply for this blog.

‘ Name: WebSiteMon.vbs
‘ Purpose:Checks availability of the given server and sends email
‘ if the server is not reachable.
‘ Paramenters: website URL (e.g.,
‘ Written By: Anand Venkatachalapathy
‘ Written Date: Aug 17th 2007
Dim MonitoredSite
Dim objWinHttp, strHTMResponse, strHTMStatus
Dim sTo, sSub, sBody

‘Get the Web Site URL from Arguments array
MonitoredSite = WScript.Arguments(0)

‘Open Windows HTTP Request object
Set objWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")

‘On Error is set to Resume Next. This is important.
On Error Resume Next

‘Open (get) the website
objWinHttp.Open "GET", MonitoredSite

‘Get the website page data
strHTMResponse = objWinHttp.ResponseText
strHTMStatus = objwinHttp.status

‘If Error is generated, website is not available
If Err.Number <> 0 Then
    sTo = ";" ‘<<<<< Change E-Mail Addresses
    sSub = MonitoredSite & " is NOT available"
    sBody = MonitoredSite & " is NOT available. This web site may be down. " & vbCrLf & vbCrLf & _
            "This alert mails will be send again in 15 minutes if the web site is not available."
    Alert_Admins sTo,sSub,sBody
    WScript.Echo MonitoredSite & " is not reachable and may be down"
End If

‘Memory wipe the objWinHttp
Set objWinHttp = Nothing

‘*-*-*-* End Of Script *-*-*-*

‘ Name:      Alert_Admins
‘ Purpose:   Send email using SMTP server.
‘ Input:     strTo – Who to send to, strSub – Subject of the message
‘             strBody – Body of the message
‘ Output:    Sends the emails to the strTO recipients
Sub Alert_Admins( strTo,strSub,strBody)

    ‘* iMsg – holds CDO.Message object
    ‘* Flds – Enumeration for CDO SMTP object properties
    ‘* iConf – holds CDO.Configuration
    Dim iMsg, Flds, iConf

    ‘* sSMTPServerName – SMTP Server Name
    Dim sSMTpServerName

    ‘* Assign your SMTP server here
    sSMTPServerName = ""   ‘<<<<< Change the SMTP server name

    ‘* Assign cdoSendUsingPort is set to 2, i.e., send using SMTP (25) port
    Const cdoSendUsingPort = 2

    ‘* Create CDO Objects and assign to variables
    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")
    Set Flds = iConf.Fields

    ‘* Assign values to Flds class properties

    With Flds
        .Item("") = cdoSendUsingPort
        .Item("") = sSMTPServerName
        .Item("") = 25 
    End With

    ‘* Assign message properties and Send the mail
    With iMsg
        Set .Configuration = iConf
        .Fields("urn:schemas:httpmail:importance").Value = 2    ‘Setting Mail importance to High (2)
        .To = strTo
        .From = ""               ‘Fake, but make-sense email FROM address
        .Sender = ""            ‘Return Email address
        .Subject = strSub
        .TextBody = strBody
    End With

End Sub

Solution: Windows cannot access the specified device, path, or file. You may not have the appropriate permissions to access the item.

In Windows 2003 SP1, this may be annoying sometimes if you don’t know what’s really happening. 

Problem: I have started building a Windows 2003 server (SP1) in the lab. I already have downloaded few Microsoft Exchange Patch files from Internet on our file share. I copied one of those Exchange 2003 patch setup file to my new server and try to run. Boom…I got an popup saying,


Solution: It turn out to be Microsoft is blocking files copied from other computers. That’s not the popup saying to us :-0 !!!!. Open the properties of the copied file (right click –> Properties). I found this,


The picture speaks itself. I don’t have to explain it.  

Deleted a Recurring Meeting without sending updates??? Solution is here.

Another day in the office. A cry came through phone from an admin who manages multiple conference rooms. "Please Help!! I have deleted a recurring meeting without sending updates? IT..Please help us to delete the meeting from all attendees".  Mind it it’s more than 20 attendees and she don’t want to call everyone to tell them to delete manually. It’s embarrassing for her.

I assured, "I am all here to help her issue".

Okay that must be a easiest job. 10 second work for a Exchange administrator like me. I open the conference room mailbox and opened the "Deleted Items" folder.  Within 10 seconds I realized it’s not a easy job. Because I didn’t find any deleted meetings in "Deleted Items" folder. What else? I tried "Tools –> Recover Deleted Items". No luck over there too.

Little investigation, I finally found out how to recover the deleted item and save the day. Here is how.

1. Open the Conference Room mailbox in Outlook.
2. Open Calendar (by clicking Calendar Button in Outlook 2003 and up OR Calendar Folder in Outlook 2002 and down)
3. Click Tools –> Recover Deleted Items
4. Find your deleted meeting and recover it.

I recovered the meeting and I called her. I told her to delete the meeting again, but send updates this time. So like I said, another day one of those Exchange admin guy saves the day. 🙂

Find the Display Name from email address from Active Directory

As a Exchange Administrator, I supposed know the answer for the following question in a blink of an eye. 

Where are the mails go when I send to this email address?

Well, that’s what I thought. It’s a more general email address like I searched for Distribution list or a mailbox or even a contact object. None. Best thing about "Active Directory Users and Computers" is you can NOT search by a email address.

My instinct says it must be a "Mail Enabled" Public Folder. So I searched through the public folders hierarchy.  There is lots of them and none of them has the specified email address attached. Exchange System Manager blankly said it delivered locally to the server.

I decided to use my special skill called "Scripting". I wrote the following script to get the display name of the email address from the Active Directory. Voila!!! I found what I was looking for in seconds.

Below is that script. If you want to use it, change the "Domain Name" for DomainContainer variable.

‘*********                       GetDisplayName.vbs                 **********
‘********* Parameters: email address                                **********
‘*********                                                          **********
‘********* This script queries the Active Directory by Email        **********
‘********* Address and displays the "Display Name" of the object.   **********

‘*********                                                          **********
‘********* Usage: GetDisplayName.vbs           **********
‘*********                                                          **********
‘********* Written By: Anand Venkatachalapathy                      **********

Set rootDSE=GetObject("LDAP://RootDSE")
DomainContainer = rootDSE.Get("defaultNamingContext")

Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ADSDSOObject"
conn.Open "ADs Provider"

sMail =  "SMTP:" & WScript.Arguments(0)  
DomainContainer = "DC=company,DC=com"
ldapStrUsers = "<LDAP://" & DomainContainer & _
">;(&(&(& (proxyAddresses=" & sMail & _
") (| (&(objectCategory=*)(objectClass=*)) ))));adspath;subtree"

Set rs1 = conn.Execute(ldapStrUsers)

While Not rs1.EOF
      Set FoundObject = GetObject (rs1.Fields(0).Value)
      WScript.Echo FoundObject.CN

Set rs1=Nothing
Set conn = Nothing
Set rootDSE = Nothing

Playing PLS (WinAMP) file in Windows Media Player


Do you ever wanted to play PLS (web broadcast) files in Windows Media Player? I do for good reasons like below.

1. WMP can buffer up to 60 seconds (or 1 Minute) of the broadcast. Somehow I can’t find it in WinAMP (at least in free edition)
2. My Keyboard support WMP for play, pause, etc.,, but NOT WinAMP

I tried opening the PLS file in WMP, it doesn’t know how to parse the PLS file. But, if you open the PLS file, copy and Paste the HTTP URL into WMP, it plays.


For Example, the typical PLS file looks like this,

Title1=(#1 – 10/50) MoonBeat Radio

If you copy the HTTP URL (, Open the WMP, Click Ctrl–>U for Open URL and paste the URL, WMP buffers and plays nicely.

Now, I know the above info..who are they kidding? I wrote a VBScript and made WMP to play the PLS file automatically. For example, I go to a Radio web site, click on PLS file link (usually says "PLAY" Button or URL), my script open the PLS, parse and open WMP with the provided HTTP URL. So I don’t have to install an extra player to listen Internet Radio on my work laptop.

If you like the above idea, use my following VBScript and CMD file.

1. Copy and Paste the following script into Notepad and save it as "PlayPLS.VBS". NOTE: While saving the script from Notepad, You NEED to type the vbscriptname.vbs in QUTOES. e.g., "PlayPLS.vbs". Otherwise it will save as PlayPLS.vbs.txt

‘*********                       PlayPLS.vbs                        **********
‘********* Parameters: PLS file name                                **********
‘*********                                                          **********
‘********* This script plays .PLS files in Windows Media Player     **********
‘*********                                                          **********
‘********* Usage: PlayPLS.vbs Sample.PLS                            **********
‘*********                                                          **********
‘********* Written By: Anand Venkatachalapathy                      **********

Set WshShell = WScript.CreateObject("WScript.Shell")
Set oArg = WScript.Arguments
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")

If oArg.Count = 0 Then
    WshShell.Popup "Invalid Arguments…Please provide the PLS file name.", _
7, "Play PLS in WMP",0
End If

sPLSFileName = oArg(0)
Set f = fso.OpenTextFile(sPLSFileName, ForReading)

Do While NOT f.AtEndOfStream
    sText =  f.ReadLine
    If InStr(UCase(sText),"FILE") > 0 Then
        sURLText =  Split(sText,"=")
        sURL = """" & sURLText(1) & """"
        sCmd = "WMPlayer " & sURL
        WshShell.Run sCmd
        Exit Do
    End If

Set fso = Nothing
Set oArg = Nothing
Set WshShell = Nothing

2. Copy and Paste the following text into Notepad and save it as PlayPLS.cmd. NOTE: Use the "double quotes" when saving the name in Notepad.

C:PathOfTheFolderPlayPLS.vbs %1

3. Open your favorite radio station (mine is, right click on PLS file link (or PLAY button) and save it on your desktop.

4. Open the file properties of PLS file (by right clicking on the PLS on the desktop and select properties), Click "Change" button next to the "Opens With:" text. Select the PlayPLS.cmd file by browsing to the corresponding folder and select the cmd file.

5. You are done. Go to your favorite radio web site again and click on "Play" Link. See it open in Windows Media Player.

6. Don’t forget to Thank me.

Mysterious Mails, Delivery Notices, Bounced mails Vs Outlook Delegates

This is what happened to me on one fine day. An Executive Admin complaints that she was getting Exchange mail delivery notices and bounced mails (NDRs) from an unknown user. 

She said it’s pretty annoying that she sends mails to bunch of users and gets bounced mails from some unknown (or long gone) users. I assured her that I will find out the issue and solution.

I laid back with my tea and thinking about the issue. If she sends mails to someone, but she gets NDRs (delivery notices in other cases) from a user who was not in TO or CC or BCC list. I know that Outlook Delegates are gets mails and meeting requests behalf of whoever delegated. I finished my last sip of tea and said myself, That is it.  "Delegates".

I started wondering about how to find out if anyone is delegated to someone else or not. After a few Live and Google search, I found out Active Directory stores the delegates and delegated users list in User properties. The following properties has the list of delegates,


I wrote a script to find out who’s delegated to whom. I ran my script against the "bunch of users" given by Admin. Voila!!! I found the list of delegates, made some phone calls and fixed the issue.  I informed the admin with the details and she praised "IT is great!!!" as always.

If you are the guy who is sipping your coffee or tea like me thinking about the same issue, Help is on the way here in this blog.

1. Manual Lookup of delegates

1. Open the ADSIEdit.msc by typing it in Start –> Run.
2. Expand Domain [domain name] container and find the user you want to check
3. Right click on the User and select "Properties"
4. Find publicDelegates and publicDelegatesBL properties and check the value

2. Use my Script to find out the delegates

Copy and Paste the following script in Notepad and save as "Delegates.vbs" to an known location.
Open Command prompt, go the directory where you saved the Delegates.vbs file.
Run "CScript Delegates.vbs <UserAccountName>"

e.g., CScript Delegates.vbs JDoe
CScript Delegates.vbs BGates

If you find what you looking for, Thank me.

‘*********                          DELEGATES.VBS                   **********
‘********* Parameters: Active Directory User Account Name           **********
‘*********                                                          **********
‘********* This script displayes User X’s Delegates and who else is **********
‘********* delegated to User X in Exchagne 2000/2003 via Outlook.   **********
‘*********                                                          **********
‘********* Usage: Cscript Delegagtes.vbs JDoe                       **********
‘*********                                                          **********
‘********* Written By: Anand Venkatachalapathy                      **********

Dim rootDSE                 ‘LDAP Direcotry Services Object
Dim DomainContainer         ‘Currently logged On Domain
Dim conn                    ‘ADODB connection object
Dim sUID            ‘Account Name from command line parameter
Dim ldapStrUsers            ‘LDAP Query
Dim rs1                     ‘LDAP Query Result Set
Dim FoundObject             ‘LDAP Query Result value
Dim objArgs                 ‘Commmand line Arguments

‘Find the local logged on AD Domain name
Set rootDSE=GetObject("LDAP://RootDSE")
DomainContainer = rootDSE.Get("defaultNamingContext")

‘If you know your domain name, you may comment the above two lines and
‘Assign your domain name yourself. Uncomment the below line and change
‘the Domain name as below format
‘DomainContainer = "DC=local,DC=company,DC=com"

‘ Connect to Active Service Connection provder
Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ADSDSOObject"
conn.Open "ADs Provider"

‘Get the command line parameter
Set objArgs = WScript.Arguments

If objArgs.Count = 0 Then
   WScript.Echo "Invalid Arguments!! provide a user account name as below…"
   WScript.Echo "CScript Delegates.vbs jdoe"
End If

sUID =  objArgs(0)  

‘Make a LDAP query string
ldapStrUsers = "<LDAP://" & DomainContainer & ">;(&(&(& (sAMAccountName=" & _
               sUID & ") (| (&(objectCategory=*)(objectClass=*)) ))));adspath;subtree"

‘Run the Query
Set rs1 = conn.Execute(ldapStrUsers)

‘Loop through the result set
While Not rs1.EOF
   Set FoundObject = GetObject (rs1.Fields(0).Value)
   WScript.Echo FoundObject.CN
   WScript.Echo "—————————————-"

   ‘Call the ListDelegates sub routine
   ListDelegates "LDAP://" & FoundObject.distinguishedName, FoundObject.CN

   rs1.MoveNext   ‘Move to next result

‘Free up the memory
Set rs1=Nothing
Set conn = Nothing
Set rootDSE = Nothing

‘********** Sub Routine: ListDelegates                              **********
‘********** Parameters: User’s AD Distinguished Name, Common Name   **********
‘**********                                                         **********
‘********** This sub find the provided user’s delegates and others  **********
‘********** delegated to the same user. Technically, it displays    **********
‘********** PublicDelegates and PublicDelegatesBL values from the   **********
‘********** Active Directory User Properties                        **********
Sub ListDelegates(sDN, sCN)
    Dim oUser   ‘User Object
    Dim objRecip ‘Dummy User Object

    Set oUser = GetObject (sDN)
    Set objRecip = oUser
    WScript.Echo "Users Delegated to " & sCN
    vDelegates = objRecip.publicDelegates
    nDelegates = UBound(vDelegates)
    If nDelegates > 0 Then
        i = 0
        Do While i <= nDelegates
            WScript.Echo vDelegates(i)
            i = i + 1
    End If
    WScript.Echo sCN & " delegated to these users "
    vDelegates = objRecip.publicDelegatesBL
    nDelegates = UBound(vDelegates)
    If nDelegates > 0 Then
        i = 0
        Do While i <= nDelegates
            WScript.Echo vDelegates(i)
            i = i + 1
    End If

    objRecip = Nothing
    oUser = Nothing
End Sub

RunAs using VBScript

If you want a VBScript to run a program using RunAs DOS command, go straight to the bottom of the blog. If you want to read the build-up for the final product, keep reading.

Time to time I came across I wanted to run a script or program as administrative privileges. The few needs are like,

  • Install a program or do something on client machines via logon script
  • Run a program using different account

Duh! RunAs command. Sure RunAs command works, but using VBScript??? You can find a VBScript example for running a program using RunAs command like below,

set oShell= Wscript.CreateObject("WScript.Shell")

oShell.Run "runas /user:domainaccount ""Notepad.exe""", 2      ‘Note 2 means minimized Window
WScript.Sleep 100

oShell.Sendkeys "password~"    ‘Note the ~ character in the end. ~ means ENTER


What’s wrong with the above script? After all it should work as expected. You know who the villain for above script. Guess…..OK. It’s attention hungry programs. When you run this script, it might send the password keys to wrong window,  while you running along with zillion programs in foreground and background. So what to do?

I rewrite the script few times and tested the script running along many programs. (Take ‘many programs’ as WinDVD, IE, Downloading a file in IE, Notepad, Command prompt and Active Directory Users and Computers). The final product is below,

Dim oShell
set oShell= Wscript.CreateObject("WScript.Shell")

oShell.Run "runas /user:domainuser ""program.exe""",2     ‘Note 2 means minimized Window
WScript.Sleep 100

For i = 0 to 10
      oShell.Popup "Opening Program.exe…",3,"Administrator",0+64  
‘3 means 3 seconds, 0+64 means OK button with Information Icon

      Activated = oShell.AppActivate ("runas")
      WScript.Sleep 10

      If Activated = 0 Then
             oShell.Sendkeys "password~"           ‘Note the ~ in the End..~ means ENTER
             Exit For
      End If


Few Tips and Tricks:

  1. If you want to run a VBScript in runas, try running RunAs /user:domainuser "WScript script1.vbs"
    • RunAs command run only executable files, so *.VBS or *.JS will not run
  2. If you want to run an *.MSC file, try running RunAs /user:domainuser "MMC test.msc"
  3. If you want tor run an Non-Executable file (other than above), try creating a DOS batch file and run the batch file using RunAs
  4. It’s not really safe to leave the VBScript file command location. Passwords are visible to any eyes. Try Encoding the VBScript using VBScript Encoder (can be downloaded from Microsoft).


For non-believer of my above VBScript sample, here is the nice list of alternatives.