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();
Related
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();
}
I can use process start and run a standard vbscript without its .vbs extension (see my code below) but how do you run a vbscript file that has been encoded using the VBScript Encoder object without the .vbe extension?
Process process = new Process();
process.StartInfo.FileName = #"wscript.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.Arguments = "//e:vbscript noExtensionFile";
process.Start();
If you're trying to run an encoded VBScript file, you want the VBScript.Encode engine rather than the VBScript engine. Try using //e:VBScript.Encode as your first argument to wscript.
Assuming your problem is with the file not having an extension and you can rename it you could do something like:
string filename = ....
if (!Path.HasExtension(filename))
{
string t = Path.ChangeExtension(filename, ".vbe");
File.Move(filename, t);
filename = t;
}
// rest of your code
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
So I have code to open a pdf programmatically. the code opens adobe reader just fine, but I get a dialog that pops up that says the file doesn't exsit. The problem is though that I can browse to the exact path that is being used to try and open the pdf in a windows explore, plus there is an if statement for if the file exists. So why isn't adobe opening the pdf?
the path for the Adobe .exe on the proc.StartInfo.FileName is correct.
I found this link: https://visibleprocrastinations.wordpress.com/2009/08/20/there-was-an-error-opening-this-document-file-cannot-be-found-acrobat-reader/ but I don't know if it still applies
PDF file path:
C:\Users\Printer\SharePoint\Partners - Doc\McG\Labels\TR109897\eLabels_TR109897.pdf
Heres the code I'm using:
Process proc = new Process();
FileInfo file = new FileInfo(filepath);
if (file.Exists)
{
//Define Location of adobe reader/command line
proc.StartInfo.FileName = #"C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe";
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.Arguments = string.Format(#"{0}", file.FullName);
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
if (proc.HasExited == false)
proc.WaitForExit(10000);
proc.Close();
return true;
}
It sounds like the shell is parsing up your filename in an unintended way. Try wrapping your filename in quotes:
proc.StartInfo.Arguments = string.Format("\"{0}\"", file.FullName);
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();