|Post date: 2007-03-11 16:21|
This is an old trick but I think people might still have use for it. It is possible to issue console commands from a LotusScript agent using the below code.
I have made an example that shows the number of seconds the server has been up.
Make sure you set the agent to "2. Allow restricted operations" and that the user signing the agent has console access.
Declare Sub OSMemFree Lib "nnotes.dll" (Byval hBuffer As Long)
Declare Function OSLockObject Lib "nnotes.dll" (Byval hBuffer As Long) As String
Declare Sub OSUnlockObject Lib "nnotes.dll" (Byval hBuffer As Long)
Declare Function NSFRemoteConsole Lib "nnotes.dll" (Byval ServerName As String, Byval ConsoleCommand As String, rethBuffer As Long) As Long
Dim hBuf As Long
Dim pBuf As String
Dim result As Long
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.currentDatabase
result = NSFRemoteConsole(db.server,"show heartbeat", hBuf)
pBuf = OSLockObject(hBuf)
Dim s As String
s = Mid(pbuf, Instr(pbuf,"time: ")+6, Instr(pbuf," seconds")-Instr(pbuf,"time: ")-6) ' Extract seconds part
Print "Server uptime: " + s + " seconds."
You can test the output here for my server: