Options

Anyone good with Visual Basic?

I'm just starting out with VB so forgive any newbie questions.

I have a simple program that copies a directory from a network drive to a directory on my local drive. Pretty simple, hardcoded file location.

The problem is that the permissions to the folder are not retained. Is there a simple way of retaining the permissions when the file is copied?

I'm sure I will have more questions as I keep working on learning this.

Comments

  • Options
    sprkymrksprkymrk Member Posts: 4,884 ■■■□□□□□□□
    I have found the best way is to call an external program like cacls.exe, xcacls or suninacle.exe from your vbscript. I never really got into vbscripting too much because the W2k, WXP and W2K3 shell commands and RK tools allow me to do everything the "old" way in batch/cmd scripting. Old dog - new tricks - you know...
    All things are possible, only believe.
  • Options
    JDMurrayJDMurray Admin Posts: 13,031 Admin
    By "Visual Basic" are you using VB6, VB.NET, or Visual Basic 2005?

    Assuming VB6, there are no intrinsic file copy procedures that preserve the file's attributes. It's common to add a reference to the FileSystemObject and use its Attributes property to read/set the file attributes before/after the file is copied. Even with VB in .NET I don't know of a method to perform a file copy which preserves the attributes. I think you'd still need to use File.GetAttributes(srcFileName) and File.SetAttributes(dstFileName).
  • Options
    Megadeth4168Megadeth4168 Member Posts: 2,157
    Visual Basic 2005

    I will try File.GetAttributes(srcFileName) and File.SetAttributes(dstFileName).
    Thanks for the suggestion :)
  • Options
    mwillmwill Member Posts: 51 ■■□□□□□□□□
    I've been there and done that. So I know what works perfect. I've tried to make an exact backup of a server using vbscript, had a script with 127 lines of code. Then I found a neato program in the Windows 2003 resource kit called Robocopy. It will do exactly what you need it to do in 5 lines or less in a batchfile.

    Check this out: http://www.ss64.com/nt/robocopy.html

    download it here: http://www.microsoft.com/downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en

    Last program you'll ever use for this stuff ;)

    PS: It does copy all ACL's with the /copyall switch read the first link!

    Hope this helps will save you LOTS OF TIME! TRUST ME I KNOW!
    Marcus Williamson
  • Options
    Danman32Danman32 Member Posts: 1,243
    Visual Basic 2005

    I will try File.GetAttributes(srcFileName) and File.SetAttributes(dstFileName).
    Thanks for the suggestion :)

    Careful, attributes are not the same as ACLs.
  • Options
    Megadeth4168Megadeth4168 Member Posts: 2,157
    Looks good, I'll check it out
Sign In or Register to comment.