O
O
Ogoun Er2011-03-05 18:06:05
JavaScript
Ogoun Er, 2011-03-05 18:06:05

How to lock a file in JScript(WSH)?

I want to block the file with parameters for the execution time, so that when accessing it, access is denied. Tried like this:

var fso = new ActiveXObject('Scripting.FileSystemObject');
var Lockeds = new ActiveXObject("Scripting.Dictionary");

function LockFile(path) {
    if (!Lockeds.Exists(path)) {
        //открываю указанный файл в режиме добавления содержимого, и не закрываю его
        Lockeds.Add(path, fso.OpenTextFile(path, 8));
    }
}

function UnLockFile(path) {
    if (Lockeds.Exists(path)) {
        //Закрываю файл
        Lockeds.Item(path).Close();
        Lockeds.Remove(path);
    }
}

, but does not help, the file can still be accessed for reading.
Purpose: to exclude the possibility of running more than one copy of the script at the same time.
Making a record, for example, in the log is not an option, because. no end of operation will be recorded when the power fails or reboots.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question