예제 #1
0
        /// <summary>
        /// Removes the "Allow" read permissions, and adds the "Deny" read permission
        /// on the HOSTS file. If the Hosts file cannot be locked, the exception error
        /// will be logged in the App error log
        /// </summary>
        public bool Lock()
        {
            // Make sure we have a security object
            if (Security == null)
            {
                return(false);
            }

            // Donot allow Read for the Everyone Sid. This prevents the BF2 client from reading the hosts file
            Security.RemoveAccessRule(new FileSystemAccessRule(WorldSid, FileSystemRights.ReadData, AccessControlType.Allow));
            Security.AddAccessRule(new FileSystemAccessRule(WorldSid, FileSystemRights.ReadData, AccessControlType.Deny));

            // Try and set the new access control
            try
            {
                HostFile.SetAccessControl(Security);
                IsLocked = true;
                return(true);
            }
            catch (Exception e)
            {
                TraceLog.TraceError("Unable to REMOVE the Readonly rule on Hosts File: " + e.Message);
                LastException = e;
                return(false);
            }
        }
예제 #2
0
        /// <summary>
        /// Removes the "Deny" read permissions, and adds the "Allow" read permission
        /// on the HOSTS file. If the Hosts file cannot be unlocked, the exception error
        /// will be logged in the App error log
        /// </summary>
        public bool UnLock()
        {
            // Make sure we have a security object
            if (Security == null)
            {
                return(false);
            }

            // Allow ReadData
            Security.RemoveAccessRule(new FileSystemAccessRule(WorldSid, FileSystemRights.ReadData, AccessControlType.Deny));
            Security.AddAccessRule(new FileSystemAccessRule(WorldSid, FileSystemRights.ReadData, AccessControlType.Allow));

            // Try and set the new access control
            try
            {
                HostFile.SetAccessControl(Security);
                IsLocked = false;
                return(true);
            }
            catch (Exception e)
            {
                TraceLog.TraceError("Unable to REMOVE the Readonly rule on Hosts File: " + e.Message);
                LastException = e;
                return(false);
            }
        }