Need a scheduled agent to delete an agent

As part of a bigger project, I’m trying to delete the Out Of Office agent from users’ mailfiles.I am able to programatically disable the OOO agent, but when I try to delete it I get the message that I “Can’t remove agent belonging to another user”.

  1. Before I do anything, the OOO agent.Owner and agent.CommonOwner properties return the name of the user.

  2. After I run a scheduled agent to disable the OOO agent, both properties return the name of the server.

  3. I then run a second scheduled agent to delete the OOO agent and get the error I mentioned (belongs to someone else).

We have a single ID for production agent use which has all admin rights and I’ve also played with the “run on behalf of” settings, but I can’t find the magic combination that will allow me to delete the OOO agent. I either need to “take ownership” of it or delete someone else’s agent!

UPDATE: I was able to delete if I changed the scheduled delete agent to run on behalf of the server’s ID. Worst case this means a dedicated agent for each server, but I hope there is a more elegant solution.

Thank you for any help.

Subject: Need a scheduled agent to delete an agent

Some ideas you could try:

  1. Remove the OOO agent from the mail template and do a “load design” from the server console (unless they have design locked the OOO agent, which you could perhaps also programmatically unlock before though).

  2. Sub Initialize

    Dim session As New NotesSession

    Dim agent As NotesAgent

    Dim doc As NotesDocument

    Dim db As New notesdatabase(“”,“”)

'make this loop through your mail databases

server= ?

maildatabasename = ?

db.Open server,maildatabasename

Set agent=db.getagent("OOOAgentName")

xurl = agent.NotesURL

xp = Instr( xurl, ".nsf" )

xunid = Mid( xurl, xp+5, 32)

Set doc = db.getdocumentbyunid( xunid )

doc.remove True

    db.Close

'end loop

End Sub

Subject: Re: Need a scheduled agent to delete an agent

Mika:That worked. Thank you for the response! I find it interesting that when manipulating agents via the agent class you cannot delete in certain circumstances, but using the notes document class (as you demonstrated) they can be deleted.

Subject: Why not simply replace the design of the desired users’ mailfiles with a template which doesn’t have an OOO agent?

Subject: Thanks for the suggestion, but it is more complicated than that. I omitted many details for brevity.