-
Feb 6th, 2025, 05:36 AM
#1
Thread Starter
Fanatic Member
How can I change the file time with a single line of code on VB6 or using the API?
Is there a function in the Win32 API to change the file time, which would take the filename string as a parameter?
The only way I know of is using the inconvenient SetFileTime function. This feature is absolutely inconvenient and disgusting, I would not like to use it. Since it takes the handle of an open file as a parameter, it is extremely inconvenient.
-
Feb 6th, 2025, 05:54 AM
#2
Re: How can I change the file time with a single line of code on VB6 or using the API
A large majority of any kind of complex file operations use handles, pidls, or shell items. It's not that inconvenient to add the 3-4 lines to get a file handle.
Code:
Dim hFile as LongPtr
hFile = CreateFile(...)
SetFileTime hFile, ...
CloseHandle hFile
the horror 
You want inconvenient? Come on over to kernel mode and find out the horror of addressing files by their FILE_OBJECT.
Code:
Public Enum FILE_OBJECT_FLAGS
FO_FILE_OPEN = &H00000001
FO_SYNCHRONOUS_IO = &H00000002
FO_ALERTABLE_IO = &H00000004
FO_NO_INTERMEDIATE_BUFFERING = &H00000008
FO_WRITE_THROUGH = &H00000010
FO_SEQUENTIAL_ONLY = &H00000020
FO_CACHE_SUPPORTED = &H00000040
FO_NAMED_PIPE = &H00000080
FO_STREAM_FILE = &H00000100
FO_MAILSLOT = &H00000200
FO_GENERATE_AUDIT_ON_CLOSE = &H00000400
FO_QUEUE_IRP_TO_THREAD = FO_GENERATE_AUDIT_ON_CLOSE
FO_DIRECT_DEVICE_OPEN = &H00000800
FO_FILE_MODIFIED = &H00001000
FO_FILE_SIZE_CHANGED = &H00002000
FO_CLEANUP_COMPLETE = &H00004000
FO_TEMPORARY_FILE = &H00008000&
FO_DELETE_ON_CLOSE = &H00010000
FO_OPENED_CASE_SENSITIVE = &H00020000
FO_HANDLE_CREATED = &H00040000
FO_FILE_FAST_IO_READ = &H00080000
FO_RANDOM_ACCESS = &H00100000
FO_FILE_OPEN_CANCELLED = &H00200000
FO_VOLUME_OPEN = &H00400000
FO_BYPASS_IO_ENABLED = &H00800000 'when set BYPASS IO is enabled on this handle
FO_REMOTE_ORIGIN = &H01000000
FO_DISALLOW_EXCLUSIVE = &H02000000
FO_SKIP_COMPLETION_PORT = FO_DISALLOW_EXCLUSIVE
FO_SKIP_SET_EVENT = &H04000000
FO_SKIP_SET_FAST_IO = &H08000000
FO_INDIRECT_WAIT_OBJECT = &H10000000
FO_SECTION_MINSTORE_TREATMENT = &H20000000
End Enum
Public Type FILE_OBJECT
Type As Integer
Size As Integer
DeviceObject As LongPtr 'PDEVICE_OBJECT
Vpb As LongPtr 'PVBP
FsContext As LongPtr
FsContext2 As LongPtr
SectionObjectPointer As LongPtr 'PSECTION_OBJECT_POINTERS
PrivateCacheMap As LongPtr
FinalStatus As NTSTATUS
RelatedFileObject As LongPtr
LockOperation As Byte
DeletePending As Byte
ReadAccess As Byte
WriteAccess As Byte
DeleteAccess As Byte
SharedRead As Byte
SharedWrite As Byte
SharedDelete As Byte
Flags As FILE_OBJECT_FLAGS
FileName As UNICODE_STRING
CurrentByteOffset As LARGE_INTEGER
Waiters As Long
Busy As Long
LastLock As LongPtr
Lock As KEVENT
Event As KEVENT
CompletionContext As LongPtr 'PIO_COMPLETION_CONTEXT
IrpListLock As LongPtr
IrpList As LIST_ENTRY
FileObjectExtension As LongPtr
End Type 'Expected size x64=0xD8, x86=0x80
-
Feb 6th, 2025, 06:08 AM
#3
Thread Starter
Fanatic Member
Re: How can I change the file time with a single line of code on VB6 or using the API
This is unfair to all programmers in the world. Think about it yourself, why is there a SetFileAttributes function that accepts a filename string, but there is no such function to set the file time?
Why do I have to write so many lines of code instead of one line to change the file time?
Last edited by HackerVlad; Feb 6th, 2025 at 06:12 AM.
-
Feb 6th, 2025, 06:11 AM
#4
Thread Starter
Fanatic Member
Re: How can I change the file time with a single line of code on VB6 or using the API
Any average programmer likes simple and straightforward functions that take a filename string as a parameter, rather than some obscure technical numbers of open descriptors...
There is a difference between writing one line of code, specifying the file name in the function parameter, or writing 5 lines of code...
-
Feb 6th, 2025, 06:36 AM
#5
Re: How can I change the file time with a single line of code on VB6 or using the API
 Originally Posted by HackerVlad
Any average programmer likes simple and straightforward functions that take a filename string as a parameter, rather than some obscure technical numbers of open descriptors...
There is a difference between writing one line of code, specifying the file name in the function parameter, or writing 5 lines of code...
'RC6-OneLiner: (setting new last Access-, Write- and Creation-Timestamps)
New_c.FSO.SetFileAttributesEx "c:\temp\test.txt", , Now, Now - 1, Now - 2

Olaf
-
Feb 6th, 2025, 06:43 AM
#6
Re: How can I change the file time with a single line of code on VB6 or using the API
-
Feb 6th, 2025, 09:52 AM
#7
Re: How can I change the file time with a single line of code on VB6 or using the API
 Originally Posted by Schmidt
'RC6-OneLiner: (setting new last Access-, Write- and Creation-Timestamps)
New_c.FSO.SetFileAttributesEx "c:\temp\test.txt", , Now, Now - 1, Now - 2
Olaf
Ah but see while HackerVlad prefers as few lines as possible, he'd also prefer a 500 line solution to a 1-line 3rd party dependency *just for the IDE*, I fear you may have given him an aneurysm suggesting something that adds exe dependencies.
-
Feb 6th, 2025, 10:16 AM
#8
Re: How can I change the file time with a single line of code on VB6 or using the API
 Originally Posted by HackerVlad
Any average programmer likes simple and straightforward functions that take a filename string as a parameter, rather than some obscure technical numbers of open descriptors...
There is a difference between writing one line of code, specifying the file name in the function parameter, or writing 5 lines of code...
Well if you specify a name by string, then Windows has to do all the fancy opening work behind the scenes for you. Doing this any time you want to do anything to a file adds a ton of performance zapping overhead. So they only make APIs like that for scenarios where it's likely a one off thing while functions likely to be used as part of a larger file operation open it once then refer to that instance to do a bunch of things, then close. You'd have to ask them how they decide which side of that an operation falls on.
-
Feb 6th, 2025, 11:40 AM
#9
Thread Starter
Fanatic Member
Re: How can I change the file time with a single line of code on VB6 or using the API
Thanks for the answers. This means that it is impossible to do this in one line of code through the API.
By the way, I forgot to ask if there is such a built-in function in VB6? I didn't find something either.
-
Feb 6th, 2025, 11:50 AM
#10
Re: How can I change the file time with a single line of code on VB6 or using the API
No... There's a built in function to set common attributes (SetAttr) but not times.
-
Feb 6th, 2025, 05:39 PM
#11
Re: How can I change the file time with a single line of code on VB6 or using the API
 Originally Posted by fafalone
Ah but see while HackerVlad prefers as few lines as possible, he'd also prefer a 500 line solution to a 1-line 3rd party dependency *just for the IDE*, I fear you may have given him an aneurysm suggesting something that adds exe dependencies. 
Code:
Sub Test()
SetFileTimes App.Path & "\test.txt", "2025-2-1", "2025-2-2 11:11:11", "2025-2-3 12:13:14"
Dim CreationTime As Date, LastAccessTime As Date, LastWriteTime As Date
GetFileTimes App.Path & "\test.txt", CreationTime, LastAccessTime, LastWriteTime
Debug.Print "readFileTime:CreationTime=" & CreationTime & ",LastAccessTime=" & LastAccessTime & ",LastWriteTime=" & LastWriteTime
End Sub
vb6 GetFileTime,SetFileTime by Windows api-VBForums
https://www.vbforums.com/showthread....pi#post5670010
With this method, three times can be modified at the same time, and the time can also be read.In any case, this is not simple, and it also requires time zone conversion between different countries.
Changing the time of the file is like cracking, which is not normal behavior in itself.
The nickname of the questioner, he said I was a hacker.
The module can be simply packaged to edit the file modification time.
If you want to make a ransomware. Encrypt all the contents of the file, and then restore the file time.
There used to be a guy lying down for half a month. How can gambling succeed in making money in communication? Aren't we all having a good time?Whether these technologies may harm others or not, we are only discussing the feasibility of the technology.
Just like Bitcoin, if the goal of many people is to create a new dark net, a new bank, and destroy the country's banking system. Even Trump himself is going to invent a new type of Bitcoin. Being a president will earn him an extra 500 billion in assets.Or even open another bank.
Last edited by xiaoyao; Feb 6th, 2025 at 05:45 PM.
-
Feb 7th, 2025, 10:24 AM
#12
Re: How can I change the file time with a single line of code on VB6 or using the API
Please stay on topic and don't start any VB6 vs .NET arguments. Those don't go anywhere good.
My usual boring signature: Nothing
 
-
Feb 7th, 2025, 10:54 AM
#13
Re: How can I change the file time with a single line of code on VB6 or using the API
Maybe we need a dedicated forum for that so we can rehash the arguments for all eternity away from the normal people
-
Feb 7th, 2025, 11:06 AM
#14
Re: How can I change the file time with a single line of code on VB6 or using the API
If we can get a dedicated forum, can we also get 2 LLMs to argue both sides of debate for us eternally?
-
Feb 7th, 2025, 11:22 AM
#15
Re: How can I change the file time with a single line of code on VB6 or using the API
or just wrap the 3-4 lines into your own function that accepts the simplified parameters you desire. create the api you want.
-
Feb 7th, 2025, 11:50 AM
#16
Re: How can I change the file time with a single line of code on VB6 or using the API
 Originally Posted by HackerVlad
This is unfair to all programmers in the world. Think about it yourself, why is there a SetFileAttributes function that accepts a filename string, but there is no such function to set the file time?
Why do I have to write so many lines of code instead of one line to change the file time?
https://devblogs.microsoft.com/oldne...15-00/?p=17893
-
Feb 7th, 2025, 06:36 PM
#17
Re: How can I change the file time with a single line of code on VB6 or using the API
The NT team rewrote the operating system from scratch, and under the NT model, practically nothing was done by name. Nearly everything was done by handle. For example, to delete a file, you opened a handle to it and set the “delete on close” attribute, and then you closed the handle.
Even if you get windows. Disk drive lists are complex.The label of each hard disk is actually not C: \ by default. In fact, the inside is GUID.
So rc6 is a wrapper around various libraries of functionality. Sometimes we also need a way of packaging that is not net, but com ActiveX DLL.
Simply speaking, it is to make our own MFC. DLL, or source code library.
For example, a single line of code creates a multithread.
How to write a code implementation?modifies the height of the menu area and the size of the menu text. One line of code gets the height of multiple lines of text.
Two days ago, I was studying how to create a vector diagram with one sentence of code? Like triangles, arcs.
The most commonly used in this regard is how to create a QR code image with a single sentence of code.
Of course, the most popular is how to create a large AI model with a single line of code. For example, deepseek, in fact, a command line can not do, but also do a lot of settings. People who are not familiar with it may be able to do it for many days.
-
Feb 7th, 2025, 07:00 PM
#18
Re: How can I change the file time with a single line of code on VB6 or using the API
Microsoft's approach is to throw away after the development is completed, and never do a simpler package. He didn't even bother to upgrade.
In fact, many times we need an API to read registry entries. , VBS can do that.
Many of the advanced features are encapsulated in the net class libraries,
Like with the API. It should be possible to create a web socket client. But to create a server, Microsoft doesn't provide us with an interface.
In four lines of code on a web page, you can create a web socket client.
If only two lines of code are needed to create a websocket server, it will be much more convenient.
twinbasic,One year later, it is estimated that these very convenient functions will be realized.
Last edited by xiaoyao; Feb 7th, 2025 at 07:03 PM.
-
Feb 8th, 2025, 06:19 AM
#19
Re: How can I change the file time with a single line of code on VB6 or using the API
 Originally Posted by HackerVlad
Is there a function in the Win32 API to change the file time, which would take the filename string as a parameter?
The only way I know of is using the inconvenient SetFileTime function. This feature is absolutely inconvenient and disgusting, I would not like to use it. Since it takes the handle of an open file as a parameter, it is extremely inconvenient.
did you try..
Code:
Private Declare Function SetFileTime Lib "kernel32" _
(ByVal hFile As Long, _
lpCreationTime As FILETIME, _
lpLastAccessTime As FILETIME, _
lpLastWriteTime As FILETIME) As Long
to hunt a species to extinction is not logical !
since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.
-
Feb 8th, 2025, 07:09 AM
#20
Thread Starter
Fanatic Member
Re: How can I change the file time with a single line of code on VB6 or using the API
 Originally Posted by ChrisE
did you try..
Code:
Private Declare Function SetFileTime Lib "kernel32" _
(ByVal hFile As Long, _
lpCreationTime As FILETIME, _
lpLastAccessTime As FILETIME, _
lpLastWriteTime As FILETIME) As Long
Well, of course I use this code, unfortunately, there is no other choice. I have to use hFile. Although I would like a function that accepts a filename string, but it does not exist due to Microsoft's fault...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|