Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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
Posted 9-Jul-12 22:20pm
Edited 10-Jul-12 22:55pm
v3
Comments
OriginalGriff at 10-Jul-12 3:31am
   
What code did you use? How did it fail? Error messages? Anything?
KothaSanjay at 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 at 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 at 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 at 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.
Kiran Susarla at 10-Jul-12 3:42am
   
Using the Process.Start method you should be able to call the executable.
If the executable file path is not added to the environment variable "PATH", then Process.Start may not be able to find this executable and will throw exception.
It is always better to pass the entire absolute filepath of the executable to the Process.Start method.
KothaSanjay at 10-Jul-12 4:01am
   
yes i have given the absolute path for the for calling the executable.and the below lines of code does exactly the same.
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();
 
lukeer at 10-Jul-12 5:14am
   
Better than posting code as comment is posting it using the "Improve question" link right below your question text. FTFY.
KothaSanjay at 10-Jul-12 5:22am
   
Thank you for ur help!
pradiprenushe at 10-Jul-12 5:17am
   
What error or exception it gives?
KothaSanjay at 10-Jul-12 6:08am
   
it already mentioned in on of the comments which i posted..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Comments
KothaSanjay at 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 at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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

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

  Print Answers RSS
0 OriginalGriff 381
1 Sergey Alexandrovich Kryukov 245
2 Marcin Kozub 225
3 Praneet Nadkar 217
4 /\jmot 189
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,614
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 28 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100