ano*_*ery 7 c# asp.net iis antivirus process
我试图在ASP.Net Web应用程序中的上传文件上运行防病毒扫描.我们正在使用Sophos,因此可以访问他们的命令行API sav32cli
.在我使用的代码中:
Process proc = new Process();
proc.StartInfo.FileName = @"C:\Program Files (x86)\Sophos\Sophos Anti-Virus\sav32cli.exe";
proc.StartInfo.Arguments = @"-remove -nc " + SavedFile;
proc.StartInfo.Verb = "runas";
proc.Start();
proc.WaitForExit();
int exitCode = proc.ExitCode;
Run Code Online (Sandbox Code Playgroud)
当单步执行代码时,当连接到w3wp
开发服务器上的进程时,代码只是从一行跳到另一行似乎什么都不做.从dev服务器上的代码运行时,它会执行预期的扫描文件并删除它是否被视为病毒.
服务器正在运行IIS 8.0,以及.Net Framework 4中内置的应用程序.我已根据这些说明更改了机器配置以允许进程作为SYSTEM帐户运行.https://support.microsoft.com/en-us/kb/317012#%2Fen-us%2Fkb%2F317012
<processModel userName="SYSTEM" password="AutoGenerate" />
Run Code Online (Sandbox Code Playgroud)
有什么我想念的吗?这种实施的最佳实践是什么?
编辑:调用时,Process
返回ExitCode
2(错误停止执行),而不是预期的0(扫描工作,没有病毒),或3(扫描工作,发现病毒).
编辑2:根据下面的评论,我将代码更改为:
Process proc = new Process();
proc.StartInfo.FileName = @"C:\Program Files (x86)\Sophos\Sophos Anti-Virus\sav32cli.exe";
proc.StartInfo.Arguments = @"-remove -nc " + SavedFile;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.Start();
StringBuilder output = new StringBuilder();
while (!proc.StandardOutput.EndOfStream)
{
string line = proc.StandardOutput.ReadLine();
output.AppendLine(line);
}
proc.WaitForExit();
int exitCode = proc.ExitCode;
ASPxMemo2.Text = exitCode.ToString() + Environment.NewLine + output.ToString();
Run Code Online (Sandbox Code Playgroud)
output
在IIS上运行时始终为空,但在从代码运行时正确填充.
编辑3:而不是看着StandardOutput
我们看,StandardError
它揭示了这个错误:
初始化检测引擎时出错[0xa0040200](可能用户管理员权限不足.)
目前我们将转向另一种病毒检查方法,但如果有人拥有它,我们仍然想知道一种可能的解决方案.
您是否尝试过以更高的信任度运行您的 Web 进程?
<system.web>
<securityPolicy>
<trustLevel name="Full" policyFile="internal"/>
</securityPolicy>
</system.web>
Run Code Online (Sandbox Code Playgroud)