3

The following code throws a 110 Error on the EndUpdateResource call only when windows explorer is open at D:\test\output\ where the executable is being copied to:

std::ifstream in("C:\\Windows\\notepad.exe", std::ios::binary);
std::ofstream out("D:\\test\\output\\notepad.exe", std::ios::binary);
out << in.rdbuf();
in.close();
out.close();

Handle hUpdateRes = BeginUpdateResource(_T("D:\\test\\output\\notepad.exe"), FALSE);
EndUpdateResource(hUpdateRes, FALSE);

As long as I don't have that folder open in windows explorer it works fine. If I have it open it will throw an error. Also, if I do a CreateFile with read and write access before the BeginUpdateResource call it will work fine even if I have the output folder open. I am really confused and would appreciate any help. Thanks!

Perez
  • 113
  • 2
  • 8
  • Disable your anti-malware product and try again. – Hans Passant Sep 22 '15 at 22:39
  • I am not able to edit the security settings on the target machine but I tried the code on a machine without a virus scanner and the code seems to work fine, so it may very well be the problem. Why does the createFile call work though? Shouldn't it fail as well if the virus scanner has the exe locked? And why does the UpdateResource calls work If I add that in there? Is it just a timing thing? – Perez Sep 22 '15 at 23:26
  • Well I got the IT dept to temporarily disable the scanner to test and you were right. It was the virus scanner. Now I just need to find a work around. Thanks. – Perez Sep 23 '15 at 20:34

2 Answers2

3

I disabled the on demand virus scanner on the machine and the code no longer throws an error.

Perez
  • 113
  • 2
  • 8
1

It's all about directory's permissions for the files you're writing. At least it was for me. I was writing files on desktop, which had Read only attribute and was getting this error randomly. I solved it by simply creating a folder on desktop and writing files to it. So, the solutions:
1) Don't write files to system's directories.
2) Create a directory yourself
3) Edit directory's attributes. Take off read-only. To do it programmatically:
How to Remove the Readonly attribute of a File MFC
removing readonly from folder, its sub folders and all the files in it

Or combine all of them.

Brackets
  • 464
  • 7
  • 12