Manage Learn to apply best practices and optimize your operations.

Shortcut for executing server commands

An example of how to send server task commands to a Domino Server using LotusScript and the WIN32 API

This tip is derived from a piece of code that was placed on the Notes.net Notes Gold Forum by Ulrich Krause. I modified it to make it easier for administrators to use and added functionality.

This is an example of how to send server task commands to a Domino Server using LotusScript and the WIN32 API. This allows for Administrators to use a form with a button, a view action, a form action, etc. to send commands to the server and in some cases see the results. Any "SHOW" command will show results, most others will come back with "Command Executed!" Follow the instructions below to set it up.

1. Create a blank form in a database. Name it anything you want.
2. Add a button to the form. The text for the button should be Console Command or something like that.
3. In the "Declarations" section of the button, copy and paste the code below.

Declare Function NSFRemoteConsole Lib "NNotes.dll" Alias "NSFRemoteConsole" (Byval Server As String, Byval cmd As String, 
ret As Long) As Long
Declare Function OSLockObject Lib "NNotes.dll" Alias "OSLockObject"
 (Byval Handle) As String
Declare Sub OSUnlockObject Lib "NNotes.dll" Alias "OSUnlockObject" 
(Byval Handle)
Declare Sub OSMemFree Lib "NNotes.dll" Alias "OSMemFree" (Byval 
Handle)
Class remoteConsole
	Private IsError As Variant
	Private rc As Integer
	Private hBuffer As Long
	Private Server As String
	Private Command As String
	Private Result As String
	
	Sub New(inpServer As String)
		Dim server As New NotesSession
		If inpServer = "" Then
			Me.IsError = True
		Else
			Me.server=inpServer
			Me.IsError = False
		End If
	End Sub
	
	Function Execute(inpCommand As String, myserver As String) As String
		If Me.Server = "" Then
			Me.Server = myserver
		End If
		If inpCommand = "" Then
			Me.execute="You must specify a command"
			Me.iserror = True
			Exit Function
		Else
			Me.command = inpCommand
		End If
		
		Me.rc = NSFRemoteConsole(Me.server, Me.command, hBuffer)
		If Me.rc <> 0 Then
			Me.iserror = True
			Me.result="Error returned " & _
			" from console [" & Cstr(rc) & "]"
		Else
			Me.result = OSLockObject(hBuffer)
			Call OSUnlockObject(hBuffer)
			Call OSMemFree(hBuffer)
			Me.Iserror = False
		End If
		If Me.result = "" Then
			Me.result = "Command executed!"
		End If
		Me.execute = Me.result
	End Function
End Class

4. In the "Click" section of the button, copy and paste the code below.

Sub Click(Source As Button)
	Dim exec As String
	Dim remConsole As New RemoteConsole("")
	'Dim ws As New NotesUIWorkspace
	'Dim uidoc As NotesUIDocument
	Dim myserver As String
	'Dim mydatabase As String
	
	'Set uidoc = ws.CurrentDocument
	myserver = Inputbox$("Type a server name", "Remote Console 
Task", "<server>")
	'mydatabase = uidoc.FieldgetText( "RI_MailFileNm" )
	Exec = Inputbox$("Enter a remote console task", "Remote 
Console Task", "Sh Ta")
	If exec = "" Then
		Exit Sub
	Else
		Msgbox remConsole.Execute(exec, myserver), 0, "Results"
	End If
End Sub

5. Save the form.
6. Open the database via the client and then choose Create --> Your Form(whatever you named your form).
7. Click the button and watch it work.

You can get creative from there. Just one of its uses from my site is that we use it in a portal we create a long while back in a Notes Database. It's a database on the Notes client that can do anything our administrators need to do at our site.

Thanks,

Steve


Declare Function NSFRemoteConsole Lib 
"NNotes.dll" Alias "NSFRemoteConsole" (Byval Server As String, Byval cmd As String, ret As Long) As Long
Declare Function OSLockObject Lib "NNotes.dll" Alias "OSLockObject"
 (Byval Handle) As String
Declare Sub OSUnlockObject Lib "NNotes.dll" Alias "OSUnlockObject" 
(Byval Handle)
Declare Sub OSMemFree Lib "NNotes.dll" Alias "OSMemFree" (Byval 
Handle)
Class remoteConsole
	Private IsError As Variant
	Private rc As Integer
	Private hBuffer As Long
	Private Server As String
	Private Command As String
	Private Result As String
	
	Sub New(inpServer As String)
		Dim server As New NotesSession
		If inpServer = "" Then
			Me.IsError = True
		Else
			Me.server=inpServer
			Me.IsError = False
		End If
	End Sub
	
	Function Execute(inpCommand As String, myserver As String) 
As String
		If Me.Server = "" Then
			Me.Server = myserver
		End If
		If inpCommand = "" Then
			Me.execute="You must specify a command"
			Me.iserror = True
			Exit Function
		Else
			Me.command = inpCommand
		End If
		
		Me.rc = NSFRemoteConsole(Me.server, Me.command, 
hBuffer)
		If Me.rc <> 0 Then
			Me.iserror = True
			Me.result="Error returned " & _
			" from console [" & Cstr(rc) & "]"
		Else
			Me.result = OSLockObject(hBuffer)
			Call OSUnlockObject(hBuffer)
			Call OSMemFree(hBuffer)
			Me.Iserror = False
		End If
		If Me.result = "" Then
			Me.result = "Command executed!"
		End If
		Me.execute = Me.result
	End Function
End Class


Sub Click(Source As Button)
	Dim exec As String
	Dim remConsole As New RemoteConsole("")
	'Dim ws As New NotesUIWorkspace
	'Dim uidoc As NotesUIDocument
	Dim myserver As String
	'Dim mydatabase As String
	
	'Set uidoc = ws.CurrentDocument
	myserver = Inputbox$("Type a server name", "Remote Console 
Task", "<server>")
	'mydatabase = uidoc.FieldgetText( "RI_MailFileNm" )
	Exec = Inputbox$("Enter a remote console task", "Remote 
Console Task", "Sh Ta")
	If exec = "" Then
		Exit Sub
	Else
		Msgbox remConsole.Execute(exec, myserver), 0, "Results"
	End If
End Sub

Dig Deeper on Domino Resources - Part 6

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close