change the version info of the file

im trying to make a tool that can change the version of the file (.exe)

UpdateResource(hResource, RT_VERSION, MAKEINTRESOURCE(1), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPVOID) lpBytes, dwSize);

i know how to update the rcdata of the resource

my problem is i dont know what to insert to it using (LPVOID) lpBytes
is it a .txt ? .rc ? is it a binary ? etc...

thanks in advance
lpBytes here is binary data. It is actually the resource content we are passing to the function UpdateResource.

Unfortunately, UpdateResource takes the resource data as parameter, not the attributes like "FileVersion". So we need to send "Version" data content.

There are two ways you can achieve this.
1) Get the fileversion using GetFileVersionInfo from the .exe, update it, make a resource of that content and then update the same to .exe using UpdateResource. This is could be errorneous as we are trying to modify the memory.

2) Second way is, you can get the "Version" resource data from another .exe file and use the same to pass it to the .exe you want to update. By this, you will have the "Version" details of an exe say app1.exe copied to another exe, say app2.exe. This can be done as in the code below,

HGLOBAL hResLoad;
HMODULE hExe;
HRSRC hRes;
HANDLE hUpdateRes;
LPVOID lpResLock;
BOOL result;

hExe = LoadLibrary(TEXT("app1.exe"));
if (hExe == NULL)
{
std::wcout << TEXT("Could not load exe.");
return 0;
}


hRes = FindResource(hExe, MAKEINTRESOURCE(1), RT_VERSION);
if (hRes == NULL)
{
std::wcout << TEXT("Could not locate dialog box.");
return 0;
}


hResLoad = LoadResource(hExe, hRes);
if (hResLoad == NULL)
{
std::wcout << TEXT("Could not load dialog box.");
return 0;
}


lpResLock = LockResource(hResLoad);
if (lpResLock == NULL)
{
std::wcout << TEXT("Could not lock dialog box.");
return 0;
}


hUpdateRes = BeginUpdateResource(TEXT("app2.exe"), FALSE);
if (hUpdateRes == NULL)
{
std::wcout << TEXT("Could not open file for writing.");
return 0;
}


result = UpdateResource(hUpdateRes,
RT_VERSION,
MAKEINTRESOURCE(1),
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
lpResLock,
SizeofResource(hExe, hRes));

if (result == FALSE)
{
std::wcout << TEXT("Could not add resource.");
return 0;
}


if (!EndUpdateResource(hUpdateRes, FALSE))
{
std::wcout <<TEXT("Could not write changes to file.");
return 0;
}


if (!FreeLibrary(hExe))
{
std::wcout << TEXT("Could not free executable.");
return 0;
}

Hope this helps!!!
Topic archived. No new replies allowed.