dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: NT
Expertise: Beginner
Apr 20, 1998

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


File version information under NT

Question:
I am using the GetFileVersionInfoSize, GetFileVersionInfo, and VerQueryValue APIs to get the file version of third-party applications. In all cases, GetFileVersionInfoSize returns a large number, but when I query it for \StringFileInfo\040904B0\ProductVersion, sometimes I get nothing. My Visual Basic application and my C++ DLL both return values, but Excel and Visio return nothing. Any thoughts?

Answer:
Not a direct answer, but if you are doing this from multiple envioronments, wouldn't it be easier to create an ActiveX exe which returns this information, and then use it from all your programs? Write it in either Visual Basic or C++; both do a good job with this kind of stuff. Then you don't have to worry about what different things you need to do in Excel, Visio, or whatever. Little utility packages like this can be incredibly useful and have a quick payback.


BSTR FAR PASCAL utl_GetFileVersion(LPTSTR
pFileName, LPTSTR pInfoToGet)
{

DWORD   dwVerInfoSize;		// Size of version information block
LPSTR   lpVersion;			// String pointer to 'version' text
DWORD   dwVerHnd=0;			// An 'ignored' parameter, always '0'
UINT    uVersionLen;		// Length of string version information
BOOL    bRetCode;
BSTR    bstrVersionInfo;	// Version Info to pass back

		// get the size of the version information block
	dwVerInfoSize = GetFileVersionInfoSize(pFileName, &dwVerHnd);
	if (dwVerInfoSize)

	{
		LPSTR   lpstrVffInfo;	// pointer to version information block
		HANDLE  hMem;		// pointer to allocated memory
		HANDLE  hMem2;		// ditto
		LPSTR	lpstrVerText;	// text string of info to get


			//allocate memory for the version information block
		hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);
		//load the version information block
		lpstrVffInfo  = (char *)GlobalLock(hMem); 
		GetFileVersionInfo(pFileName, dwVerHnd, 
			dwVerInfoSize, lpstrVffInfo);

		hMem2 = GlobalAlloc(GMEM_MOVEABLE, 25 + strlen(pInfoToGet));
	lpstrVerText  = (char *)GlobalLock(hMem2);

		sprintf(lpstrVerText,"\\StringFileInfo\\040904B0\\%s",pInfoToGet);

		// Query the version information block for Product Version
		bRetCode = VerQueryValue((LPVOID)lpstrVffInfo,
			TEXT(lpstrVerText),
			(LPVOID *)&lpVersion,
			&uVersionLen);

		if(bRetCode)
		{
				// copy version info into a string VB understands
			bstrVersionInfo = SysAllocStringLen(NULL, strlen(lpVersion)+1);
			memset(bstrVersionInfo, 0, strlen(lpVersion)+1);
			memcpy(bstrVersionInfo, lpVersion, strlen(lpVersion));
			return (bstrVersionInfo);
		}
		else
		{

			return (0);
		}
	}
	else

		return (0);
  }
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date