delete file in program files

Discussion in 'Application Software' started by Stannieman, Dec 2, 2009.

  1. Stannieman

    Stannieman MDL Guru

    Sep 4, 2009
    2,232
    1,805
    90
    Hello,
    I've made a little program in visual basic which automatically copies patched files of solidworks 2010 to the right directory.

    When I copy the files I use:
    "my.computer.filesystem.renamefile" to rename the .dll to .dll.bak
    "my.computer.filesystem.copyfile" to copy the patched .dll
    "systel.io.file.create" to create an empty file whit no extension, this is to tell the program that the patch is already installed and so the uninstaller know's the .dll.bak file really exists.

    For uninstalling I use:
    "my.computer.filesystem.deletefile" to delete the .dll
    "my.computer.filesystem.renamefile" to reneme the .dll.bak to .dll

    The problem is that when it's removing the .dll a just in time debugger window pop's up which says the acces to the dll is denied.
    However, I am able to remove the .dll.bak propperly whit the same command.
    Renaming the .dll to .dll.del, then rename the .dll.bak to .dll and then removing the .dll.del also gives an error.


    Does anyone know how this comes? It happens with windows 7 and xp and I always run it as admin.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. genuine555

    genuine555 MDL Expert

    Oct 3, 2009
    1,639
    56
    60
    #2 genuine555, Dec 2, 2009
    Last edited by a moderator: Apr 20, 2017
    you need to take ownership of the files before you can rename/delete them.

    Don't know the syntax in VB, but here it is in plain :
    Code:
    
    takeown.exe /f %WINDIR%\explorer.exe
    icacls.exe %WINDIR%\explorer.exe /grant administrator:f
    
    I'm sure you will be able to convert it.


    gen555

    EDIT : ask PAYMYRENT. He will know this in VB language...
     
  3. Stannieman

    Stannieman MDL Guru

    Sep 4, 2009
    2,232
    1,805
    90
    Thank's, I already thought it would be something like that. But do you know why I am still able to rename the files without taking ownership?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. genuine555

    genuine555 MDL Expert

    Oct 3, 2009
    1,639
    56
    60
    You can rename them ?

    Wow, then the take ownership is allready done normally.
    Could it be because the files are in use ?

    I know when I mod a file, like explorer.exe, and I want to replace it with the modded file, I can rename the original to .exe.bak, but can't delete it cause it is in use.
    After reboot, the explorer.exe.bak could be deleted.

    And why would you want to delete original files ?
    Isn't it better to keep them there as backups ?

    gen555
     
  5. tum0r

    tum0r MDL Novice

    Aug 26, 2009
    34
    6
    0
    if that .dll is being used by a service, try:

    net stop "service name" , then delete it
     
  6. genuine555

    genuine555 MDL Expert

    Oct 3, 2009
    1,639
    56
    60
    that could render the system instable. Caution is needed when doing this.
    Make sure the service is not neccesary, and that no other services depend on it.
     
  7. Stannieman

    Stannieman MDL Guru

    Sep 4, 2009
    2,232
    1,805
    90
    #7 Stannieman, Dec 3, 2009
    Last edited: Dec 3, 2009
    (OP)
    I rename the original dll to bak and copy a replacement dll. Now I CAN delete the bak, so the file wasn't in use. I can also (without reboot) rename the replacement dll (so that's also not in use), and than rename the bak back to dll. But removing the replacement dll (renamed or not) is impossible.

    In my final app the bak files won't be removed, I was just testing if a renamed file can be removed.

    Conclusion:
    I can't remove the original dll, except when I rename it first.
    I can't remove the replacement dll (renamed or not renamed), but I can rename it.
    The replacement file can't be in use, because I haven't started any program after placing it in the program files folder.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. Stannieman

    Stannieman MDL Guru

    Sep 4, 2009
    2,232
    1,805
    90
    #8 Stannieman, Dec 3, 2009
    Last edited: Dec 3, 2009
    (OP)
    I can remove the files manually. There comes a windows which says I need admin preveleges, and after klicking proceed it romeves the files propperly.
    But I've set in visual studio that my app requires admin rights, and when I open it there comes a UAC popup asking for admin rights, so I guess it should have all the pregeleges to delete the files?

    Anyway, here's my code, maybe it's not the best method to do the job, but it's the first vb app. I'm writing which need acces to external files.

    To install the patch:

    To uninstall:

    The patching goes fine, all files are renamed, cracked ones are copied and empty files are created, and SW is activated.
    Uninstalling goes wrong.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. genuine555

    genuine555 MDL Expert

    Oct 3, 2009
    1,639
    56
    60
    Well, like I said, Stannieman, PAYMYRENT can help you big time with this. He's got some VB skillz.
    Don't know if he's got the time, but you could ask him ?

    Anyway, for your first app, it looks pretty neat.

    Genuine props :)
     
  10. Stannieman

    Stannieman MDL Guru

    Sep 4, 2009
    2,232
    1,805
    90
    Thank's :)
    And it's not really my first app, I've already made some simple things wich calculates the avarage of values it textboxes. The only difference it that this is can actually be useful.
    And I will first check wether the files are in use (but I think not) and if they aren't I will ask paymyrent

    thanks
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. Stannieman

    Stannieman MDL Guru

    Sep 4, 2009
    2,232
    1,805
    90
    For the take ownership stuff:
    The admin already had ownership (in dutch "volledig beheer", so in English I guess "full control").
    I now also took ownership for the non-admin account, but it still doesn't delete, so it's 100% sure due to something else.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  12. PAYMYRENT

    PAYMYRENT MDL Developer

    Jul 28, 2009
    1,462
    419
    60
    im so sorry i have not been able to help you with this. torrent speed is slow so i really have no way to test my changes... please dont get mad for i am working as fast as i can
     
  13. Stannieman

    Stannieman MDL Guru

    Sep 4, 2009
    2,232
    1,805
    90
    Ow, nevermind, but have you any idea what I may be doing wrong when you look at my code? Admin has ownership and the app runs as admin, so I don't see what the problem could be...
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...