从命令行调用DoScan.exe实用程序 [英] Calling DoScan.exe utility from Command Line

查看:74
本文介绍了从命令行调用DoScan.exe实用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!



是否有人知道如何从Windows Server 2008(64位)环境中的C#代码调用DoScan.exe实用程序(Symantic Endpoint Protection)。



我想要扫描用户从我网站上传的文件,如果发现任何受感染的文件,我想删除它们。



我已经为Windows XP(32位)系统做了这个,我的代码成功了。

但是当我试图在Windows Server 2008中执行相同的活动时,它会失败。



以下是代码

  public   void  PerformScanning( string  [] strfiles, string  strFilePath, string  strDestPath)
{
try
{

处理myProcess;
FileStatus objFileStatus;
myProcess = new Process();
if (!Directory.Exists(strFilePath + \\Logs))
{
Directory.CreateDirectory(strFilePath + \\Logs);
}
foreach string strFile in strfiles)
{
objFileStatus = new FileStatus();
myProcess.StartInfo.FileName = C:\\Program Files \\ Symantec \ \ Symantec Endpoint Protection\\DoScan.exe;

string myprocarg = C:\\Program Files \\ Symantec \\\\ tymantec Endpoint Protection \\DoScan.exe / cmdlinescan + strFile + / LOGFILE = \\ + strFilePath + \\Logs \\ + Path.GetFileName(strFile)+ 。 log \;
myProcess.StartInfo.Arguments = myprocarg;
myProcess.Start();
myProcess.WaitForExit();

int j = 0 ;
int y = 0 ;
for (j = 0 ; j < = 1000000 ; j ++)
{
y = y + 1 ;
}
string FILENAME = strFilePath + \\Logs\\ + Path.GetFileName(strFile)+ 的.log;
string SearchLine = null ;
bool IsClean = true ;
string MyFound = null ;

StreamReader objStreamReader = 默认(StreamReader);
objStreamReader = File.OpenText(FILENAME);

while (objStreamReader.Peek()!= -1)
{
SearchLine = objStreamReader.ReadLine() ;
if (SearchLine.Contains( Found ))
{
IsClean = false ;
MyFound = SearchLine;
}
}
objStreamReader.Close();


if (IsClean)
{
File.Move(strFile,strDestPath + \\ + Path.GetFileName(strFile));
if (File.Exists(strFilePath + \\ + strfiles))
{
File.Delete(strFilePath + \\ + strfiles);
}
objFileStatus.UpdateUploadedFileStatus( Sucess Y,strDestPath + \\ + Path.GetFileName(strFile),Path.GetFileNameWithoutExtension(strFile).Substring( 6 ,Path.GetFileNameWithoutExtension( strFile).Length - 6 ), 未检测到威胁);
Console.WriteLine( 文件: + strFile + 成功扫描);
File.Delete(strFilePath + \\Logs \\ + Path.GetFileName(strFile)+ .log);

}
else
{
string path = strFile;
File.Delete(path);
objFileStatus.UpdateUploadedFileStatus( 失败 N,strFile,Path.GetFileNameWithoutExtension(strFile).Substring( 6 ,Path .GetFileNameWithoutExtension(strFile).Length - 6 ), 发现病毒);
Console.WriteLine( 文件: + path + 已删除。);

}
}
}
catch
{
Console.Write ( 由于某些异常),无法完成流程;
}
}

[/编辑]



任何帮助都将不胜感激。



谢谢



Sanjay

解决方案

从上面的代码片段开始我知道你将无效的文件名和参数传递给myProcess。

它应该像

 myProcess.StartInfo.FileName =   C:\\Program Files \\ Symantec \\ Symantec Endpoint Protection\\DoScan.exe ; 
string myprocarg = / cmdlinescan + strFile + / LOGFILE = \\ + strFilePath + \\Logs \\ + Path.GetFileName(strFile)+ 。log \;
myProcess.StartInfo.Arguments = myprocarg;
myProcess.Start() ;





如果有效,请尝试回答。



所有最好的。

Kiran


也更新了终点

http://www.symantec.com/business/support/索引?页=含量&ID = TECH105414

Hi!!

Does any one know how to invoke the DoScan.exe utility(Symantic Endpoint Protection) from the C# Code in Windows Server 2008(64bit) environment.

I want the files uploaded by users from my website to be scanned and if any infected files are found i want to remove those.

I have done this for Windows XP (32bit) System and my code does it successfully.
But when i tried to do the same activity in windows server 2008 , it fails.

[Edit]Here is the code

public void PerformScanning(string[] strfiles, string strFilePath,string strDestPath)
        {
            try
            {

                Process myProcess;
                FileStatus objFileStatus;
                myProcess = new Process();
                if (!Directory.Exists(strFilePath + "\\Logs"))
                {
                    Directory.CreateDirectory(strFilePath + "\\Logs");
                }
                foreach (string strFile in strfiles)
                {
                    objFileStatus = new FileStatus();
                   myProcess.StartInfo.FileName = "C:\\Program Files\\Symantec\\Symantec Endpoint Protection\\DoScan.exe";
                  
                    string myprocarg = "C:\\Program Files\\Symantec\\Symantec Endpoint Protection\\DoScan.exe /cmdlinescan " + strFile + "/LOGFILE=\\" + strFilePath + "\\Logs\\" + Path.GetFileName(strFile) + ".log\"";
                    myProcess.StartInfo.Arguments = myprocarg;
                    myProcess.Start();
                    myProcess.WaitForExit();

                    int j = 0;
                    int y = 0;
                    for (j = 0; j <= 1000000; j++)
                    {
                        y = y + 1;
                    }
                    string FILENAME = strFilePath + "\\Logs\\" + Path.GetFileName(strFile) + ".log";
                    string SearchLine = null;
                    bool IsClean = true;
                    string MyFound = null;

                    StreamReader objStreamReader = default(StreamReader);
                    objStreamReader = File.OpenText(FILENAME);

                    while (objStreamReader.Peek() != -1)
                    {
                        SearchLine = objStreamReader.ReadLine();
                        if (SearchLine.Contains("Found"))
                        {
                            IsClean = false;
                            MyFound = SearchLine;
                        }
                    }
                    objStreamReader.Close();


                    if (IsClean)
                    {
                        File.Move(strFile, strDestPath + "\\" + Path.GetFileName(strFile));
                        if (File.Exists(strFilePath + "\\" + strfiles))
                        {
                            File.Delete(strFilePath + "\\" + strfiles);
                        }
                        objFileStatus.UpdateUploadedFileStatus("Sucess", "Y", strDestPath + "\\" + Path.GetFileName(strFile), Path.GetFileNameWithoutExtension(strFile).Substring(6, Path.GetFileNameWithoutExtension(strFile).Length - 6), "No threat detected");
                        Console.WriteLine("File:" + strFile + "Scanned Sucessfully");
                        File.Delete(strFilePath + "\\Logs\\" + Path.GetFileName(strFile) + ".log");

                    }
                    else
                    {
                        string path = strFile;
                        File.Delete(path);
                        objFileStatus.UpdateUploadedFileStatus("Failure", "N", strFile, Path.GetFileNameWithoutExtension(strFile).Substring(6, Path.GetFileNameWithoutExtension(strFile).Length - 6), "Virus Found");
                        Console.WriteLine("File:" + path + "Deleted.");

                    }
                }
            }
            catch
            {
                Console.Write("The Process Cannot be completed due to some exception");
            }
        }

[/Edit]

any help would be appreciated.

Thanks

Sanjay

解决方案

From the code snippet above what I understand you are passing invalid filename and arguments to the myProcess.
It should be like

myProcess.StartInfo.FileName = "C:\\Program Files\\Symantec\\Symantec Endpoint Protection\\DoScan.exe";
string myprocarg = " /cmdlinescan " + strFile + "/LOGFILE=\\" + strFilePath + "\\Logs\\" + Path.GetFileName(strFile) + ".log\"";
myProcess.StartInfo.Arguments = myprocarg;
myProcess.Start();



Please try and like the answer if it works.

All the Best.
Kiran


Also updated end point
http://www.symantec.com/business/support/index?page=content&id=TECH105414


这篇关于从命令行调用DoScan.exe实用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆