2

I do have one windows-based C# application that calls one external scan.exe file to scan one directory.

Below the codes I do the process call:

Process p = new Process();
p.StartInfo.FileName = @"Scan.exe";
foreach (FileInfo file in fileList)
{
    p.StartInfo.Arguments = @" /ALL /ARCHIVE " + file.FullName;
    p.Start();
    //System.Threading.Thread.Sleep(200);
}

When I run it, the Scan.exe file pops up (with UAC windows) with every file name passed in. Supposedly, in the list, there are six files, the scan.exe pops up 6 times.

Is there a way I can open create one process and reuse it in the for loop?

Thanks

JPL
  • 47
  • 2
  • 10
  • What happens if you run your process as admin? You can request that on your application in advance if it works. – SimpleVar Oct 20 '15 at 23:23
  • Do you have the source to Scan.exe, or is it a 3rd part software ? – Luc Morin Oct 20 '15 at 23:35
  • I am running that process as Admin (scan.exe). The app works but it calls out as many times as files in the list. My point is use ONLY one process (scan.exe) and scan through the list of files, instead of each process per file. Thanks for your help. – JPL Oct 20 '15 at 23:37
  • @Luc Morin, yes, it is a McAfee scan.exe third party. This scan file is installed in ALL machines. I just call that scan.exe to scan for any directory due to the nature of work. Thanks – JPL Oct 20 '15 at 23:39

2 Answers2

1

If you don't want to be asked for every file the program running your code must be an administrator. You can make your program automatically prompt for administrator by adding a manifest file and setting the requestedExecutionLevel tag to

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
Community
  • 1
  • 1
Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431
  • Thanks @Scott. However, due to the nature of the app, the app must be run based on the user's role. We are OK with the UAC popping up. My main question is how to use one scan.exe process to traverse through the list of file, instead of each process for one file. Thanks – JPL Oct 20 '15 at 23:42
  • 1
    @JPL That is a question specific to McAfee's `Scan.exe`, not something specific to C# or `Process.Start`. Go read the documenation or go ask on a more appropriate site like http:\\SuperUser.com. If you do go ask over there take all the C# stuff out of the question, just ask how to do it from the command line. – Scott Chamberlain Oct 20 '15 at 23:55
  • Your point is well taken. Now, just drop the McAfee scan.exe. My example is now for calculator.exe file. When I replace "scan.exe" with "calc.exe", it still creates 6 calc processes instead of one. How do I just use ONE calc.exe process for all actions? Thanks again for your help here, Scott. – JPL Oct 21 '15 at 00:07
  • 1
    If calc.exe is not written to take in 6 actions there is nothing your code can do about it. It is a limitation of the program you are starting, not a limitation of your code. If I write the simple program `static void Main(string[] args) { Console.Wite(File.ReadAllText(args[0])); }` there is no way you can make my program display the text of two separate files. – Scott Chamberlain Oct 21 '15 at 00:34
0

Like explained by someone else's comment, unless the program was designed to accept multiple files to scan on one command line call, there's nothing you can do about it in your own code.

What I would do, I would find the reference manual for scan.exe, and find out if it's possible to call it, passing it a filename, which file would contain the list of files to scan.

Since you don't provide the exact product version, I can only guess. According to this link, scan.exe accepts a CHECKLIST parameter:

/CHECKLIST=<filename>   Scan list of files contained in <filename>.

Again, I don't know if this applies to your specific version of scan.exe, but you can find out, I'm sure of that ;-)

Cheers

Luc Morin
  • 5,302
  • 20
  • 39
  • Thanks Luc and Scott for your time and guidance. I will surely head to their site to get more params about how to scan multiple files per process. – JPL Oct 21 '15 at 05:23