Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. VS_VERSION_INFO question

VS_VERSION_INFO question

Scheduled Pinned Locked Moved C / C++ / MFC
questionsysadminhelpannouncement
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    crewchill
    wrote on last edited by
    #1

    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!

    D R 2 Replies Last reply
    0
    • C crewchill

      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!

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      So is your question about GetVersionInfo() returning the correct value, or how to copy over a potentially in-use file?

      C 1 Reply Last reply
      0
      • D David Crow

        So is your question about GetVersionInfo() returning the correct value, or how to copy over a potentially in-use file?

        C Offline
        C Offline
        crewchill
        wrote on last edited by
        #3

        My question is how to use GetVersionInfo() to return the correct value. Thanks

        D 1 Reply Last reply
        0
        • C crewchill

          My question is how to use GetVersionInfo() to return the correct value. Thanks

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          This article should help: http://www.microsoft.com/msj/0498/c0498.aspx

          1 Reply Last reply
          0
          • C crewchill

            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!

            R Offline
            R Offline
            RobJones
            wrote on last edited by
            #5

            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!

            C 1 Reply Last reply
            0
            • R RobJones

              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!

              C Offline
              C Offline
              crewchill
              wrote on last edited by
              #6

              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:

              R 1 Reply Last reply
              0
              • C crewchill

                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:

                R Offline
                R Offline
                RobJones
                wrote on last edited by
                #7

                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!

                C 1 Reply Last reply
                0
                • R RobJones

                  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!

                  C Offline
                  C Offline
                  crewchill
                  wrote on last edited by
                  #8

                  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!

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups