如果你真的需要做这个预先构建,那么你几乎是运气不好,因为相关的选项被禁止在限量版中,恐怕。
但是,一旦安装完成,您可以从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
将版本号放入可执行文件中。 –