Jump to content

FileCopy fails


Recommended Posts

Hi, I'm having a problem with my script. It intends to replace "aero.msstyles" in my fresh install of Windows 7. First I give it permissions to do so - it works, I have permissions. Then I close explorer.exe to make sure file is not in use. And then FileCopy fails...

And the strangest thing that if I run the same FileCopy command as a standalone script, it works (provided permissions are already given and explorer isn't using the file). I can't understand why would it work as a separate script, but would always fail in my script.  :mad2:

#notrayicon
#RequireAdmin
#include <Permissions.au3>
_GrantAllAccess(@WindowsDir & '\Resources\Themes\Aero\aero.msstyles')
ProcessClose('explorer.exe')
ProcessWaitClose('explorer.exe')
FileCopy(@ScriptDir & '\aero.msstyles', @WindowsDir & '\Resources\Themes\Aero\aero.msstyles', 1)
ShellExecute('explorer.exe')

P.S. I have also tried launching explorer.exe and copying file after that, but still nothing. Besides, as far as I'm aware file copying should not depend on Windows Explorer.

And yes, copy fails even when original file doesn't exist in the directory (i.e. script does not fail trying to replace).

 

UPDATE:

Deleted all explorer.exe-related lines, and now it works. But it's no good for me because I do need to restart explorer to prevent "file in use".

Does... uhm... does restarting Windows Explorer intervene with the script somehow?

 

UPDATE 2:

Also it looks like the script hangs for some unknown reason. That's even more weird because I don't see what could potentially hang it.

Edited by supraspecies
Link to comment
Share on other sites

Got it! Solved my problem. The issue is that explorer.exe does not stay closed - it auto-restarts right after you terminate it. So the script was likely hanging on ProcessWaitClose. Edited the script to:

#notrayicon
#RequireAdmin
#include <Permissions.au3>
_GrantAllAccess(@WindowsDir & '\Resources\Themes\Aero')
ProcessClose('explorer.exe')
FileCopy(@ScriptDir & '\aero.msstyles', @WindowsDir & '\Resources\Themes\Aero\aero.msstyles', 1)

And now it works.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...