mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-06 00:38:49 +01:00
🎨 Support one-click addition of Microsoft Defender exclusions https://github.com/siyuan-note/siyuan/issues/13650
This commit is contained in:
parent
311b9e7b3d
commit
2ecdc7a295
1 changed files with 5 additions and 5 deletions
|
|
@ -52,17 +52,17 @@ func AddMicrosoftDefenderExclusion() (err error) {
|
|||
installPath := filepath.Dir(util.WorkingDir)
|
||||
psArgs := []string{"-Command", "Add-MpPreference", "-ExclusionPath", installPath, ",", util.WorkspaceDir}
|
||||
if isAdmin() {
|
||||
logging.LogInfof("current user is admin, add Windows Defender exclusion path [%s, %s]", installPath, util.WorkingDir)
|
||||
logging.LogInfof("current user is admin, add Windows Defender exclusion path [%s, %s]", installPath, util.WorkspaceDir)
|
||||
cmd := exec.Command("powershell", psArgs...)
|
||||
gulu.CmdAttr(cmd)
|
||||
output, cmdErr := cmd.CombinedOutput()
|
||||
if nil != cmdErr {
|
||||
logging.LogErrorf("add Windows Defender exclusion path [%s, %s] failed: %s, %s", installPath, util.WorkingDir, cmdErr, string(output))
|
||||
logging.LogErrorf("add Windows Defender exclusion path [%s, %s] failed: %s, %s", installPath, util.WorkspaceDir, cmdErr, string(output))
|
||||
err = cmdErr
|
||||
return
|
||||
}
|
||||
} else {
|
||||
logging.LogInfof("current user is not admin, use elevator to add Windows Defender exclusion path [%s, %s]", installPath, util.WorkingDir)
|
||||
logging.LogInfof("current user is not admin, use elevator to add Windows Defender exclusion path [%s, %s]", installPath, util.WorkspaceDir)
|
||||
elevator := filepath.Join(util.WorkingDir, "elevator.exe")
|
||||
if "dev" == util.Mode || !gulu.File.IsExist(elevator) {
|
||||
elevator = filepath.Join(util.WorkingDir, "elevator", "elevator-"+runtime.GOARCH+".exe")
|
||||
|
|
@ -83,13 +83,13 @@ func AddMicrosoftDefenderExclusion() (err error) {
|
|||
argPtr, _ := syscall.UTF16PtrFromString(strings.Join(ps, " "))
|
||||
execErr := windows.ShellExecute(0, verbPtr, exePtr, argPtr, cwdPtr, 1)
|
||||
if execErr != nil {
|
||||
logging.LogErrorf("add Windows Defender exclusion path [%s, %s] failed: %s", installPath, util.WorkingDir, execErr)
|
||||
logging.LogErrorf("add Windows Defender exclusion path [%s, %s] failed: %s", installPath, util.WorkspaceDir, execErr)
|
||||
err = execErr
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
logging.LogInfof("added Windows Defender exclusion path [%s, %s]", installPath, util.WorkingDir)
|
||||
logging.LogInfof("added Windows Defender exclusion path [%s, %s]", installPath, util.WorkspaceDir)
|
||||
util.PushMsg(Conf.language(102), 5000)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue