Personal Blog of Thomas Hampel - Creative Mythbusting in Development and Collaboration

Who am I?

Feeds

Delete Workstation ECL

Thomas Hampel
 17 November 2011

Recently I came across a situation where multiple workstations had a corrupted local ECL. The document itself was corrupted that it was not possible to edit nor refresh it automatically. The only chance was to rebuild the ECL completely by creating a new NAB, which of course is not what users want to do. With some little reverse engineering and the help of some friends, I've figured out how to use an (undocumented) Notes API call to delete the workstation ECL directly.
For those who want to do something similar, here is the sourcecode:


%REM

      Agent DeleteECL

%END REM

Option
Public
Option
Declare

Const
ERR_MASK = &H3fff
Const
PKG_MASK = &H3f00
Const
ERRNUM_MASK = &H00ff

Declare
Function NSFDbOpen Lib "nnotes.dll" (ByVal PathName As String, rethDB As Long) As Integer
Declare
Function NSFDbClose Lib "nnotes.dll" (ByVal hDB As Long) As Integer
Declare
Function NSFDbDeleteECL Lib "nnotes.dll" (ByVal hDB As Long, ByVal UserName As String, ByVal UserNameLen As Integer, ByVal ECLType As Integer) As Integer
Declare
Function OSLoadString Lib "nnotes.dll" (ByVal hModule As Long, ByVal stringCode As Integer, _
ByVal
retBuffer As String, ByVal bufferLength As Integer) As Integer

Sub
DeleteECL(Source As Button)
     
Dim rc%, build&, filename$
     
Dim hDB&
     
Dim s As New NotesSession
     
      build& =  s.NotesBuildVersion        

     
If build& <= 190 Then filename$ = "desktop5.dsk" Else filename$ = "names.nsf"
     
     
Print "Using desktop file : " & filename$
     
      rc% = NSFDbOpen (filename$, hDB&)

     
If rc% <> 0 Then
             
Print "Unable to open " & filename$
             
End
     
End If
     
      rc% = NSFDbDeleteECL  (hdb&, s.UserName,
Len (s.UserName), 1)
     
If rc% = 0 Then
             
Print "Successfully deleted local Workstation-ECL in file " & filename$ & " for user " & s.UserName
     
Else
             
Print "Not successful, returncode = " & rc%
             
Print GetAPIError  (rc%)
     
End If
     
      rc% = NSFDbDeleteECL  (hdb&, s.UserName,
Len (s.UserName), 2)
     
If rc% = 0 Then
             
Print "Successfully deleted local Applet-ECL in file " & filename$ & " for user " & s.UserName
     
Else
             
Print "Not successful, returncode = " & rc%
             
Print GetAPIError  (rc%)
     
End If
     
      rc% = NSFDbDeleteECL  (hdb&, s.UserName,
Len (s.UserName), 3)
     
If rc% = 0 Then
             
Print "Successfully deleted local JavaScript-ECL in file " & filename$ & " for user " & s.UserName
     
Else
             
Print "Not successful, returncode = " & rc%
             
Print GetAPIError  (rc%)
     
End If
      rc% = NSFDbClose (hDB&)

     

End
Sub
Function
GetAPIError (errorCode As Integer) As String
     
'** this function translates Notes API error codes into their
     
'** corresponding error strings
     
Dim errorString As String*256
     
Dim returnErrorString As String
     
Dim resultStringLength As Long
     
Dim errorCodeTranslated As Integer
     
     
'** mask off the top 2 bits of the errorCode that was returned; this is
     
'** what the ERR macro in the API does
      errorCodeTranslated = (errorCode
And ERR_MASK)
     
     
'** get the error code translation using the OSLoadString API function
      resultStringLength = OSLoadString(
0, errorCodeTranslated, errorString, Len(errorString) - 1)
     
     
'** strip off the null-termination on the string before you return it
     
If (InStr(errorString, Chr(0)) > 0) Then
              returnErrorString =
Left$(errorString, InStr(errorString, Chr(0)) - 1)
     
Else
              returnErrorString = errorString

     
End If
     
      GetAPIError = returnErrorString

     

End
Function
Comments [0]
Tagged with: Development
Go ElsewhereSubscribe to RSSAboutStay ConnectedAnd More
Thomas Hampel, All rights reserved.