栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

获取.exe的版本信息

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

获取.exe的版本信息

在花了几个小时上网并编码之后,我找到了使用JNA来获取文件的版本信息的解决方案。

import com.sun.jna.Library;import com.sun.jna.Memory;import com.sun.jna.Native;import com.sun.jna.Pointer;import com.sun.jna.ptr.IntByReference;import com.sun.jna.ptr.PointerByReference;import com.sun.jna.win32.W32APIOptions;import java.io.IOException;public class FileVersionInfo{    interface Version extends Library {        Version INSTANCE = (Version) Native.loadLibrary("Version", Version.class, W32APIOptions.UNICODE_OPTIONS);        public int GetFileVersionInfoSizeW(String lptstrFilename, int dwDummy);        public boolean GetFileVersionInfoW(String lptstrFilename, int dwHandle, int dwLen, Pointer lpData);        public int VerQueryValueW(Pointer pBlock, String lpSubBlock, PointerByReference lplpBuffer, IntByReference puLen);    }    static class VS_FIXEDFILEINFO extends com.sun.jna.Structure {        public int dwSignature;        public int dwStrucVersion;        public int dwFileVersionMS;        public int dwFileVersionLS;        public int dwProductVersionMS;        public int dwProductVersionLS;        public int dwFileFlagsMask;        public int dwFileFlags;        public int dwFileOS;        public int dwFileType;        public int dwFileSubtype;        public int dwFileDateMS;        public int dwFileDateLS;public VS_FIXEDFILEINFO(com.sun.jna.Pointer p){     super(p);}    }    public static void main(String[] args) throws IOException {        int dwDummy = 0;        int versionlength = Version.INSTANCE.GetFileVersionInfoSizeW(     "C:\Test\chromeinstall.exe", dwDummy);        byte[] bufferarray = new byte[versionlength];        Pointer lpData = new Memory(bufferarray.length);        PointerByReference lplpBuffer = new PointerByReference();        IntByReference puLen = new IntByReference();        boolean FileInfoResult = Version.INSTANCE.GetFileVersionInfoW(     "C:\Test\chromeinstall.exe",     0, versionlength, lpData);        System.out.println(FileInfoResult);        int verQueryVal = Version.INSTANCE.VerQueryValueW(lpData,     "\", lplpBuffer,     puLen);        VS_FIXEDFILEINFO lplpBufStructure = new VS_FIXEDFILEINFO(     lplpBuffer.getValue());        lplpBufStructure.read();        short[] rtnData = new short[4];        rtnData[0] = (short) (lplpBufStructure.dwFileVersionMS >> 16);        rtnData[1] = (short) (lplpBufStructure.dwFileVersionMS & 0xffff);        rtnData[2] = (short) (lplpBufStructure.dwFileVersionLS >> 16);        rtnData[3] = (short) (lplpBufStructure.dwFileVersionLS & 0xffff);        for (int i = 0; i < rtnData.length; i++) { System.out.println(rtnData[i]);        }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/451302.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号