首页 > 解决方案 > 通过 Powershell 删除所有用户的可执行位

问题描述

我有一个小问题想听听你的意见:

在我们两次在托管中心感染了恶意软件之后 - 我们决定在内部托管我们的服务器。但是为了避免再次感染蜜蜂 - 我们希望对本地 PC 的权限进行一些更改:在收集了大量信息后 - 我发现恶意软件很可能会自行安装在以下文件夹中:C:\Windows\Temp %USERPROFILE%\ Appdata\Local(Win 7/8/10/Vista)%USERPROFILE%\Local 设置

因此,我想从文件夹和子文件夹中删除可执行位 - 但这样做是明智的 - 因为很可能所有程序都是从 %USERDATA%\AppData\Local 执行的 - 那么没有程序将运行。我确实尝试过这个 - 但除非我改回来,否则无法开始任何事情

在谷歌上搜索了很多之后——我发现这个脚本做得最多——但仍然存在所有文件都无法执行的问题???

# Get the ACL for an existing folder For $Users
$existingAcl = Get-Acl -Path 'C:\Windows\Temp'
# Set the permissions that you want to apply to the folder
$permissions = $env:username, 'ExecuteFile', 'ContainerInherit,ObjectInherit', 'None', 'Deny'
# Create a new FileSystemAccessRule object
$rule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList         $permissions
# Modify the existing ACL to include the new rule
$existingAcl.SetAccessRule($rule)
# Apply the modified access rule to the folder
$existingAcl | Set-Acl -Path 'C:\Windows\Temp'

有人可以指出我正确的方式或告诉我这是否不好并且会破坏比它解决的更多

提前谢谢P

标签: powershellfilepermissions

解决方案


推荐阅读