code_junkie

Random MoveFileEx failures on Vista (access denied, looks like caused by search indexer)

Nov 11th, 2011
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <windows.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4.  
  5. bool test() {
  6. unsigned char buf[] = {
  7. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99,
  8. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99
  9. };
  10. HANDLE h;
  11. DWORD nbytes;
  12. LPCTSTR fn_tmp = "aaa";
  13. LPCTSTR fn = "bbb";
  14. h = CreateFile(fn_tmp, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_ALWAYS, 0, 0);
  15. if (h == INVALID_HANDLE_VALUE) return 0;
  16. if (!WriteFile(h, buf, sizeof buf, &nbytes, 0)) goto error;
  17. if (!FlushFileBuffers(h)) goto error;
  18. if (!CloseHandle(h)) goto error;
  19. if (!MoveFileEx(fn_tmp, fn, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED | MOVEFILE_WRITE_THROUGH)) {
  20. printf("error=%dn", GetLastError());
  21. return 0;
  22. }
  23. return 1;
  24. error:
  25. CloseHandle(h);
  26. return 0;
  27. }
  28.  
  29. int main(int argc, char** argv) {
  30. unsigned int i;
  31. for (i = 0;; ++i) {
  32. printf("*%un", i);
  33. if (!test()) return 1;
  34. }
  35. return 0;
  36. }
Add Comment
Please, Sign In to add comment