Problem getting the date of a running EXE file 
Author Message
 Problem getting the date of a running EXE file

I'm using using some code from Randy Birch's VBNET site (
http://www.*-*-*.com/ ) 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.



Tue, 16 Aug 2011 21:14:49 GMT  
 Problem getting the date of a running EXE file
   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.

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.



Tue, 16 Aug 2011 23:43:28 GMT  
 Problem getting the date of a running EXE file


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).

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



Wed, 17 Aug 2011 08:14:18 GMT  
 Problem getting the date of a running EXE file

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).

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


Sat, 20 Aug 2011 08:06:41 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. VB4:Problems running exe-file

2. Getting an Icon from an exe file

3. QuickBasic 7 - Getting Path to .EXE File

4. Why getting HUGE EXE file in VB 4 32 bit

5. Getting a CLSID for a .EXE file

6. Getting .exe file version properties?

7. Getting info out of an .exe file

8. Getting icons from .EXE files

9. Getting icons from EXE files

10. getting name of exe file from task list

11. Getting an incon from exe-file

12. Getting an incon from exe-file

 

 
Powered by phpBB® Forum Software