Home > Domino Tips > Administrator > Server > Shortcut for executing server commands
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

SERVER

Shortcut for executing server commands


Steve Holman
10.09.2001
Rating: -4.53- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


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



Code

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

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Server
How to move Notes databases off Domino 8 servers and save disk space
Move a Lotus Domino server to a new certifier without a reinstall
Securely connect Lotus Domino servers on different domains
Track and record Lotus Notes user logins to Domino Server
Use SMTP outbound authentication to relay hosts in Lotus Notes Domino 8
Log off idle Lotus Notes users for better Domino Server performance
Copy Lotus Notes databases from the Domino Server console command line
How to perform an in-place upgrade of Lotus Domino server hardware
Daylight Saving Time 2007 -- seven helpful tips for Lotus Notes administrators
FileZilla

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts