zoukankan      html  css  js  c++  java
  • vc++读取文件属性的详细信息描述 读取QQ的注册表路径

    //////////////////////////////////////////////////////////////
    //
    // File: getfileversion.cpp
    // Description: 获取EXE文件的属性详细信息
    // Created: 2012-10-18
    // Author: lhsbqb
    //
    //////////////////////////////////////////////////////////////
    
    /*
    The following code shows how to get FILEINFO value from resource file.
    
    These WIN32 functions will be used:
    
    * GetFileVersionInfo
    * GetFileVersionInfoSize
    * VerQueryValue
    * GetModuleFileName
    */
    
    #include "stdafx.h"
    #include <windows.h>
    #include <tchar.h>
    #include <string>
    #include <iostream>
    #include "stdio.h"
    
    
    #pragma comment(lib, "version.lib")
    using namespace std;
    
    std::string GetFileVersion(char * strFilePath) 
    {
        DWORD dwSize; 
        DWORD dwRtn; 
        std::string szVersion;  
        //获取版本信息大小
        dwSize = GetFileVersionInfoSize(strFilePath,NULL); 
        if (dwSize == 0) 
        { 
           return ""; 
        }
        char *pBuf; 
        pBuf= new char[dwSize + 1]; 
        if(pBuf == NULL)
           return "";
        memset(pBuf, 0, dwSize + 1);
        //获取版本信息
        dwRtn = GetFileVersionInfo(strFilePath,NULL, dwSize, pBuf); 
        if(dwRtn == 0) 
        { 
           return ""; 
        }
        LPVOID lpBuffer = NULL;
        UINT uLen = 0;
        //版本资源中获取信息
        
    dwRtn = VerQueryValue(pBuf, 
       TEXT("\\StringFileInfo\\080404b0\\FileDescription"), //0804中文
       //04b0即1252,ANSI
       //可以从ResourceView中的Version中BlockHeader中看到
       //可以测试的属性
       /*
       CompanyName 
       FileDescription 
       FileVersion 
       InternalName 
       LegalCopyright
       OriginalFilename
       ProductName 
       ProductVersion 
       Comments
       LegalTrademarks 
       PrivateBuild 
       SpecialBuild 
       */         
       &lpBuffer, 
       &uLen); 
    if(dwRtn == 0) 
    { 
       return ""; 
    }
    szVersion = (char*)lpBuffer;
    delete pBuf; 
    return szVersion; 
    }
    
    
    void main()
    {
    #define MY_BUFSIZE 500
        HKEY hKey;
        TCHAR szProductType[MY_BUFSIZE];
        DWORD dwBufLen = MY_BUFSIZE;
        LONG lRet;
    
        if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
            TEXT("SOFTWARE\\Tencent\\PlatForm_Type_List\\3"),
            0,
            KEY_QUERY_VALUE,
            &hKey) == ERROR_SUCCESS)
        {
            lRet = RegQueryValueEx(hKey,
                TEXT("TypePath"),
                NULL,
                NULL,
                (LPBYTE)szProductType,
                &dwBufLen);
    
            //return szProductType;
        
        }
    
        RegCloseKey(hKey);
    
        //char * strFilePath  = "C:\\Program Files\\Tencent\\QQ\\Bin\\QQ.exe";
        char * strFilePath = szProductType;
        cout << strFilePath << " FileDescription is: " << GetFileVersion(strFilePath) << endl;
        getchar();
    }

    参考了msdn如下代码:

    #define RTN_UNKNOWN 0
    #define RTN_SERVER 1
    #define RTN_WORKSTATION 2
    #define RTN_NTAS 3
    #define RTN_ERROR 13
    
    DWORD GetWindowsVariant(void)
    {
        #define MY_BUFSIZE 32    // Arbitrary initial value. 
                                 // Dynamic allocation will be used.
        HKEY hKey;
        TCHAR szProductType[MY_BUFSIZE];
        DWORD dwBufLen = MY_BUFSIZE;
        LONG lRet;
    
        if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
            TEXT("SYSTEM\\CurrentControlSet\\Control\\ProductOptions"),
                        0,
                        KEY_QUERY_VALUE,
                        &hKey) != ERROR_SUCCESS) return RTN_ERROR;
    
        lRet = RegQueryValueEx(hKey,
                        TEXT("ProductType"),
                        NULL,
                        NULL,
                        (LPBYTE)szProductType,
                        &dwBufLen);
    
        RegCloseKey(hKey);
    
        if(lRet != ERROR_SUCCESS) return RTN_ERROR;
    
        // check product options, in order of likelihood
        if(lstrcmpi(TEXT("WINNT"), szProductType) == 0) 
             return RTN_WORKSTATION;
        if(lstrcmpi(TEXT("SERVERNT"), szProductType) == 0) 
             return RTN_SERVER;
        if(lstrcmpi(TEXT("LANMANNT"), szProductType) == 0) 
             return RTN_NTAS;
        // else return "unknown variant" code
        else return RTN_UNKNOWN;
    } 

    http://www.pythonschool.com/python/14.html 转摘

  • 相关阅读:
    kvm虚拟机网络管理
    kvm虚拟机存储管理
    kvm虚拟机迁移
    KVM嵌套虚拟化nested之CPU透传
    kvm认识和安装
    博客美化(二)
    日志管理
    IP分为五类
    windows(xshell)免密码登录
    mpvue的toast弹窗组件-mptosat
  • 原文地址:https://www.cnblogs.com/pythonschool/p/2729872.html
Copyright © 2011-2022 走看看