Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MoveFileEx not always working?

MoveFileEx not always working?

Scheduled Pinned Locked Moved C / C++ / MFC
databasecomwindows-adminjsonhelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kayembi
    wrote on last edited by
    #1

    Hi, I have an app that uses MoveFileEx with MOVEFILE_DELAY_UNTIL_REBOOT. The app basically extracts some temporary files from a .zip file to a cache directory. After each file is extracted, a delete on reboot key is added to the registry if the system is WinNT/2000/XP, otherwise WinInit.ini is used. If the program ends normally, the registry keys are deleted (or WinInit.ini is restored to its former state). The idea is simply that the cached files are cleaned up no matter how the program ends. However, there seems to be some bug whereby the files aren't always deleted on boot up. Strangely, sometimes they are, sometimes they aren't. I can't find any logic behind it, despite having tested it over and over again. In every case my code seems to be working fine, as I check the registry before rebooting and the PendingFileRenameOperations key contains all of the info that should be there (all the paths to the files I want to delete with \\?\ before them or whatever). When I reboot, the PendingFileRenameOperations key is gone - as though it has been executed - but the files are not always deleted. Very strange. This is the basics of the code I am using to do this: /* Extract all files in a .zip archive and set them up so that they should be deleted on reboot if the PC is reset while the program is running: */ //fileno = number of files contained in a .zip file: for (int currfile = 0; currfile < fileno; currfile++) { /* Zip extraction is handled by the library available from www.artpol-software.com */ //Extract the file: zip.ExtractFile(currfile,OutputPath_str); //extract file from .zip by index to cache dir //Set it up so that the file will be deleted if the PC is rebooted: /* EDITED: here I have some code that gets the file name and file path from the current zip index number, and stores the full path in a string, szCurrFile... (I know this is working, because it displays the correct info in the registry) */ //For each file, remove it if PC is rebooted: if(MoveFileEx(szCurrFile,NULL,MOVEFILE_DELAY_UNTIL_REBOOT)==0) { //Fall back to WinInit.ini... //here I have my fallback code using WritePrivateProfileSection() } SetFileAttributes(szCurrFile,FILE_ATTRIBUTE_HIDDEN); //Ensure window is updated if anything happens in the meantime: if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { if(msg.message == WM_QUIT) { //If user destroys this program, skip to the end to clean up: GRS_quit = 1; //flag to tell rest of program to skip certain loops

    D 1 Reply Last reply
    0
    • K Kayembi

      Hi, I have an app that uses MoveFileEx with MOVEFILE_DELAY_UNTIL_REBOOT. The app basically extracts some temporary files from a .zip file to a cache directory. After each file is extracted, a delete on reboot key is added to the registry if the system is WinNT/2000/XP, otherwise WinInit.ini is used. If the program ends normally, the registry keys are deleted (or WinInit.ini is restored to its former state). The idea is simply that the cached files are cleaned up no matter how the program ends. However, there seems to be some bug whereby the files aren't always deleted on boot up. Strangely, sometimes they are, sometimes they aren't. I can't find any logic behind it, despite having tested it over and over again. In every case my code seems to be working fine, as I check the registry before rebooting and the PendingFileRenameOperations key contains all of the info that should be there (all the paths to the files I want to delete with \\?\ before them or whatever). When I reboot, the PendingFileRenameOperations key is gone - as though it has been executed - but the files are not always deleted. Very strange. This is the basics of the code I am using to do this: /* Extract all files in a .zip archive and set them up so that they should be deleted on reboot if the PC is reset while the program is running: */ //fileno = number of files contained in a .zip file: for (int currfile = 0; currfile < fileno; currfile++) { /* Zip extraction is handled by the library available from www.artpol-software.com */ //Extract the file: zip.ExtractFile(currfile,OutputPath_str); //extract file from .zip by index to cache dir //Set it up so that the file will be deleted if the PC is rebooted: /* EDITED: here I have some code that gets the file name and file path from the current zip index number, and stores the full path in a string, szCurrFile... (I know this is working, because it displays the correct info in the registry) */ //For each file, remove it if PC is rebooted: if(MoveFileEx(szCurrFile,NULL,MOVEFILE_DELAY_UNTIL_REBOOT)==0) { //Fall back to WinInit.ini... //here I have my fallback code using WritePrivateProfileSection() } SetFileAttributes(szCurrFile,FILE_ATTRIBUTE_HIDDEN); //Ensure window is updated if anything happens in the meantime: if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { if(msg.message == WM_QUIT) { //If user destroys this program, skip to the end to clean up: GRS_quit = 1; //flag to tell rest of program to skip certain loops

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Does MoveFileEx() or SetFileAttributes() (is this required) ever fail? If so, what is the error from GetLastError()?


      Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

      K 1 Reply Last reply
      0
      • D David Crow

        Does MoveFileEx() or SetFileAttributes() (is this required) ever fail? If so, what is the error from GetLastError()?


        Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

        K Offline
        K Offline
        Kayembi
        wrote on last edited by
        #3

        Hi, thanks for the reply. This is the weird (and really annoying) thing - neither fail. I have checked their return values, and all is okay. And I have even checked the registry itself, and found that all the values are perfectly correct inside PendingFileRenameOperations, and everything seems fine. And yet still, sometimes when I reset the computer, nothing is deleted. At first I thought that it must somehow be falling through to the code at the end of my program which removes the entries from the registry if the files have been deleted normally after the program has closed, but I tried commenting this code out and it made no difference. This is really strange. Does anyone know of any reason why PendingFileRenameOperations in the registry might be ignored or just deleted at boot up without actually running? Many thanks, KB

        D 1 Reply Last reply
        0
        • K Kayembi

          Hi, thanks for the reply. This is the weird (and really annoying) thing - neither fail. I have checked their return values, and all is okay. And I have even checked the registry itself, and found that all the values are perfectly correct inside PendingFileRenameOperations, and everything seems fine. And yet still, sometimes when I reset the computer, nothing is deleted. At first I thought that it must somehow be falling through to the code at the end of my program which removes the entries from the registry if the files have been deleted normally after the program has closed, but I tried commenting this code out and it made no difference. This is really strange. Does anyone know of any reason why PendingFileRenameOperations in the registry might be ignored or just deleted at boot up without actually running? Many thanks, KB

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Could it be a permissions issue? Are the files on an NTFS volume?


          Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups