Saturday, April 12, 2008

How to get Lotus notes client details , policy details of the notes user , ip address , OS .. others by using lotus script

This lotus script generates the below data and then sends a mail. Care has been taken so that lotus script executes only once and only one mail is send from a client.

Data which is collected :

UserName
IP address
Platform
Notes Build version
Notes Client version
Policy details


Note : I have written below code by referring to Lotus notes domino designer help files & few public articles posted at internet and help from one of my friend.


Sub Click(Source As Button)

Dim jSession As JavaSession
Dim jClass As JavaClass
Dim jObject As JavaObject
Dim jMethod As JavaMethod

Dim session As New NotesSession
Dim doc As New NotesDocument(session.CurrentDatabase) 'Document which is being sent as mail
Dim ws As New NotesUIWorkspace
Dim all As String
Dim platform As String
Dim buildversion As String
Dim notesVersion As String
Dim userName As String
Dim getIPAddress As String
Dim check As String

check=session.GetEnvironmentString("IBMClientFlag")
If check="" Then
Call session.SetEnvironmentVar("IBMClientFlag","false")
End If

check=session.GetEnvironmentString("IBMClientFlag")

If check="false" Then


Set jSession = New JavaSession()
Set jClass = jSession.GetClass("java/net/InetAddress")
Set jMethod = jClass.GetMethod("getLocalHost","()Ljava/net/InetAddress;")
Set jObject = jMethod.Invoke()

getIPAddress = jObject.getHostAddress()
platform= session.Platform
buildversion=session.NotesBuildVersion
notesVersion=session.NotesVersion
Dim nam As NotesName
Set nam = session.CreateName(session.UserName)
userName = msg & nam.Abbreviated & Chr(13)

all = all & Chr(13)
all = all & Chr(9)

all=all &"UserName is : "
all=all & userName
all = all & Chr(13)
all = all & Chr(9)


all=all &"IP address is : "
all=all &getIPAddress
all = all & Chr(13)
all = all & Chr(9)

all=all &"Platform : "
all=all &platform
all = all & Chr(13)
all = all & Chr(9)

all=all &"Notes Build version is : "
all=all & buildversion
all = all & Chr(13)
all = all & Chr(9)

all=all &"Notes Client version is : "
all=all & notesVersion
all = all & Chr(13)
all = all & Chr(9)
all = all & Chr(13)
all = all & Chr(9)
all = all & "Policy Details "
all = all & Chr(13)
all = all & Chr(9)
all = all & Chr(13)
all = all & Chr(9)

%REM

To get ALL Policy Information

%END REM

Dim db As New notesdatabase("","names.nsf")
Dim view As notesview
Dim doc1 As notesdocument
Dim doc2 As notesdocument
Set view=db.GetView("$Policies")
Set doc1=view.GetFirstDocument
Dim policyName As String
Dim policyType As String
Dim status As String
Dim AllPolicy As String


While Not doc1 Is Nothing
policyName = doc1.FullName(0)
policyType = doc1.Type(0)
all = all & policyName
all = all & Chr(9)
all=all &"Policy Type is : "
all = all & policyType
all = all & Chr(13)
all = all & Chr(9)
Allpolicy = AllPolicy & policyType
Set doc1=view.GetNextDocument(doc1)
Wend

Call doc.AppendItemValue("Form","Memo")
Call doc.AppendItemValue("UserName",userName )
Call doc.AppendItemValue("IPAddress", getIPAddress)
Call doc.AppendItemValue("NotesVersion", notesVersion )
Call doc.AppendItemValue("Buildversion", buildversion )
Call doc.AppendItemValue("Platform", platform )
Call doc.AppendItemValue("Allpolicy", Allpolicy )

Call doc.AppendItemValue("Body", all)
Call doc.appendItemValue("Subject","Lotus Notes Client & Policy Details for user " & userName )
Call doc.Send(False,"piyush42@gmail.com")
Call session.SetEnvironmentVar("IBMClientFlag","true")

End If


End Sub

No comments: