1. Наверное это вопрос уже обсуждался, но поиск у меня выдает ошибку. Как определить есть или нет установленный принтер?
2. Пытаюсь менять «файловое время», но ф-я SetFileTime срабатывает не всегда? А изменять дату последнего доступа к exe файлам вообще не хочет. Использую следующий код, может в ф-ю CreateFile другие константы нужно передать?
Option Explicit
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Dim OFName As OPENFILENAME
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) 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
Private Const GENERIC_WRITE = &H40000000
Private Const OPEN_EXISTING = 3
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SystemTime, lpFileTime As FILETIME) As Long
Private Declare Function LocalFileTimeToFileTime Lib "kernel32" (lpLocalFileTime As FILETIME, lpFileTime As FILETIME) As Long
Private Declare Function SetFileTime Lib "kernel32.dll" (ByVal hfile As Long, ByRef lpCreationTime As FILETIME, ByRef lpLastAccessTime As FILETIME, ByRef lpLastWriteTime As FILETIME) As Long
Private Declare Function ExtractAssociatedIcon Lib "shell32.dll" Alias "ExtractAssociatedIconA" (ByVal hInst As Long, ByVal lpIconPath As String, lpiIcon As Long) As Long
Private Declare Function DrawIcon Lib "user32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal hIcon As Long) As Long
Private Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long
Dim sPath As String
Private Sub ChengeFileTime(sPath As String)
Dim nDate As Date
Dim hfile As Long
Dim nCreatedTime As FILETIME
Dim nModifiedTime As FILETIME
Dim nAccessedTime As FILETIME
Dim SysTime As SystemTime
nDate = CDate(lblCreated.Caption)
With SysTime
.wYear = Year(nDate)
.wMonth = Month(nDate)
.wDay = Day(nDate)
.wDayOfWeek = Weekday(nDate) - 1
.wHour = Hour(nDate)
.wMinute = Minute(nDate)
.wSecond = Second(nDate)
.wMilliseconds = 0
End With
SystemTimeToFileTime SysTime, nCreatedTime
LocalFileTimeToFileTime nCreatedTime, nCreatedTime
nDate = CDate(lblModified.Caption)
With SysTime
.wYear = Year(nDate)
.wMonth = Month(nDate)
.wDay = Day(nDate)
.wDayOfWeek = Weekday(nDate) - 1
.wHour = Hour(nDate)
.wMinute = Minute(nDate)
.wSecond = Second(nDate)
.wMilliseconds = 0
End With
SystemTimeToFileTime SysTime, nModifiedTime
LocalFileTimeToFileTime nModifiedTime, nModifiedTime
nDate = CDate(lblAccessed.Caption)
With SysTime
.wYear = Year(nDate)
.wMonth = Month(nDate)
.wDay = Day(nDate)
.wDayOfWeek = Weekday(nDate) - 1
.wHour = Hour(nDate)
.wMinute = Minute(nDate)
.wSecond = Second(nDate)
.wMilliseconds = 0
End With
SystemTimeToFileTime SysTime, nAccessedTime
LocalFileTimeToFileTime nAccessedTime, nAccessedTime
hfile = CreateFile(sPath, GENERIC_WRITE Or FILE_SHARE_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)
SetFileTime hfile, nCreatedTime, nAccessedTime, nModifiedTime
CloseHandle hfile
End Sub
Ответить
|