VS_VERSION_INFO question
-
OK so here's my current situation. I have a program that I put in the shared network drive. People are using this program a lot, so upgrading is a bit pain in the neck. First I have to rename the exe, copy the new exe, then find all the active instances of the program and close them, then delete it. Works great until couple weeks ago where I thought I close every active instance and I still couldn't delete it. Had to ask admin guy to delete it. So I decide to go with slightly more clever way: get a timer to periodically check the exe version. Suppose I have a.exe, and I rename a.exe to a.exe.bak and put a.exe with newer version in. If somebody still have the instance of a.exe.bak running, it will check a.exe for newer version, and will close that instance. Great in theory, but it doesnt happen! For some reason the code to check the version using GetVersionInfo("a.exe"...) always return the old version even if the old a.exe has been renamed to a.exe.bak and a.exe that has higher version is put in the same directory. I suspect this is because the code still thinks the handle to open the old a.exe is still open or something. Any help? Thanks a bunch!
-
OK so here's my current situation. I have a program that I put in the shared network drive. People are using this program a lot, so upgrading is a bit pain in the neck. First I have to rename the exe, copy the new exe, then find all the active instances of the program and close them, then delete it. Works great until couple weeks ago where I thought I close every active instance and I still couldn't delete it. Had to ask admin guy to delete it. So I decide to go with slightly more clever way: get a timer to periodically check the exe version. Suppose I have a.exe, and I rename a.exe to a.exe.bak and put a.exe with newer version in. If somebody still have the instance of a.exe.bak running, it will check a.exe for newer version, and will close that instance. Great in theory, but it doesnt happen! For some reason the code to check the version using GetVersionInfo("a.exe"...) always return the old version even if the old a.exe has been renamed to a.exe.bak and a.exe that has higher version is put in the same directory. I suspect this is because the code still thinks the handle to open the old a.exe is still open or something. Any help? Thanks a bunch!
So is your question about
GetVersionInfo()
returning the correct value, or how to copy over a potentially in-use file? -
So is your question about
GetVersionInfo()
returning the correct value, or how to copy over a potentially in-use file? -
This article should help: http://www.microsoft.com/msj/0498/c0498.aspx
-
OK so here's my current situation. I have a program that I put in the shared network drive. People are using this program a lot, so upgrading is a bit pain in the neck. First I have to rename the exe, copy the new exe, then find all the active instances of the program and close them, then delete it. Works great until couple weeks ago where I thought I close every active instance and I still couldn't delete it. Had to ask admin guy to delete it. So I decide to go with slightly more clever way: get a timer to periodically check the exe version. Suppose I have a.exe, and I rename a.exe to a.exe.bak and put a.exe with newer version in. If somebody still have the instance of a.exe.bak running, it will check a.exe for newer version, and will close that instance. Great in theory, but it doesnt happen! For some reason the code to check the version using GetVersionInfo("a.exe"...) always return the old version even if the old a.exe has been renamed to a.exe.bak and a.exe that has higher version is put in the same directory. I suspect this is because the code still thinks the handle to open the old a.exe is still open or something. Any help? Thanks a bunch!
I use the following in a application.. It seems to work fine for pulling the version info..
CString CMainFrame::GetVerInfo(CString strFile)
{
DWORD size = GetFileVersionInfoSize(strFile.LockBuffer(),0);
strFile.UnlockBuffer();if(size > 0) { CString results; char \*pData = new char\[size\]; // GET THE FILE VERSION AND STORE IT IN pData if(GetFileVersionInfo(strFile.LockBuffer(), 0, size, pData)) { strFile.UnlockBuffer(); VS\_FIXEDFILEINFO\* lpvi; UINT iLen; if(VerQueryValue(pData,"\\\\", (void \*\*)&lpvi, &iLen)) { // FORMAT THE VERSION EXAMPLE ( 1.2.3.1 ).. results.Format("%u.%u.%u.%u",HIWORD(lpvi->dwFileVersionMS), LOWORD(lpvi->dwFileVersionMS), HIWORD(lpvi->dwFileVersionLS), LOWORD(lpvi->dwFileVersionLS)); } } // CLEAN UP delete\[\] pData; return results; } else return "Unknown";
}
Rob Whoever said nothing's impossible never tried slamming a revolving door!
-
I use the following in a application.. It seems to work fine for pulling the version info..
CString CMainFrame::GetVerInfo(CString strFile)
{
DWORD size = GetFileVersionInfoSize(strFile.LockBuffer(),0);
strFile.UnlockBuffer();if(size > 0) { CString results; char \*pData = new char\[size\]; // GET THE FILE VERSION AND STORE IT IN pData if(GetFileVersionInfo(strFile.LockBuffer(), 0, size, pData)) { strFile.UnlockBuffer(); VS\_FIXEDFILEINFO\* lpvi; UINT iLen; if(VerQueryValue(pData,"\\\\", (void \*\*)&lpvi, &iLen)) { // FORMAT THE VERSION EXAMPLE ( 1.2.3.1 ).. results.Format("%u.%u.%u.%u",HIWORD(lpvi->dwFileVersionMS), LOWORD(lpvi->dwFileVersionMS), HIWORD(lpvi->dwFileVersionLS), LOWORD(lpvi->dwFileVersionLS)); } } // CLEAN UP delete\[\] pData; return results; } else return "Unknown";
}
Rob Whoever said nothing's impossible never tried slamming a revolving door!
BOOL CVersionDlg::OnInitDialog() { ......... regular MFC exe wizard ....... SetTimer(1, 5000, NULL); return TRUE; // return TRUE unless you set the focus to a control } void CVersionDlg::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default CString strFile = "E:\\MyProjects\\version\\Debug\\version.exe"; DWORD size = GetFileVersionInfoSize(strFile.LockBuffer(),0); strFile.UnlockBuffer(); if(size > 0) { CString results; char *pData = new char[size]; // GET THE FILE VERSION AND STORE IT IN pData if(GetFileVersionInfo(strFile.LockBuffer(), 0, size, pData)) { strFile.UnlockBuffer(); VS_FIXEDFILEINFO* lpvi; UINT iLen; if(VerQueryValue(pData,"\\", (void **)&lpvi, &iLen)) { // FORMAT THE VERSION EXAMPLE ( 1.2.3.1 ).. results.Format("%u.%u.%u.%u",HIWORD(lpvi->dwFileVersionMS),LOWORD(lpvi->dwFileVersionMS), HIWORD(lpvi->dwFileVersionLS),LOWORD(lpvi->dwFileVersionLS)); MessageBox("Version", results); } } delete[] pData; } CDialog::OnTimer(nIDEvent); } Make 2 version.exe, put one with version 1.0.0.1 (version1.exe) and the other one 1.0.0.5 (version5.exe). Copy version1.exe to version.exe. Run version.exe. A dialog should pop up 1.0.0.1 every 5 seconds. Rename version.exe to version.bak. The dialog should cease popping up. Copy version5.exe to version.exe. The dialog will pop up again still with 10.0.0.1 (while it should be 10.0.0.5). So still no solution :confused:
-
BOOL CVersionDlg::OnInitDialog() { ......... regular MFC exe wizard ....... SetTimer(1, 5000, NULL); return TRUE; // return TRUE unless you set the focus to a control } void CVersionDlg::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default CString strFile = "E:\\MyProjects\\version\\Debug\\version.exe"; DWORD size = GetFileVersionInfoSize(strFile.LockBuffer(),0); strFile.UnlockBuffer(); if(size > 0) { CString results; char *pData = new char[size]; // GET THE FILE VERSION AND STORE IT IN pData if(GetFileVersionInfo(strFile.LockBuffer(), 0, size, pData)) { strFile.UnlockBuffer(); VS_FIXEDFILEINFO* lpvi; UINT iLen; if(VerQueryValue(pData,"\\", (void **)&lpvi, &iLen)) { // FORMAT THE VERSION EXAMPLE ( 1.2.3.1 ).. results.Format("%u.%u.%u.%u",HIWORD(lpvi->dwFileVersionMS),LOWORD(lpvi->dwFileVersionMS), HIWORD(lpvi->dwFileVersionLS),LOWORD(lpvi->dwFileVersionLS)); MessageBox("Version", results); } } delete[] pData; } CDialog::OnTimer(nIDEvent); } Make 2 version.exe, put one with version 1.0.0.1 (version1.exe) and the other one 1.0.0.5 (version5.exe). Copy version1.exe to version.exe. Run version.exe. A dialog should pop up 1.0.0.1 every 5 seconds. Rename version.exe to version.bak. The dialog should cease popping up. Copy version5.exe to version.exe. The dialog will pop up again still with 10.0.0.1 (while it should be 10.0.0.5). So still no solution :confused:
I'm assuming that version.exe is not the name of the program that this code is in right? If it is, I didn't think you could rename the exe while it was running.. If not, not sure why it's not working, strange.. Is your file name/path defined in the timer like the code above or are you actually putting the file name/path in a member variable? Rob Whoever said nothing's impossible never tried slamming a revolving door!
-
I'm assuming that version.exe is not the name of the program that this code is in right? If it is, I didn't think you could rename the exe while it was running.. If not, not sure why it's not working, strange.. Is your file name/path defined in the timer like the code above or are you actually putting the file name/path in a member variable? Rob Whoever said nothing's impossible never tried slamming a revolving door!
It is. Yes you can rename it. It seems like Windows OS doesnt care much about filename as long as it already acquired the handle for exe. Done this a few times. And you are right if it is not the file that is running, it works fine. I just hard code the exe filename because my project is called version.dsp. Just for a test program. I guess this rename - copy - check version idea doesnt work. :(( Thanks!