SetReadOnly.vbs
This script, which sets the read-only attribute of a file, requires three parameters:
It requires three parameters:
- The full path to the file.
- The required Read Only state: y or Y makes the file read only, and all other characters allow users to edit the file.
- The full path to a log file, which is created by the script if an error occurs. In this case, an error message is written to the file (if possible). If the special value *DEBUG is provided as the third parameter, error messages are shown interactively.
The script returns one of the following codes:
- 0: the script was successful
- 1: the script failed; an error message has been written to the log file
- 2: the script failed and was unable to write an error message to the log file
- 3: the script was not called according to its signature (wrong number of parameters)
This example script demonstrates how SetReadOnly can be called from within a KCM Core script.
# ITP/Server script SetReadOnly
Parameter Text File;
Parameter Boolean ReadOnly;
Parameter Text LogFile;
Const Text pathtovbs = "C:\Program files\ITP Server\Tools\SetReadOnly.vbs";
# The declaration above is one line!
Var Text readonlychar = "N";
If (ReadOnly) Then
readonlychar = "Y";
Fi;
RunCommand
CmdLine("WScript.exe //B //nologo " +
"""" + pathtovbs + """ " +
"""" + File + """ " +
"""" + readonlychar + """ " +
"""" + LogFile + """");
# Please note that all quotes in CMDLine are needed. (quotes are
# used to escape quotes)