-
Notifications
You must be signed in to change notification settings - Fork 319
/
Copy pathsample4.vb
52 lines (46 loc) · 1.89 KB
/
sample4.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST")
Set sitesCollection = sitesSection.Collection
siteElementPos = FindElement(sitesCollection, "site", Array("name", "ftp.example.com"))
If siteElementPos = -1 Then
WScript.Echo "Element not found!"
WScript.Quit
End If
Set siteElement = sitesCollection.Item(siteElementPos)
Set ftpServerElement = siteElement.ChildElements.Item("ftpServer")
Set sessionsElement = ftpServerElement.ChildElements.Item("sessions").Collection
WScript.Echo "Active Sessions: " & CLng(sessionsElement.Count)
For i = 0 To CLng(sessionsElement.Count)-1
Set sessionElement = sessionsElement.Item(i)
WScript.Echo vbTab & "Session ID: " & sessionElement.GetPropertyByName("sessionId").Value
WScript.Echo vbTab & vbTab & "User Name: " & sessionElement.GetPropertyByName("userName").Value
WScript.Echo vbTab & vbTab & "Previous Command: " & sessionElement.GetPropertyByName("previousCommand").Value
Next
Function FindElement(collection, elementTagName, valuesToMatch)
For i = 0 To CInt(collection.Count) - 1
Set element = collection.Item(i)
If element.Name = elementTagName Then
matches = True
For iVal = 0 To UBound(valuesToMatch) Step 2
Set property = element.GetPropertyByName(valuesToMatch(iVal))
value = property.Value
If Not IsNull(value) Then
value = CStr(value)
End If
If Not value = CStr(valuesToMatch(iVal + 1)) Then
matches = False
Exit For
End If
Next
If matches Then
Exit For
End If
End If
Next
If matches Then
FindElement = i
Else
FindElement = -1
End If
End Function