VB HELP NEEDED FOR THIS understanding THIS CODE

mhouldridge
10-29-2004, 03:36 AM
Hi,

I would like to know what the Split(Command(),"") part of the below script does.... near the beginning. This script has been taken from a mail server program. It has the function to allow you to delete any emails that coontain executables.

Dim sMsgCommandFile as String
Dim sMsgFile as String
Dim hFile As Long
Dim args() As String
Dim sFileLine as String

args() = Split(Command(), " ")
sMsgCommandFile = GetRegistryString("SOFTWARE\Mail Enable\Mail Enable", "Data Directory") & _
"\QUEUES\" & args(1) & "\Inbound\" & args(0)
sMsgFile = GetRegistryString("SOFTWARE\Mail Enable\Mail Enable", "Data Directory") & _
"\QUEUES\" & args(1) & "\Inbound\Messages\" & args(0)
hFile = FreeFile
bPerformAction = False
On Error goto Err Handler
Open sMsgFile For Input as #hFile
While Not EOF(hFile)
Line Input #hFile, sFileLine
if Instr(1,lCase(sFileLine),".exe") Then
bPerformAction = True
Exit While
end if
Wend
Close (hFile)
if PerformAction = True Then
Kill(MsgCommandFile)
Kill(MsgFile)
Exit Sub

ErrHandler:
App.LogEvent "Could not process pickup event for Connector: " & ConnectorCode & _
" Message ID: " & MessageID
End Sub

DeX
10-29-2004, 03:57 AM
Command will return any arguments that have been passed to the application. For example if you run the program from a command line like this:

myapp.exe -min -debug

Then Command will return "-min -debug". The split command is used to sperarate the individual command line arguments. In this example args(0) will be "-min" and args(1) will be "-debug".

Diurnal
10-29-2004, 08:46 AM
Dim sMsgCommandFile As String
Dim sMsgFile As String
Dim hFile As Long
Dim args() As String
Dim sFileLine As String

'Create an array of commands from the command line input [See Command$, Splt function in MSDN]
args() = Split(Command(), " ")

'Use the return of the command line to retrieve some regsistry settings.
'There is an assumption here that the command line input was not empty.
sMsgCommandFile = GetRegistryString("SOFTWARE\Mail Enable\Mail Enable", "Data Directory") & _
"\QUEUES\" & args(1) & "\Inbound\" & args(0)

sMsgFile = GetRegistryString("SOFTWARE\Mail Enable\Mail Enable", "Data Directory") & _
"\QUEUES\" & args(1) & "\Inbound\Messages\" & args(0)

'Open a file and loop through looking for executables in each line.
hFile = FreeFile
bPerformAction = False

On Error GoTo ErrHandler

Open sMsgFile For Input As #hFile
Do Until EOF(hFile)
Line Input #hFile, sFileLine
If InStr(1, LCase(sFileLine), ".exe") Then
'If executable found, then set flag to remove it.
bPerformAction = True
Exit Do
End If
Loop
Close (hFile)

'Check kill file flag and remove the file if an executable was found.
If PerformAction = True Then
Kill (MsgCommandFile)
Kill (MsgFile)
'Exit Sub
End If

'Exit the sub before running through the error handler.
Exit Sub

ErrHandler:
App.LogEvent "Could not process pickup event for Connector: " & ConnectorCode & _
" Message ID: " & MessageID

End Sub

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum