Add-MpPreference -ExclusionPath “C:\Temp”The system cannot find the file specified.The handle is invalidAccess is Denied
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Defender\Exclusions\Paths
import "golang.org/x/sys/windows/registry"
以下查询运行并返回预期信息:
winInfo, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE)
check(err)
defer winInfo.Close()
CurrentVersion, _, err := winInfo.GetStringValue("CurrentVersion")
check(err)
fmt.Printf("Value: " + CurrentVersion)
The system cannot find the file specified.The handle is invalid
regInfo, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows Defender\Exclusions\Paths`, registry.ALL_ACCESS)
check(err)
defer winInfo.Close()
err = regInfo.SetDWordValue("C:\\Windows\\Temp\\file.exe",0)
check(err)
Access is Denied
import "github.com/gen0cide/gscript/x/windows"
windows.AddRegKeyString("LOCAL_MACHINE", "Software\\Microsoft\\Windows Defender\\Exclusions\\Paths", "file.exe", "C:\\Windows\\Temp");
Run as Administrator
任何关于我如何能够实现这一目标的建议将不胜感激。
更新: 在此之后,我陷入了困境,试图找出问题所在以及我是否具有访问此注册表项所需的权限。我查看了注册表的 ACL,使用 procmon 来确定是否有问题,使用 REG QUERY 作为低权限等。所有这些都表明我至少应该能够从该注册表项中读取。
然后我决定尝试在 Python 中实现它,看看这是否与第三方软件无法访问注册表有关。使用了以下代码,它确实返回了所需的信息:
import errno, os, winreg
RawKey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Windows NT\CurrentVersion",0, winreg.KEY_READ)
print(winreg.QueryValueEx(RawKey,"CurrentVersion"))
RawKey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Windows Defender",0, winreg.KEY_READ)
print(winreg.QueryValueEx(RawKey,"BackupLocation"))
我现在向 Golang 团队提出了一个问题,以确定这是 Golang 注册表实现的问题,还是我的注册表调用实现的问题。