如果你真的需要做這個預先構建,那麼你幾乎是運氣不好,因爲相關的選項被禁止在限量版中,恐怕。
但是,一旦安裝完成,您可以從Windows註冊表中提取版本和觸摸安裝程序已刪除的任何文件。以下是您可以用來完成第一部分的代碼:
static const std::string key = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"; // Arguably the best place from which to obtain msi version data
static const unsigned MAX_KEY_LENGTH = 255; // Maximum length of a registry key
static const std::string displayName = /*ToDo - your display name here*/
static const unsigned displayNameSize = /*ToDo - the size of the display name here + 1 for the null terminator*/
int g_version; // The version number as it appears in the registry
HKEY hKey = NULL;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, key.c_str(), 0, KEY_ENUMERATE_SUB_KEYS, &hKey) == ERROR_SUCCESS){
for (DWORD Index = 0; g_version == 0U; ++Index){
DWORD cName = 256;
char SubKeyName[MAX_KEY_LENGTH + 1/*Maximum length of a registry key is 255, add 1 for termination*/];
if (RegEnumKeyEx(hKey, Index, SubKeyName, &cName, NULL, NULL, NULL, NULL) != ERROR_SUCCESS){
break;
}
HKEY hSubKey = NULL;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, (key + "\\" + SubKeyName).c_str(), 0, KEY_QUERY_VALUE, &hSubKey) == ERROR_SUCCESS){
// Is the DisplayName equal to displayName?
DWORD dwType = REG_SZ;
TBYTE buf[displayNameSize];
DWORD dwSize = displayNameSize;
HRESULT res;
if ((res = RegQueryValueEx(hSubKey, TEXT("DisplayName"), NULL, &dwType, (PBYTE)&buf, &dwSize)) == ERROR_SUCCESS){
if (!::strncmp(displayName.c_str(), (PTCHAR)buf, displayNameSize)){
// get the version
dwType = REG_DWORD;
dwSize = displayNameSize;
if (RegQueryValueEx(hSubKey, TEXT("Version"), NULL, &dwType, (PBYTE)&buf, &dwSize) == ERROR_SUCCESS && dwType == REG_DWORD){
g_version = (buf[3] << 24) + (buf[2] << 16) + (buf[1] << 8) + buf[0];
}
}
}
RegCloseKey(hSubKey);
}
}
RegCloseKey(hKey);
}
您已經提到過,您將在可執行文件中對其進行編碼。這可以作爲構建後步驟運行,限制版支持這一點。然後,您只需將版本號嵌入到您的一個安裝文件中;您的可執行文件將能夠執行的操作。
你究竟在做什麼? – Bathsheba
將版本號放入可執行文件中。 –