Illegal function call in Scheduled agent

I have an agent which transfers files between servers.When I ran the agent manually, working fine.When I schedule it I am getting an error: “Illegal function call”

My code goes like this:

Sub Tranportfiles

'Unix side handling to transfer the file to windows directory(C:\Lotus)

Dim GetFileName As String

Dim  FileDirPath As String

Dim FName As String

Dim UnCpath As String



'******Copy files from Unix to Windows *****

'Get File name path unix side

GetFileName$="\\ims4\ims4_usr2\lotusshare\sree\*.txt"    'Used to get actual file name in unix folder

FileDirPath$="\\ims4\ims4_usr2\lotusshare\sree\"			'Set the file directory path

FName$=Dir$(GetFileName$,0)						          'Get the File name

UnCpath$=FileDirPath$ & Fname$



'Setting up of the file paths windows side

IMPortFilepath$="C:\Lotus\*.txt"

Path$="C:\Lotus\"                       'Path of the directory.

CPath$=Path$ & FName$



'Loop through to move all the text file and kills the text files in unix side 

Do While FName$ <>""

	CPath$=Path$ & FName$

	Filecopy	UnCpath$,CPath$

	Kill UnCpath$		

	FName$=Dir$(GetFileName$,0)

	UnCpath$=FileDirPath$ & FName$

Loop

'************Moving the files over *************

End Sub '** End of Tranport sub routene**

I think FName$=Dir$(GetFileName$,0) is causing that error when I ran as a scheduled agent?

Am I doing any thing wrong…

Any help appreciated.

Regards,

Sree

Subject: Illegal function call in Scheduled agent

Break it down until it doesn’t fail and see which piece of code is throwing the error…

Subject: Did you sign the agent with the server’s id when you ran it as a schuduled agent.

Subject: Illegal function call in Scheduled agent

I did that and the line which is causing problem is FName$=Dir$(GetFileName$,0).Seems it doesn’t like Dir$ in a scheduled agent?

Subject: Okay, try something like this.

Set directory = New notesdbdirectory ( Inputbox$(“What is the Server Name?”)) Set db = directory.getfirstdatabase(database)

Actually you’ll hardcode the directory, but for testing it works well.

Subject: Never mind! I went brain-dead.

Subject: Illegal function call in Scheduled agent

This is due to the Domino server being started as a service and the server not having access to the unc path.

Workaround would be to start Domino server as application.