I am using Doscan.exe of SEP to scan files before uploading but there is no provision provided by SEP to generate a separate log file for each scanned file, so that's why I am not able to make sure whether the file is ok or not for uploading.
If anyone has a way to check this thing then please let me know.
I am using version 14.2
Thanks.
ProcessStartInfo start = new ProcessStartInfo();
start.Arguments = " /ScanFile C:\\Users\\New Text Document (2).txt";
start.FileName = #"C:\Program Files (x86)\Symantec\Symantec Endpoint Protection\14.2.3332.1000.105\Bin\DoScan.exe";
start.WindowStyle = ProcessWindowStyle.Hidden;
start.CreateNoWindow = true;
using (Process proc = Process.Start(start))
{
proc.WaitForExit();
}
Related
ProcessStartInfo startInfo = new ProcessStartInfo();
Process first = new Process();
startInfo.FileName = "OUTLOOK";
startInfo.Arguments = "http:\\blabla.com\EMAIL.msg";
startInfo.CreateNoWindow = true;
first.StartInfo = startInfo;
first.Start();
i used Process.Start to start up Outlook and open a .Msg file. how can i reuse the same process to open another .msg file without opening multiple processes/threads/instances of outlook?
i have tried something like
Process[] outlook = Process.GetProcessesByName("OUTLOOK");
Process existing = outlook[0];
startInfo.FileName = "outlook";
startInfo.Arguments = "http:\\blabla.com\2ndEMAIL.msg";
startInfo.CreateNoWindow = true;
existing.StartInfo = startInfo;
existing.Start();
to reuse the same process but i'm still opening multiple windows of outlook instead of just the .MSG file it
Slightly modified your code, this might work.
var first = new Process();
var pinfo = new ProcessStartInfo
{
FileName = "http:\\blabla.com\EMAIL.msg",
Arguments = "/quiet",
CreateNoWindow = true
};
first.StartInfo = pinfo;
first.Start();
Only one instance of Outlook can be run at the same time.
how can i reuse the same process to open another .msg file without opening multiple processes/threads/instances of outlook?
You can use the Process.Start method to open the message in Outlook. There is no need to specify Outlook, only path to the .msg file.
Be aware, the Application class in Outlook provides you the CreateItemFromTemplate method. It creates a new Outlook item based on the specified template and returns the newly created Outlook item. You can use it to create an Outlook item based on the .MSG file. See How To: Create a new Outlook message based on a template for more information.
If you want to close the already open Outlook messages, it is your responsibility to do so - use Application.Inspectors collection to enumerate all messages that Outlook is currently displaying and close them.
Just do it
var process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = fullPath //path of msg file
};
process.StartInfo = startInfo;
process.Start();
I am running c# application in service mode. And i am using pdf2swf tool to convert odf to swf format. Images saved in pdf is converting. But if any test adding to pdf is not getting converted in service mode.
But when run as UI mode(Consoleapplication.exe) then everything is getting converted.
string inputFileName = this.Filename;
string outputFileName = inputFileName.Replace("pdf", "swf");
StringBuilder sb = new StringBuilder();
sb.AppendFormat("{0} -o {1}", inputFileName, outputFileName);
string executingDirPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase).Replace("file:\\", "");
string dataDirectoryPath = Path.Combine(executingDirPath, "pdf2swf.exe");
ProcessStartInfo psi = new ProcessStartInfo(dataDirectoryPath, sb.ToString());
psi.UseShellExecute = false;
System.Diagnostics.Process pdf2swf = new System.Diagnostics.Process();
pdf2swf.StartInfo = psi;
pdf2swf.Start();
pdf2swf.WaitForExit();
pdf2swf.Close();
pdf2swf.Dispose();
Regards
Sangeetha
Direct using process to start pdf2swf.ext maybe had some privilege problems.I used another way to solve this problem,write a batch file,then running the batch file by process.
Batch file sample:
c:
cd C:\Program Files (x86)\SWFTools\
pdf2swf.exe -f -T 9 -t "%1" -o "%2"
Code in program:
Process p = new Process();
string path = basePath + "/plugin/ConvertToSwf.bat";//batch file path
ProcessStartInfo pi = new ProcessStartInfo(path, filePath + " " + swfPath);//passing the file path and converted file path to batch file
pi.UseShellExecute = false;
pi.RedirectStandardOutput = true;
p.StartInfo = pi;
p.Start();
p.WaitForExit();
I faced a similar problem recently. I solved the issue by adding a separate console application(Consoleapplication.exe) with administrative-rights that runs on my server without shell.
Also, try to upgrade to the newest version of pdf2swf.
FYI. I recently had this problem (thought it was fonts not being embedded but actually was missing all text in converted swf). What fixed it for me was to set:
pi.UseShellExecute = false;
AND set the working directory;
pi.WorkingDirectory = "C:\windows\temp"; // path where read & write is
I have a C# asp.net web page which reads PDF file from Mysql database (which stores as longblob format) and open it. It works in my Localhost; the page reads the file from database and open with acrobat reader but it doesn't work in the testing server after i deploy the page. The acrobat reader doesn't open and i don't see acroRd32.exe in the taskmgr manager. I feel it is permission issue because i use process.start() which may not allow in the server but i dont see error messages. If there are permissions needs to be done in server; can anyone kindly points me the direction?
Thank You.
Here are my code:
MySqlDataReader Reader = null;
connection.Open();
MySqlCommand command = new MySqlCommand("Select Image, File_Type, File_Name from table where ImageID = " + ImageID, connection);
Reader = command.ExecuteReader();
if (Reader.Read())
{
byte[] buffer = (byte[])Reader["Image"];
System.IO.MemoryStream stream1 = new System.IO.MemoryStream(buffer, true);
stream1.Write(buffer, 0, buffer.Length);
String fileName = Reader["File_Name"].ToString();
String dirName = "C:\\thefolder\\";
if (!Directory.Exists(dirName))
{
// if not then create
Directory.CreateDirectory(dirName);
}
if (File.Exists(dirName+fileName))
File.Delete(dirName + fileName);
Directory.CreateDirectory(Path.GetDirectoryName(Reader["File_Name"].ToString()));
using (Stream file = File.Create(dirName + fileName))
{
file.Write(buffer, 0, buffer.Length);
}
Process process = new Process();
process.StartInfo.FileName = "AcroRd32.exe";
process.Start();
}
Thanks for your help, i am able to send pdf content via response. Here is the code
//Process process = new Process();
//process.StartInfo.FileName = "AcroRd32.exe";
//process.Start();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.Clear();
Response.AppendHeader("Content-Disposition", "attachment");
Response.TransmitFile(dirName + fileName);
Response.End();
Your C# code runs on the server.
Therefore, Process.Start starts a process on the server, not your computer.
It is fundamentally impossible for you to start a process directly on the client.
However, if you serve the PDF in the HTTP response (with the correct Content-Type), the browser will open it in a PDF viewer.
you don't have permissions to do that from the ASP.Net worker process.
you need impersonation:
ASP.NET Impersonation
How To: Use Impersonation and Delegation in ASP.NET 2.0
Hadn't read the question thoroughly...
If you won't to start a process on the server, you can use impersonation.
Otherwise you should serve this file from the IIS - to allow the user to download it.
Serving Dynamic Content with HTTP Handlers
Or if you are useing ASP.NET.MVC:
ASP.NET MVC - How do I code for PDF downloads?
This code works today (2022) in IIS 10, Windows Server 2019:
string strFileExePath = ConfigurationManager.AppSettings["Audio:ffmpeg.Directory"].ToString();
string strFileExe = ConfigurationManager.AppSettings["Audio:ffmpeg.Directory"].ToString() + "ffmpeg.exe";
// http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.useshellexecute.aspx
// http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandardoutput.aspx
// Create the ProcessInfo object
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(strFileExe);
psi.UseShellExecute = false;
psi.RedirectStandardOutput = false;
psi.RedirectStandardInput = true; // avoid hang, later close this...
psi.RedirectStandardError = false;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.CreateNoWindow = false; // If the UseShellExecute property is true or the UserName and Password properties are not null, the CreateNoWindow property value is ignored and a new window is created.
psi.ErrorDialog = false;
psi.WorkingDirectory = strFileExePath;
// argumentos
psi.Arguments = $"-y -i \"{fileWithPath}\" -aq 8 -ac 1 -f s16le -ar 8000 -acodec pcm_s16le -vol 500 \"{fileOutputWithPath}\"";
// Start the process
using (Process process = Process.Start(psi))
{
// http://csharptest.net/321/how-to-use-systemdiagnosticsprocess-correctly/
process.StandardInput.Close(); // no wait for input, avoid hang
// process.WaitForExit(); can produce request timeout
}
I want to convert a doc/docx file to postscript by C# without using Word save to file since Word saved a big ps file.
Also, I want to know if there is a way to optimize a PDF by C#.
can I do that?
did you find anyway so you can convert doc/docx to ps?I have the same problem.
I know that it's too late to help you, but you can use ghostscript for optimizing pdf
int ExitCode;
ProcessStartInfo ProcessInfo;
Process Process;
ProcessInfo = new System.Diagnostics.ProcessStartInfo("gswin64.exe", "-dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=C:\\26178DATA\\LowResOutput.pdf -dCompatibilityLevel=1.4 C:\\26178DATA\\Holding.pdf");
ProcessInfo.CreateNoWindow = true;
ProcessInfo.UseShellExecute = true;
ProcessInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
Process = Process.Start(ProcessInfo);
Process.WaitForExit();
ExitCode = Process.ExitCode;
Process.Close();
I am using ProcessStartInfo to print my pdf file in my C# project in background. But the file that I printed is cutting off my top and bottom of the pdf file when printed. But when I print the same file by right clicking the pdf file it prints correctly.
Here is my code:
System.Diagnostics.Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = filename; // use default app to execute verb
//assert: can only go to local default printer
startInfo.Verb = "Print"; //prints to default printer
//try to keep Window hidden - work in background
startInfo.UseShellExecute = true;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.CreateNoWindow = true;
// set process to startInfo and execute start
process.StartInfo = startInfo;
process.Start();
process.WaitForExit(10000);
process.CloseMainWindow();
process.Close();
this is in milliseconds. so it's only going to wait 10 seconds. Is that long enough?
process.WaitForExit(10000);
consider
process.WaitForExit();