Sunday, April 6, 2014

Execute Server Process from Server Side Code

Sometimes when dealing with certain scenarios, there comes the question, whether a server side process execution could be initiated through server side code. This could be done. In fact this could be done in SharePoint. The code needs to be run withing elevated privileges.



Process proc = new Process();
proc.StartInfo.FileName = string.Concat(ConfigurationManager.AppSettings["Get The File Path"].ToString(), "MYExecutable.exe");
 proc.StartInfo.Arguments = "\"" + ConfigurationManager.AppSettings["argumentOne"].ToString() + file.Name + "\"" + " -o \"" + ConfigurationManager.AppSettings["argumentTwo"].ToString() + myFile + "\"";

proc.StartInfo.UseShellExecute = false;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.RedirectStandardOutput = true;

proc.Start();
proc.WaitForExit();


No comments:

Post a Comment