Page 1 sur 1

Executer les commandes consoles sur le serveur

MessagePublié: 19 Avr 2007 à 14:27
par Michael DELIQUE
Code : Tout sélectionner
Public Function ExecuteCommandeServeur_API(Byval wServer As String, Byval wCommande As String) As Long
' Execute les commandes consoles sur le serveur   
   
%REM
Declare Function NSFRemoteConsole Lib "nnotes.dll" (Byval ServerName As String, Byval ConsoleCommand As String, rethBuffer As Long) As Long
Declare Function OSLockObject Lib "nnotes.dll" ( Byval lHandle As Long ) As Long
Declare Function OSUnlockObject Lib "nnotes.dll" ( Byval lHandle As Long ) As Integer
Declare Function OSMemFree Lib "nnotes" (Byval Handle As Long) As Integer
%END REM
   
      'Déclaraton Variable
   Dim nbBuf As Long
   Dim pBuf As String
   
   On Error Goto ErreurExecuteCommandeServeur_API
   
   ExecuteCommandeServeur_API = NSFRemoteConsole(wServer, wCommande, nbBuf)
   pBuf = OSLockObject(nbBuf)
   
   Call OSUnlockObject(nbBuf)
   Call OSMemFree(nbBuf)
   
   pBuf = ""
   
   Exit Function
ErreurExecuteCommandeServeur_API:
   Msgbox "("+Cstr(Getthreadinfo (1))+")"+Chr(10)+"Erreur " + Str(Err) + " : "+Chr(10) + Cstr(Error)+". "+Chr(10)+"Ligne N° "+Cstr(Erl),16," ERREUR !"
   Exit Function
End Function

MessagePublié: 19 Avr 2007 à 14:32
par Michael DELIQUE
cette fonction utilise l'api pour faire un broadcast, doit être exécuté depuis un agent sur le server

Code : Tout sélectionner
Public Sub Broadcast(Byval wServer As String, Byval wMessage As String, wUser As String )
    'Déclaration Variable
   Dim Commande As String
   Dim nmServer As NotesName
   Dim nmUser As NotesName
   
   On Error Goto ErreurBroadcast
   
   If Trim(wMessage) = "" Then
      Error 9999,"no message"
      Exit Sub
   End If
   
   If Trim(wUser) = "" Then
      Error 9999,"no user"
      Exit Sub
   Else
      Set nmUser = New NotesName(wUser)
   End If
   
   
   If Trim(wServer) = "" Then
      If Session Is Nothing Then
         Set Session = New NotesSession
      End If
      Set nmServer = New NotesName(Session.CurrentDatabase.Server)
   Else
      Set nmServer = New NotesName(wServer)
   End If
   
   Commande = {Broadcast "(!)}+wMessage+{""}+Cstr(nmUser.Abbreviated)+{"}
   
   Call ExecuteCommandeServeur_API(Cstr(nmServer.abbreviated),Commande)
   
   Set nmServer = Nothing
   Set nmUser = Nothing
   Commande = ""
   
   Exit Sub
ErreurBroadcast:
   Msgbox "("+Cstr(Getthreadinfo (1))+")"+Chr(10)+"Erreur " + Str(Err) + " : "+Chr(10) + Cstr(Error)+". "+Chr(10)+"Ligne N° "+Cstr(Erl),16," ERREUR !"
   exit Sub
End Sub

MessagePublié: 19 Avr 2007 à 14:34
par JYR
Salut Michael,

Simple cunriosité. J'ai utilisé des API semblables pas le passé. Dans mon cas, je les lançais à partir de mon poste. Toi, c'est pour lancer à partir d'un agent programmé?

Dans mon cas, je n'ai jamais fait confiance à des API "sensibles" de ce type :D

En V6, il s'agit maintenant de fonctions incluses dans le Notessession (SendConsoleCOmmand)

JYR

MessagePublié: 19 Avr 2007 à 14:35
par JYR
Tu as posté durant que j'écrivais ma réponse. :P

MessagePublié: 19 Avr 2007 à 14:54
par Michael DELIQUE
Hello JYR

J'avais mis ça au point en V5 pour un agent lancé depuis un client lourd via un RunOnServer et pour mon besoin c'était très stable.

Et je n'ai pas mis a jours ma fonction avec le nouvel objet V6 mais ça n'est pas grand chose à faire

MessagePublié: 25 Avr 2007 à 09:43
par oguruma
oui en effet, c'est dispo en V6 maintenant plus besoin des api ;)

MessagePublié: 21 Mai 2007 à 13:05
par Michael DELIQUE
pour info

voici la commande qui remplace l'API à partir de la V6:

notesSession.SendConsoleCommand