I realized that we can just wait for the file to get unlocked, we don't need to create the new process and all that. So I deleted the implementation for that.
I also realized that the check to see if the file increases in size was wrong, it said that it increased in size because size2 was -1, because the sharing violation error, so I've waited for the file to be closed in that part and found that the file actually stay the same in size, so I wrote a buffer bigger than the file into the key, forcing it to allocate more bytes to the file.