Option Compare Database
Option Explicit
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
Private Declare Function WaitForSingleObject Lib _
"kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds _
As Long) As Long
Declare Function CreateProcessA Lib "kernel32" _
(ByVal lpApplicationName As Long, _
ByVal lpCommandLine As String, _
ByVal lpProcessAttributes As Long, _
ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, _
ByVal lpCurrentDirectory As Long, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject _
As Long) As Long
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&
Function ShellCommand(s As String) As Long
Dim result As Long
'I tried this version but I imagine it didn't work, and I had to find the longer version.
'I've left it here in case you want to try it.
's = "C:\windows\system32\ftp.exe -ns:" & Chr(34) & CurrentProject.Path & "\FTPCollect.txt" & Chr(34)
'MsgBox s
result = Shell(s, 1)
ShellCommand = result
' ExecCommand "C:\windows\system32\ftp.exe -ns:e\databases\edifast\scripts\ftpcollect.txt", 1
' MsgBox result
End Function
Public Sub ExecCommand(cmdline$, screenmode&)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim retval As Long
'this was a test to show the ftp command line, and then exit
'MsgBox cmdline
'Exit Sub
Dim smode As Long
On Error Resume Next
smode = Nz(DLookup("ftpfocusmode", "tblconstants"), 0)
If smode = 0 Then smode = 1
' Initialize the STARTUPINFO structure:
start.cb = Len(start)
' Start the shelled application:
'params
'1 - appname
'2 =command line
'3 = processattributes
'4 = threadattributes
'5 = inherithandles
'6= creationflags
'7 = lpenvironment
'8 = currentdirectory
'9 = startupinfo
'10 = processinfo
On Error GoTo fail
retval = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
' Wait for the shelled application to finish:
retval = WaitForSingleObject(proc.hProcess, INFINITE)
retval = CloseHandle(proc.hProcess)
exithere:
Exit Sub
fail:
Call MsgBox("Error: " & err & " Desc: " & err.Description)
Resume exithere
End Sub