VBScript - Changing Folder Attribute


  • Hi,

    I have a folder name FSO on my c drive. Inside this folder I have different type of file.

    I want to create a VBscript that will allow me to set the entire folder on Read-Only so data inside won`t be modify.

    Right now I have the following statement but it does not work.

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.GetFolder("C:\FSO")
    If objFolder.Attributes = objFolder.Attributes AND 1 Then
        objFolder.Attributes = objFolder.Attributes XOR 1
    End If

    Thursday, September 26, 2013 9:15 PM


All replies

  • right click on folder and choose the read only checkbox.


    Thursday, September 26, 2013 9:25 PM
  • The FSO is only a test folder to I can make sure the script is running fine.

    The actual folder is located in the user profile and I have over 500 pc to do so I`m not going to right click each and every computer. This is the reason why I mention I want to create a VBScript file

    Thanks for the quick answer

    Thursday, September 26, 2013 9:32 PM
  • What's the goal? If you want read-only for users, then don't give them permission to write or delete. Attribute change won't do that since they can simply right-click the file and uncheck the "read-only" box.


    Thursday, September 26, 2013 9:39 PM
  • You can set this globally using a GPO.  Just define the folder you want to guard and set the security in the GPO.  It will apply to all computers within about 30 minutes to one hour.

    The Read-only attribute of a folder does nothing in NTFS.  You are wasting your time.

    Use GP and set folder security to everyone read and Admins FULL.  It takes about 5 minutes to define the GPO.


    Thursday, September 26, 2013 9:52 PM
  • Here is the story,

    I want to prevent user from modifying their outlook signature. To achieve this  I thought about creating a VBS files that is going to be push by a GPO that contain a value to put the signature folder in read-only so most of the users will not know how to modify it and if a support technician needs to modify it he can just remove the check mark from the read only modify it and but the check mark back.

    By doing this instead of having 1000 users modifying their signature i`m only going to have about 10 so it`s easier after to deal with those 10 users.

    I did check some software that can add signature on the exchange server directly but the Issus with this is it`s adding the signature at the complete end so If you have a bunch of reply/forward all your signature are at the end the email and not the text you just add.

    Thursday, September 26, 2013 10:32 PM
  • It won't work but go ahead and try it

    attrib +r %userprofile%\Local\Application Date\Microsoft....

    That sets a folder to read -only.  It doe not make it read only for the owner and it will not work. Try it.


    Thursday, September 26, 2013 10:46 PM
  • Thursday, September 26, 2013 10:51 PM