Rename and move a file

Ok. So I have tried every example I have found on this site to copy a file to another directory with the extension of .bak. Not one of them worked. Some say Completed (no file ever in the directory), or failed. What the “H” am I doing incorrectly?

I have tried:
copy “C:\windows\system32\MpSigStub.exe” “C:\utility\MpSigStub.bak”

I have tried:
waithidden cmd.exe /C copy “c:\windows\system32\MpSigStub.exe” “c:\utility\MpSigStub.old”

and numerous others with no luck.

So, there are 2 potential considerations here:

  1. The copy command requires that the destination directory exist, and the destination file does not exist
  2. wow64 redirection

My guess is that you’re running into wow64 redirection…

Try something like the following:

// disable Windows' wow64 redirection on 64-bit OS
action uses wow64 redirection {not x64 of operating system}
// delete destination file in case it exists
delete "C:\utility\MPSigStub.bak"
// create destination folder if it does not exist
if {not exists folder "C:\utility"}
	folder create "C:\utility"
endif

// copy file
copy "C:\windows\system32\MpSigStub.exe" "C:\utility\MpSigStub.bak"

The file does not exist in the C:\utility directory and the directory already exists. Why wouldn’t the copy command work? copy “c:\windows\system32\MpSigStub.exe” “c:\utility\MpSigStub.bak”

Newbie here :slight_smile:

1 Like

Another consideration would be file system permissions. Are there restrictions on either the file or the destination folder that would prevent the LOCALSYSTEM user from accessing these items?

1 Like

Oh BTW your example did work

Given that the BigFix Client is currently a 32-bit process, Windows redirects certain system paths to other locations. In this case, C:\windows\system32\ is redirected to C:\windows\syswow64\. This means that windows is redirected/translating your copy statement to something like the following:

copy "c:\windows\syswow64\MpSigStub.exe" "c:\utility\MpSigStub.bak"

And likely, in this case, the source file does not exist in that particular path, leading to a failure.

By including action uses wow64 redirection {not x64 of operating system} at the beginning of our actionscript, we’re instructing the BigFix Client to avoid Windows’ wow64 redirection.

1 Like