dominoExperts.com - Powered by Domino 8.5.2 Domino Accelerator Pack
- GoFaster=1
Lotus Triple Search DominoExperts + Blogs + R8 forum
dominoExperts.com -> General Domino Talk

 Console commands from agent


Tomas NielsenPost 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.

Code:
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
Sub Initialize
 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."
 Call OSUnlockObject(hBuf)
 Call OSMemFree(hBuf)
End Sub

You can test the output here for my server:
http://www.dominoexperts.com/de/uptime.nsf/uptime?openagent

 


Kenneth HaggmanPost date: 2007-03-15 21:24

Your code is correct, and has the advantage of being backwards compatible with R4 and R5.

But from ND6 you can do this with 'standard' LotusScript, like:
consoleReturn$ = notesSession.SendConsoleCommand( serverName$, consoleCommand$ )

See the help file.


Tomas NielsenPost date: 2007-03-15 21:27

Cool! I had missed that one.

It is almost too easy when you do not use the C++ API. 




RSS feed
Subscribe to Forum

Share this page

Top posters
Tomas Nielsen212
Joacim Boive27
Fredrik Stöckel27
Danne14
Niklas Waller13
Kenneth Haggman11
Bryan Kuhn10
Daniel Lehtihet9
Jonas Israelsson8
dm997