Force Files to Mot Be Read Only

When you need to ensure a file isn't inverse under any circumstances in Windows, information technology's time to make information technology read-only. Setting a file as read-simply or write-protecting a file prevents any changes whatsoever. If you don't know how to set up files equally read-only and need to, you lot're in the right identify!

In this tutorial, you're going to learn how to set and remove the read-merely attribute in File Explorer, the command-line (cmd), and via PowerShell!

Let's become going.

Prerequisites

This post will be a hands-on tutorial. If yous'd similar to follow along, be sure you accept the following:

  • A Windows PC. This tutorial will employ Windows 10 and Windows PowerShell v5.1.
  • A file to toggle the read-only attribute on. This tutorial volition use a file located at C:\Shared\readme.txt.

How to Brand a File Read-Only (and Writable) in File Explorer

In that location are a few different means to set a file as read-simply simply allow'southward start out this tutorial by commencement roofing how to make it happen via Windows File Explorer.

The read-only attribute is stored as a metadata property rather than in the content of the file. The property can be seen through Windows File Explorer.

Assuming that you're on the desktop of your Windows PC:

ane. Open Windows File Explorer and navigate to the folder that stores the file you'll be working with (C:\Shared) in this case.

ii. Right click the file and click Properties to open up the file's Backdrop box. This box contains various metadata about that particular file such as size, when it was created, modified, etc. Information technology besides has file attributes.

Click the read-simply checkbox in the Attributes group to write-protect the file or set it as read-only, click Apply to assign the read-merely attribute, and OK to shut the dialog box.

The properties box of the file readme.txt. Note the location of the Read-only attribute check box and the Apply button.
The backdrop box of the file readme.txt. Annotation the location of the Read-just attribute check box and the Apply button.

Similarly, to remove the read-only attribute from the file, uncheck the Read-only checkbox.

How to Make a File Read-But (and Writable) via Command Line

File attributes aren't just exposed via File Explorer. You can also manipulate file attributes including the read-only attribute via the command line. To do so, you must use a command called attrib.

one. Open a control prompt (cmd.exe).

ii. Navigate to the folder the file is in.

3. Run attrib with no parameters. The attrib command volition immediately look for all files in the working directory and return all files and the enabled file attributes. Yous can see below the readme.txt file does not take the read-only attribute enabled.

Archive attribute enabled (A) but no read-only attribute (R)
Archive aspect enabled (A) simply no read-only attribute (R)

4. Now, run attrib to assign the read-only attribute. The +r parameter is fundamental hither. This parameter tells Windows to set the read-only attribute on the file.

5. Run attrib once again with no parameters to verify the read-merely attribute was applied. Yous can at present see in the screenshot below the R label shows up indicating the read-merely aspect has been applied write-protecting the file.

Read-only attribute (R) is now enabled
Read-just attribute (R) is now enabled

Similarly, to remove the read-but aspect use the -r parameter.

How to Make a File Read-Only (and Writable) with PowerShell

If you're not a fan of the GUI or the command prompt or want to apply have a lilliputian more than ease of control, look no farther than PowerShell! Let's now learn how to brand a file read-only with PowerShell!

  1. Open Windows PowerShell.

2. Run the Get-Particular cmdlet providing the path to the file you lot're toggling the read-only attribute on. The Attributes holding returned contains each file attribute that'south currently enabled.

            get-item -Path "c:\shared\readme.txt" | format-tabular array proper noun, attributes          
The Archive attribute is only enabled.
The Archive attribute is just enabled.

Using the Format-Table cmdlet is not necessary merely by doing then, tells PowerShell to display only the two properties you're interested in in an piece of cake-to-view format (Name and Attributes)

3. Assign the read-only attribute past adding the ReadOnly attribute to the Attributes property as shown below.

            ## Capture the file object in the $file variable  $file = Get-Item -Path "c:\shared\readme.txt" ## Not to overwrite the existing attributes, create a new array containing ## the current file attributes while adding the ReadOnly attribute and assign ## that array as the new value of the Attributes property  $file.Attributes = @($file.Attributes,"ReadOnly")          
Assigning the Read Only Attribute
Assigning the Read Merely Attribute

four. Now, view the Attributes belongings of the $file object and yous'll run across that yous've at present practical the ReadOnly attribute to the file while maintaining whatsoever existing attributes that existed on the file beforehand. You tin also run Go-Item over again to view the same results.

Viewing the Attribute Property
Viewing the Attribute Belongings

To remove the ReadOnly aspect from the file, follow the exact same approach but this time gear up the value of the Attributes property to Normal eastward.k. $file.Attributes = "Normal".

Conclusion

Yous should now know how to gear up a file every bit read-but and vice versa. Setting a file equally read-only is meant to forbid accidental changes. Merely know that, setting a file as read-just is not necessarily a security measure and does not prevent access to the file or someone from merely irresolute the aspect themselves.

Armed with this new knowledge of protecting files from being accidentally overwritten, do you have any files you lot'd like to protect?

sanchezgoety1946.blogspot.com

Source: https://adamtheautomator.com/how-to-make-a-file-read-only/

0 Response to "Force Files to Mot Be Read Only"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel