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. RegDeleteValue with REG_MULTI_SX/MoveFileEx?

RegDeleteValue with REG_MULTI_SX/MoveFileEx?

Scheduled Pinned Locked Moved C / C++ / MFC
windows-adminhelptutorialquestion
3 Posts 1 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'm using MoveFileEx with MOVEFILE_DELAY_UNTIL_REBOOT to delete some temporary files if the user reboots the PC whilst using my program (XP/2000/NT - I'm using WinInit.INI for other systems). However, if the program closes normally, I need to cancel the MOVEFILE_DELAY_UNTIL_REBOOT for all the temporary files that it has been set for. According to MSDN, MoveFileEx "stores the locations of the files to be renamed at restart in the following registry value: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations This registry value is of type REG_MULTI_SZ. Each rename operation stores the following pair of NULL-terminated strings: szDstFile\0\0 szSrcFile\0szDstFile\0\0" I checked the registry using regedit, and found all the values there as specified, and discovered that, say if the file to be deleted is "c:\\test\test.exe", then it would be listed in the registry as: \??\c:\\test\test.exe Thus, to cancel all of registry entries, I tried this: [code] HKEY hKey; char szRegKey[MAX_PATH]; RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\PendingFileRenameOperations", 0,KEY_ALL_ACCESS,&hKey); //this part should be looped for each file to be deleted: strcpy(szRegKey,"\\??\\"); strcat(szRegKey,szFileToDelete); RegDeleteValue(hKey,szRegKey); RegCloseKey(hKey); [/code] However, this didn't work - all the entries in the registry were left just as they were. Could anybody tell me where I am going wrong, and how to correct this so that I can delete all of the registry values that were added by MoveFileEx? Any help much appreciated, Many thanks, KB

    K 1 Reply Last reply
    0
    • K Kayembi

      Hi, I'm using MoveFileEx with MOVEFILE_DELAY_UNTIL_REBOOT to delete some temporary files if the user reboots the PC whilst using my program (XP/2000/NT - I'm using WinInit.INI for other systems). However, if the program closes normally, I need to cancel the MOVEFILE_DELAY_UNTIL_REBOOT for all the temporary files that it has been set for. According to MSDN, MoveFileEx "stores the locations of the files to be renamed at restart in the following registry value: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations This registry value is of type REG_MULTI_SZ. Each rename operation stores the following pair of NULL-terminated strings: szDstFile\0\0 szSrcFile\0szDstFile\0\0" I checked the registry using regedit, and found all the values there as specified, and discovered that, say if the file to be deleted is "c:\\test\test.exe", then it would be listed in the registry as: \??\c:\\test\test.exe Thus, to cancel all of registry entries, I tried this: [code] HKEY hKey; char szRegKey[MAX_PATH]; RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\PendingFileRenameOperations", 0,KEY_ALL_ACCESS,&hKey); //this part should be looped for each file to be deleted: strcpy(szRegKey,"\\??\\"); strcat(szRegKey,szFileToDelete); RegDeleteValue(hKey,szRegKey); RegCloseKey(hKey); [/code] However, this didn't work - all the entries in the registry were left just as they were. Could anybody tell me where I am going wrong, and how to correct this so that I can delete all of the registry values that were added by MoveFileEx? Any help much appreciated, Many thanks, KB

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

      Can anybody help? :) I discovered that my problem was that the strings I was trying to delete individually weren't the registry values, but "PendingFileRenameOperations" was the value - which I was treating as a key. Thus, I can use this code successfully to remove "PendingFileRenameOperations", the value created by MoveFileEx: [code] HKEY hKey; char szRegKey[MAX_PATH]; RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Session Manager", 0,KEY_ALL_ACCESS,&hKey); RegDeleteValue(hKey,"PendingFileRenameOperations"); RegCloseKey(hKey); [/code] The problem with this, of course, is that if any other programs have used MoveFileEx with MOVEFILE_DELAY_UNTIL_REBOOT, then my program will delete all this info too, which is undesirable. Does anyone know how I can delete *only* the strings that my program has added to the PendingFileRenameOperations value? Or, is there a function that will allow me to back up the original "PendingFileRenameOperations" value when my program starts (eg. by copying it with a different name), then add the values I need, then if my program ends normally I can replace the updated "PendingFileRenameOperations" with the backup (so that in effect the values I have added are deleted)? Many thanks for any help, KB

      K 1 Reply Last reply
      0
      • K Kayembi

        Can anybody help? :) I discovered that my problem was that the strings I was trying to delete individually weren't the registry values, but "PendingFileRenameOperations" was the value - which I was treating as a key. Thus, I can use this code successfully to remove "PendingFileRenameOperations", the value created by MoveFileEx: [code] HKEY hKey; char szRegKey[MAX_PATH]; RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Session Manager", 0,KEY_ALL_ACCESS,&hKey); RegDeleteValue(hKey,"PendingFileRenameOperations"); RegCloseKey(hKey); [/code] The problem with this, of course, is that if any other programs have used MoveFileEx with MOVEFILE_DELAY_UNTIL_REBOOT, then my program will delete all this info too, which is undesirable. Does anyone know how I can delete *only* the strings that my program has added to the PendingFileRenameOperations value? Or, is there a function that will allow me to back up the original "PendingFileRenameOperations" value when my program starts (eg. by copying it with a different name), then add the values I need, then if my program ends normally I can replace the updated "PendingFileRenameOperations" with the backup (so that in effect the values I have added are deleted)? Many thanks for any help, KB

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

        Ah, figured it out. I just use RegQueryValueEx to get the value of PendingFileRenameOperations when the program starts. If it returns ERROR_SUCCESS, I just replace the changed value with the saved value when the program ends using RegSetValueEx, otherwise I delete PendingFileRenameOperations using RegDeleteValue(). Thanks anyway, KB

        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