Programmatically Make a File Read-Only From LabVIEW

Updated Aug 28, 2023

Reported In

Software

  • LabVIEW

Issue Details

Is it possible in LabVIEW to programmatically set a file as read-only, and if so, how do I do it?

Solution

LabVIEW 7.1 
Read-only permissions can be set in LabVIEW by using the Access Rights.vi, located under All Functions»File I/O»Advanced File Functions in the functions palette.
LabVIEW 8.x and Later
Read-only permissions can be set in LabVIEW by using the Set Permissions.vi, located under Programming»File I/O»Advanced File Functions in the functions palette.
 
In order to set permissions as read-only for users, the new permissions or the permissions input should be 100000000 in binary, or 256 in decimal, depending on the format of the input. The default format of the input is decimal. To return the permissions to read/write, simply input 110000000 in binary or 384 in decimal.

Additional Information

The path input specifies the file or directory whose access rights are to be changed, while the new permissions or permissions input specifies exactly what permissions are set. The new permissions parameter in 7.1 and the permissions parameter in 8.x is represented by a 16-bit integer and it uses the least significant 9-bits of this integer to specify read, write, and execute permissions for users, groups, and others. The following illustration shows the format of this parameter:
 
Note that the use of the permissions parameter is very limited on non-Linux operating systems. You can use permissions to change only write permissions for users (bit 7); the operating system ignores changes to all the other bits. For additional details on how the Set Permissions.vi behaves, see LabVIEW Help: Setting Permissions .