Home All Groups Group Topic Archive Search About

Problem getting the date of a running EXE file

Author
27 Feb 2009 1:14 PM
Martin
I'm using using some code from Randy Birch's VBNET site (
http://vbnet.mvps.org/code/fileapi/filedatetime.htm ) to get the
"modified" date from a series of .exe files so that my program can
then make use of the latest one (it launches it using a Shell
command). However, it appears that if one of the .exe files is already
running then the dates cannot be retrieved (apparently, the OpenFile
function fails if the executable is running).

Does anyone know if there's a way around this?

Thanks.

Author
27 Feb 2009 3:43 PM
mayayana
You might try Shell. Someone may offer an
API solution eventually, which would be better than
using the Shell object, but if not you could try the
following and see if it works:

Set a reference to MS Shell Objects and Controls

Set oFol = SH.Namespace(folderpath)

where oFol is a Folder2 object in the Shell hierarchy.

A Folder object has an Items member, which returns
a FolderItems collection. That has its own FolderItem
member, which is a file/folder that has numerous properties.

  The only caveat is that Shell actually represents Explorer's
visual version of the file system. FolderItems will probably
not include hidden files and may not include some system
file types.


Show quoteHide quote
> I'm using using some code from Randy Birch's VBNET site (
> http://vbnet.mvps.org/code/fileapi/filedatetime.htm ) to get the
> "modified" date from a series of .exe files so that my program can
> then make use of the latest one (it launches it using a Shell
> command). However, it appears that if one of the .exe files is already
> running then the dates cannot be retrieved (apparently, the OpenFile
> function fails if the executable is running).
>
> Does anyone know if there's a way around this?
>
> Thanks.
>
>
>
>
Author
28 Feb 2009 12:14 AM
MikeD
"Martin" <ironwoodcan***@gmail.com> wrote in message
news:ckpfq4pppc45vep6ug0gs2otfk53oojhot@4ax.com...
> I'm using using some code from Randy Birch's VBNET site (
> http://vbnet.mvps.org/code/fileapi/filedatetime.htm ) to get the
> "modified" date from a series of .exe files so that my program can
> then make use of the latest one (it launches it using a Shell
> command). However, it appears that if one of the .exe files is already
> running then the dates cannot be retrieved (apparently, the OpenFile
> function fails if the executable is running).
>

You might want to try VB's own FileDateTime function. Also, after looking at
Randy's code and assuming you didn't modify this part of it, he's opening
the file for reading AND writing.  Try opening the file for just reading by
using OF_READ instead of OF_READWRITE. Here's the constant declaration:

Private Const OF_READ = &H0

However, checking the file's date stamp (created, modified, last accessed)
may not be best way to deal with this because a file's date stamp is not
always a reliable means of determining the most recent version of a file. A
better way, IMO, would be to check the file's actual version number if it
has one. This is what installers (even just half decent ones) check when
determining if an existing file should be overwritten.

Of course, I'm kind of making an assumption that these exe files are the
same program, and have the same names so therefore must exist in different
folders. If that's the case, the the *best* thing to do is delete the old
versions. Seems a little bit bizarre to me what you are doing (or why you
need to do this).

--
Mike
Author
3 Mar 2009 12:06 AM
Karl E. Peterson
Martin wrote:
> I'm using using some code from Randy Birch's VBNET site (
> http://vbnet.mvps.org/code/fileapi/filedatetime.htm ) to get the
> "modified" date from a series of .exe files so that my program can
> then make use of the latest one (it launches it using a Shell
> command). However, it appears that if one of the .exe files is already
> running then the dates cannot be retrieved (apparently, the OpenFile
> function fails if the executable is running).

You don't need to open a file to read its datestamps.  Just call FindFirstFile and
examine the returned WIN32_FIND_DATA structure.  See
http://vb.mvps.org/samples/FileInfo for a drop in class module that'll do it for
you.
--
..NET: It's About Trust!
http://vfred.mvps.org