How to Overwrite a file in c:\windows..... backup permissions restore permissions

Hi Everyone,

i am trying to create a function where i can specify a source file and a target file.
I want to store the permissions that the target file has and backup the target file.
Copy the source file to the target files location and name.
Set permissions for the new file to match the old file (eg System, Trusted Installer etc....)

The file copying is pretty simple but i don't how to get permission for the file or set them on the new file.

Can anyone help with this?
Also being allowed to copy to a location like: C:\windows\winsxs\wow64_microsoft-windows-a..cing-infrastructure_31bf3856ad364e35_6.1.7600.16385_none_0bfcc31f07a61f6d\

'Create backup
System.IO.File.Move(strTargetFile, strTargetFile & ".bak")

'Copy file
System.IO.File.Copy(strSourceFile, strTargetFile)
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michael FowlerSolutions ConsultantCommented:
Faheem ShaikhCommented:
Microsoft has a very extensive File copy command line tool called Robocopy. I have used it in one of my projects for keeping to directories in sync. It exposes a lot of details on what you want to copy including permissions, backup, logging, audit, etc. There is a C sharp implementation for Robocopy called Robosharp which will help if you want to use this tool.
Please read more on Robocopy and Robosharp using the below links.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bguentherAuthor Commented:
Thanks for your help. i will see what i can make of it
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Storage Software

From novice to tech pro — start learning today.