Deklaration: 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 Beschreibung: Parameter:
dwDesiredAccess Konstanten: Private Const GENERIC_READ = &H80000000 ' Nur Lesen Private Const GENERIC_WRITE = &H40000000 ' Nur Schreiben Rückgabewert: Beispiel: 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&) 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 Diese Seite wurde bereits 27.861 mal aufgerufen. |
vb@rchiv CD Vol.6 ![]() ![]() Geballtes Wissen aus mehr als 8 Jahren vb@rchiv! Online-Update-Funktion Entwickler-Vollversionen u.v.m. Buchempfehlung Tipp des Monats ![]() Dieter Otter sevTabStrip: Rechtsklick auf Reiter erkennen Eine Funktion, mit der sich prüfen lässt, auf welchen Tab-Reiter ein Mausklick erfolgte Neu! sevCommand 4.0 ![]() Professionelle Schaltflächen im modernen Design! Mit nur wenigen Mausklicks statten auch Sie Ihre Anwendungen ab sofort mit grafischen Schaltflächen im modernen Look & Feel aus (WinXP, Office, Vista oder auch Windows 8), inkl. große Symbolbibliothek. |
||||||||||||||||||||||||
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein. |