Bredonosec> есть такая задача.
Bredonosec> Заблокировать файл от изменений и стираний.
Можно открыть с блокировкой на запись. Тогда, пока процесс висит, будет неизменяем, нестираем. А вот переместить можно.
Bredonosec> Отнятие прав не вариант, бо автоматически под админом запускается скрипт, который в числе прочего восстанавливает права (работает с cacls).
http://www.microsoft.com/downloads/... — попробуй более мощную.
Там можно кое-что менять, что нельзя в основной. Можно забрать права у админа на чтение папки.
Тогда он не увидит файл, соответственно, cacls не сможет восстановить права. Но сам понимаешь, что такая защита легко пробиваема.
Bredonosec> Блокирование должно происходить даже при запуске компа автоматически, без локально залогиненных пользователей. То есть, запускаемая после логона в профиле юзера программка не годится.
Оформить маленький сервис, который подднимается автоматом.
Bredonosec> Желательно, чтоб это был или бесплатный софт, или который можно скрыть. Или некие системные возможности. Словом, варез светиться не должен.
http://msdn.microsoft.com/en-us/library/40xe80wx%28v=vs.80%29.aspx — как создать сервис.
If you choose not to use the Windows Service project template, you can write your own services by setting up the inheritance and other infrastructure elements yourself. When you create a service programmatically, you must perform several steps that the template would otherwise handle for you:
You must set up your service class to inherit from the ServiceBase class.
You must create a Main method for your service project that defines the services to run and calls the Run method on them.
You must override the OnStart and OnStop procedures and fill in any code you want them to run.
// Дальше — msdn.microsoft.com
Если сервис писать неохота, то напиши просто программку, а её запусти при помощи
http://www.codeproject.com/KB/system/xyntservice.aspx
Командочка SC —
http://technet.microsoft.com/en-us/library/bb490995.aspx — обеспечит тебе работу с сервисами из CLI.
http://msdn.microsoft.com/en-us/library/aa363858.aspx — как открывать файлы.
The CreateFile function can create a new file or open an existing file. You must specify the file name, creation instructions, and other attributes. When an application creates a new file, the operating system adds it to the specified directory.
The operating system assigns a unique identifier, called a handle, to each file that is opened or created using CreateFile. An application can use this handle with functions that read from, write to, and describe the file. It is valid until all references to that handle are closed.
// Дальше — msdn.microsoft.com
http://msdn.microsoft.com/en-us/library/aa365202.aspx — локирование.
Locks the specified file for exclusive access by the calling process. This function can operate either synchronously or asynchronously and can request either an exclusive or a shared lock.
A handle to the file. The handle must have been created with either the GENERIC_READ or GENERIC_WRITE access right. For more information, see File Security and Access Rights.
This parameter may be one or more of the following values.
The function requests an exclusive lock. Otherwise, it requests a shared lock.
The function returns immediately if it is unable to acquire the requested lock.
// Дальше — msdn.microsoft.com
В последнем для тебя важно:
Locking a portion of a file for shared access denies all processes write access to the specified region of the file, including the process that first locks the region. All processes can read the locked region.
Bredonosec> Я предполагаю, что запуск при старте чего-то, что будет занимать этот файл, было б идеально. Или добавить в список подгружаемых длл-ок к какому-нить системному процессу (только не к проводнику - он может быть не запущен вовсе)
Bredonosec> есть ли такие средства, и если да, то какие?
Xcacls.vbs is an unsupported tool that provides additional capabilities not provided with the supported utility, Xcacls.exe.
// www.microsoft.com