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:windowswinsxswow64_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)



Have you looked at the FileIOPermission Class
https://msdn.microsoft.com/en-us/library/system.security.permissions.fileiopermission(v=vs.110).aspx



Have you looked at the FileIOPermission Class
https://msdn.microsoft.com/en-us/library/system.security.permissions.fileiopermission(v=vs.110).aspx



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.

https://technet.microsoft.com/en-us/library/cc733145.aspx

http://robosharp.codeplex.com/



Thanks for your help. i will see what i can make of it





Share this

Related Posts

There was an error in this gadget