Jump to content
Sign in to follow this  

Copy in use/locked files on reboot

Recommended Posts

This little udf will make windows copy used or locked files after the PC is rebooted.

Copy the new files to a temporary location and call the function with the new file full path and the file to replace full path. You can call this multiple times to add more files to the restart copy list in the registry.

_CopyAfterRestart("c:\temp\myfile.exe","C:\Documents and Settings\ChrisLambert\Desktop\myFile.exe")

; ----------------------------------------------------------------------------
; AutoIt Version: 3.2.*
; Author:        Chris Lambert
; Script Function:
;   Template AutoIt script.
; ----------------------------------------------------------------------------

;~ Function: _CopyAfterRestart()
;~ Desctiption tells windows to copy files on reboot
;~ Version: N/A
;~ Author: ChrisL
;~ Parameter(s): 
;~ $new_file = The full path to the new file to use after reboot
;~ $to_replace = The full path to the old file to overwrite
;~ Example:
;~ _CopyAfterRestart("c:\temp\internet.exe","C:\Documents and Settings\ChrisLambert\Desktop\internet.exe")
;~ _CopyAfterRestart("c:\temp\myfile.exe","C:\Documents and Settings\ChrisLambert\Desktop\myFile.exe")
;~ @error 1 $new_file does not exist
;~ @error 2 $to_replace does not exist

Func _CopyAfterRestart($new_file,$to_replace)
    If NOT FileExists($new_file) then 
        Return 0
    If NOT FileExists($to_replace) then 
        Return 0
    $existing_entries = Regread ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager","PendingFileRenameOperations") 
    If $existing_entries <> "" then $existing_entries = $existing_entries & @lf
    Regwrite ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager","PendingFileRenameOperations","REG_MULTI_SZ",$existing_entries  & "\??\" & $new_file & @lf & "!\??\" & $to_replace)

Share this post

Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...