Hallo,
ich habe die Foremsuche verwendet um Beispiele anzuschauen. Leider habe ich es nicht geschaft diese script von eknori zum laufen zu bringen.
Hintergrund:
Der Agent soll jeden tag um 12:00 Uhr ein Zip Datei entpacken und die Dateien in die eigene Datenbank importieren.
Ich habe unzip.exe runtergeladen und unter Windows/system32 kopiert. Die komplette Script von eknori habe ich unter Declaration eingefügt und unter Initialize aufgerufen:
************************************************
Sub Initialize
Dim Files As String
Dim ExtractTo As String
Files = "c:\test.zip"
ExtractTo = "c:\temp"
Call Unzip(Files,ExtractTo)
End Sub
************************************************
Script von Eknori:
************************************************
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
Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Declare Function WaitForSingleObject Lib "kernel32" (Byval hHandle As Long, Byval dwMilliseconds As Long) As Long
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (Byval hwnd As Long, Byval lpOperation As String, Byval lpFile As String, Byval lpParameters As String, Byval lpDirectory As String, Byval nShowCmd 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
'// Options for unzip.exe
'// for more options see the documentation of "unzip.exe"
Const QUIETMODE = " -qq " ' do not show messages
Const OVERWRITE = " -o " ' overwrite existing files
Const NEVER_OVERWRITE = " -n " ' never overwrite existing files
Const REFRESH = " -f " ' freshen existing file, create none
Const UPDATE = " -u " ' update files, create if necessary
Const ZIPINFO = " -Z -t " ' Summary of Zip-File
Const ZIPINFO_VERBOSE = " -Z -2 -t " ' Like ZIPINFO including FileNames
Const ZIPINFO_FILE = "~ZIPINFO.TMP" ' File containing ZIP-Informations
Const ZIPINFO_WZUNZIP = " -v "
Class UnzipFile
Private ExeFile As String
Private ExtractTo As String
Private FilesToExtract As String
Private UnzipOptions As String
Declare Public Sub New(UnzipExe As String, ExtractFilesTo As String)
Declare Private Function IsPathAvailable(path As String) As Variant
Declare Private Function IsDriveAvailable(drivNam$) As Variant
Declare Public Function Unzip(Files As String, Options As String)
Declare Public Function ZipInfo(Files As String)
Declare Private Sub ShellAndWait(Byval RunProg As String)
Declare Public Property Get Executable As String
Declare Public Property Set Executable As String
Declare Public Property Get TargetPath As String
Declare Public Property Set TargetPath As String
Sub New (UnzipExe As String, ExtractFilesTo As String)
'// Constructor
ExeFile = UnzipExe
dummy = IsPathAvailable(ExtractFilesTo)
ExtractTo = ExtractFilesTo
End Sub
Public Property Get Executable As String
Executable = ExeFile
End Property
Public Property Set Executable As String
ExeFile = Executable
End Property
Public Property Get TargetPath As String
TargetPath = ExtractTo
End Property
Public Property Set TargetPath As String
dummy = IsPathAvailable(TargetPath)
ExtractTo = TargetPath
End Property
Public Function Unzip(Files As String, Options As String)
'// Unzip Files
FilesToExtract = Files
UnzipOptions = Options
CommandStr = ExeFile & UnzipOptions & FilesToExtract & " -d " & ExtractTo
Call ShellAndWait(CommandStr)
End Function
Public Function ZipInfo(Files As String)
'// Unzip Files
FilesToExtract = Files
CommandStr = ExeFile & ZIPINFO_WZUNZIP & FilesToExtract & " > ZIPINFO"
Call ShellAndWait(CommandStr)
Msgbox ZIPINFO
End Function
Private Function IsDriveAvailable(drivNam$) As Variant
'// Test for existing drive and Path
'// if Path does not exist, create it
On Error Goto Errors
IsDriveAvailable = False
If Dir$(drivNam,
<> "" Then
IsDriveAvailable = True
End If
TheEnd:
Exit Function
Errors:
Resume TheEnd
End Function
Private Function IsPathAvailable(path As String) As Variant
'// Test, ob das Pfad vorhanden ist; wenn nicht, wird Pfad angelegt
Dim session As New NotesSession
Dim MyPath$, tmpPath$
Dim result%, pos%
On Error Resume Next
If IsDriveAvailable(Left(path,3)) Then
Chdrive Left( path, 1 )
Chdir path
result = False
pos = 1
If Curdir + "\" <> path Then
If Right( path, 1 ) <> "\" Then path = path + "\"
If path = "" Then Goto Exit_CheckDir
Chdrive Left( path, 1 )
Do While pos <> 0
pos = Instr( pos, path, "\" )
If pos > 0 Then
tmpPath = Left( path, pos-1 )
Mkdir tmpPath
Chdir tmpPath
pos = pos + 1
End If
Loop
If Curdir + "\" = path Then
result = True
End If
Else
result = True
End If
Else
End If
Exit_checkDir:
IsPathAvailable = result
Exit Function
End Function
Private Sub ShellAndWait(Byval RunProg As String)
Dim proc As PROCESS_INFORMATION
Dim StartInf As STARTUPINFO
StartInf.cb = Len(StartInf)
RetVal = CreateProcessA(0&, RunProg, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, StartInf, proc)
RetVal = WaitForSingleObject(proc.hProcess, INFINITE)
RetVal = CloseHandle(proc.hProcess)
End Sub
End Class
************************************************
Bin in LS nicht gut, irgendwo mache ich eine große denkfehler. Währe nett wenn jemand mir eine kleine hilfe für die problem Lösung anbietet.
Gruss
Ozan