|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Problem getting the date of a running EXE fileI'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. 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. > > > > "Martin" <ironwoodcan***@gmail.com> wrote in message You might want to try VB's own FileDateTime function. Also, after looking at 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). > 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 Martin wrote:
> I'm using using some code from Randy Birch's VBNET site ( You don't need to open a file to read its datestamps. Just call FindFirstFile and > 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). 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.
VB6 runtime is supported on Windows 7
Printing PictureBox Contents ListBox color Stupid Format$ Question Office 2003 installer pops up when loading a project FYI: MS UK VB6 Usage survey/poll - update Gradient Windows Update KB960715 blocks MSFLXGRD.OCX!!!!! Any solution ? Reading Stack from VB6 How to read XML data stream via a URL address into a string ? |
|||||||||||||||||||||||