Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
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
C#
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
Posted
Updated 10-Jul-12 21:55pm
v3
Comments
OriginalGriff 10-Jul-12 3:31am    
What code did you use? How did it fail? Error messages? Anything?
KothaSanjay 10-Jul-12 3:50am    
ok below is the code which intended to scan the files from a specified path to moves the scanned files to a target folder.It creates log files for the files whose scanning process has started. It works perfectly in XP but donno y it doest work in Windows server 2008 .Here the DoScan.exe doest get called and no log file get generated. The only exception that the code throws is file not found, and it is refering to the log file which is not gereated by the DoScan.exe

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 AntiVirus\\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");
}
}
Alan N 10-Jul-12 4:57am    
Have you opened a command window manually and typed in the command line to verify that it is correct?
KothaSanjay 10-Jul-12 5:04am    
Yes, In XP i have done this and when i attempted to do the same in windows server 2008 the DoScan.exe doesn't get open and nothing happens when i double click it.
Is this a drawback of Symantic anit virus system?
Alan N 10-Jul-12 6:03am    
I don't know anything about DoScan, but clearly if the program will not execute from a command prompt then trying to do the same via Process.Start will be a waste of time.

From the code snippet above what I understand you are passing invalid filename and arguments to the myProcess.
It should be like
C#
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
 
Share this answer
 
Comments
KothaSanjay 11-Jul-12 3:54am    
No ,the code which i posted was the one which is from my development system
and there the path is "C:\\Program Files\\Symantec AntiVirus\\DoScan.exe"
and i mentioned the correct path while testing in the server.
sorry i will update the question.
Looking for the correct solution.
Thanks in advance
Kiran Susarla 11-Jul-12 4:52am    
One more thing, on my x64 dev machine DoScan.exe is present in c:\program files(x86)\Symantec\Symantec Endpoint Protection\DoScan.exe. See if this is the path on your server as well.

http://www.codeproject.com/Articles/18577/How-to-redirect-Standard-Input-Output-of-an-applic
Go through the above link and pass your exe, parameters and check whether you are passing correct parameters or not and then you can modify the code accordingly.
Also updated end point
http://www.symantec.com/business/support/index?page=content&id=TECH105414
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900