Worauf muss ich achten wenn ich aus folgendem Code ein modul erstellen möchte
Private Declare Function CreateFile Lib "kernel32.dll" Alias "CreateFileA" \_
(ByVal lpFileName As String, ByVal dwDesiredAccess As Long, \_
ByVal dwShareMode As Long, lpSecurityAttributes As Any, \_
ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, \_
ByVal hTemplateFile As Long) As Long
Private Declare Function GetFileTime Lib "kernel32" (ByVal hFile As Long, \_
lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As \_
FILETIME) As Long
Private Declare Function FileTimeToLocalFileTime Lib "kernel32" (lpFileTime As \_
FILETIME, lpLocalFileTime As FILETIME) As Long
Private Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As \_
FILETIME, lpSystemTime As SYSTEMTIME) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) \_
As Long
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
' CreateFile dwDesiredAccess Konstanten
Private Const GENERIC\_READ = &H80000000 ' Nur Lesen
Private Const GENERIC\_WRITE = &H40000000 ' Nur Schreiben
' CreateFile dwShareMode Konstanten
Private Const FILE\_SHARE\_READ = &H1
Private Const FILE\_SHARE\_WRITE = &H2
' CreateFile dwCreationDisposition Konstanten
' ===========================================
' Erstellt eine neue Datei und überschreibt eine bereits vorhandene
Private Const CREATE\_ALWAYS = 2
' Erstellt eine neue Datei nur, wenn sie noch nicht existiert
Private Const CREATE\_NEW = 1
' Öffnet eine bereits vorhande Datei bzw. erstellt diese,
' wenn sie noch nicht existiert
Private Const OPEN\_ALWAYS = 4
' Öffnet eine bereits vorhandene Datei
Private Const OPEN\_EXISTING = 3
' Öffnet eine bereits vorhandene Datei und löscht den Inhalt
Private Const TRUNCATE\_EXISTING = 5
' CreateFile dwFlagsAndAttributes
' ===============================
Private Const FILE\_ATTRIBUTE\_ARCHIVE = &H20 ' Archiv
Private Const FILE\_ATTRIBUTE\_HIDDEN = &H2 ' Versteckt
Private Const FILE\_ATTRIBUTE\_NORMAL = &H80 ' Normal
Private Const FILE\_ATTRIBUTE\_READONLY = &H1 ' Schreibgeschützt
Private Const FILE\_ATTRIBUTE\_SYSTEM = &H4 ' Systemdatei
' Datei wird beim Schließen gelöscht
Private Const FILE\_FLAG\_DELETE\_ON\_CLOSE = &H4000000
' Es wird kein Puffer/Cache benutzt
Private Const FILE\_FLAG\_NO\_BUFFERING = &H20000000
' Erlaubt gleichzeitiges Lesen und Schreiben
' (nicht bei Windows 95, 98, CE)
Private Const FILE\_FLAG\_OVERLAPPED = &H40000000
' Erlaubt Case-Sensitive Dateinamen
Private Const FILE\_FLAG\_POSIX\_SEMANTICS = &H1000000
' Richtet den Puffer für einen Random-Access Zugriff aus
Private Const FILE\_FLAG\_RANDOM\_ACCESS = &H10000000
' Richtet den Puffer für einen sequentuellen Zugriff aus
Private Const FILE\_FLAG\_SEQUENTIAL\_SCAN = &H8000000
' Nutzt keinen Platten-Cache, sondern schreibt direkt in die Datei
Private Const FILE\_FLAG\_WRITE\_THROUGH = &H80000000
' Datumsinformationen einer Datei ermitteln (Erstellungsdatum)
Private Sub Command1\_Click()
Dim hFile As Long
Dim Retval As Long
Dim CTime As FILETIME
Dim STime As SYSTEMTIME
Dim Dummi As FILETIME
' Datei öffnen (nicht Erstellen, falls nicht vorhanden)
hFile = CreateFile("c:\autoexec.bat", GENERIC\_READ, FILE\_SHARE\_READ, \_
ByVal 0&, OPEN\_EXISTING, FILE\_ATTRIBUTE\_ARCHIVE, 0&:wink:
If hFile = -1 Then
MsgBox "Die Datei wurde nicht gefunden", vbOKOnly + vbInformation, \_
"Fehler"
Exit Sub
End If
' Erstellungsdatum ermitteln
GetFileTime hFile, CTime, Dummi, Dummi
' Konvertieren nach "Lokale Zeitzone"
FileTimeToLocalFileTime CTime, CTime
' In Systemzeit umwandeln
FileTimeToSystemTime CTime, STime
' Ausgabe des Datums
MsgBox "Die datei wurde erstellt am: " & STime.wDay & "." & \_
STime.wMonth & "." & STime.wYear, vbOKOnly + vbInformation, \_
"Erstellt am"
' Resourcen wieder frei geben
CloseHandle hFile
End Sub
[MOD] Pre-Tags eingefügt.