i am trying to read output from .exe file of a c++ program and trying to use this output for further use in my asp.net web application but it isn't working
this is what i have done so far
System.Diagnostics.Process MyProcess = new System.Diagnostics.Process();
MyProcess.StartInfo.CreateNoWindow = true;
MyProcess.StartInfo.UseShellExecute = false;
MyProcess.StartInfo.RedirectStandardOutput = true;
MyProcess.StartInfo.WorkingDirectory = "C:\\Users\\Hussain\\Documents";
MyProcess.StartInfo.FileName = "demo.exe";
MyProcess.StartInfo.Arguments = "MyArgument";
MyProcess.Start();
String s = MyProcess.StandardOutput.ReadToEnd();
System.IO.StreamWriter file = new
System.IO.StreamWriter("C:\\Users\\Hussain\\Documents\\123.txt");
file.WriteLine(s);
file.Close();
MyProcess.WaitForExit();
MyProcess.Close();
Related
I run psexec in visual studio but I can not in IIS. I search some days all given solutions is old and there is not usable these days.
my OS is Windows 10 and it is my code:
string psFileName = Server.MapPath(".") + #"\\PSTools\\PsExec.exe";
string computerName = "computerName";
string userName = "DOMAIN\\userName";
string password = "password";
string exePath = "C:\\Program Files\\Mozilla Firefox\\firefox.exe";
string paramters = "\"https://www.google.com\"";
private void RunRemote(string psFileName, string computerName, string userName, string password, string exePath, string paramters)
{
// string path = Application.StartupPath+ #"\PSTools\PsExec.exe";
try
{
Process process = new Process();
ProcessStartInfo psi = new ProcessStartInfo(psFileName);
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.RedirectStandardInput = true;
psi.WindowStyle = ProcessWindowStyle.Minimized;
psi.CreateNoWindow = true;
psi.Domain = "ITCPIDC-CENTER";
psi.UserName = "gholizadeh.al";
SecureString theSecureString = new NetworkCredential("", password).SecurePassword;
psi.Password = theSecureString;
psi.Arguments = $"\\\\{computerName} -d -u {userName} -p {password} \"{exePath}\" {paramters}";
process.StartInfo = psi;
process.Start();
string output = process.StandardOutput.ReadToEnd();
Label1.Text = output;
string errormessage = process.StandardError.ReadToEnd();
Label1.Text = errormessage;
process.WaitForExit();
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}
}
I expected to run firefox by psexec in asp.net web form but just run in visual studio running
I am trying to use ASP.NET in Window Task Scheduler. I want to send the email on specific time.
But ASP.NET is not run as an EXE, it has a dynamic ip address.
I have no idea to use Window Task Scheduler in ASP.NET.
Can you give me any solutions for it?
void SendEmail()
{
//get the data from database
DataTable data = GetData();
DataTable email_data = GetEmailData();
//set DataTable Name of Excel Sheet
data.TableName = "NSOList";
//Create a New Workook
using (XLWorkbook wb = new XLWorkbook())
{
//Add the DataTable as Excel Workhseet
wb.Worksheets.Add(data);
using (MemoryStream memoryStream = new MemoryStream())
{
//Save the Excel Workbook to MemoryStream
wb.SaveAs(memoryStream);
//Convert MemoryStream to Byte array
byte[] bytes = memoryStream.ToArray();
memoryStream.Close();
//body with embedded image
AlternateView body = AlternateView.CreateAlternateViewFromString
("Hi <br><br> <img src=cid:example>", null, "text/html");
//create the LinkedResource (embedded image)
LinkedResource image = new LinkedResource("c:\\example.png");
image.ContentId = "example";
//add the LinkedResource to the appropriate view
body.LinkedResources.Add(image);
String from = "abcd#abcd.net";
//bring Email data
for (int i = 0; i < email_data.Rows.Count; i++)
{
String to = email_data.Rows[i][0].ToString();
using (MailMessage mm = new MailMessage(from, to))
{
SmtpClient smtp = new SmtpClient();
mm.Subject = "List";
mm.AlternateViews.Add(body);
mm.Attachments.Add(new Attachment(new MemoryStream(bytes), "NSOList.xlsx"));
mm.IsBodyHtml = true;
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential();
credentials.UserName = "abcd#gmail.com";
credentials.Password = "abcd";
smtp.UseDefaultCredentials = true;
smtp.Credentials = credentials;
smtp.Port = 587;
smtp.Send(mm);
}
}
}
}
}
You should use a Task Scheduler like Quartz.Net. It allows you to define classes as Jobs, and then execute those jobs according to an schedule. I'm currently using it in some in-house projects and it performs as advertised.
EDITED
Check the answers here.
It should be a console application with your code in it. In bin folder it will create a .exe file which you need to use it in windows task scheduler.
Following link provides you a step by step procedure on how to create a task in windows task scheduler.
http://www.digitalcitizen.life/how-create-task-basic-task-wizard
i try to use wkhtmltopdf.exe from server to convert html file to pdf then when process is done. application must to create file pdf . How can i do ? Please help.
this is code
string myDocumentsPath = "c:\\wkhtmltopdf.exe ";
ProcessStartInfo psi = new ProcessStartInfo(myDocumentsPath, " http://www.website.com/page");
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.RedirectStandardError = true;
psi.CreateNoWindow = true;
Process myProcess = Process.Start(psi);
myProcess.WaitForExit();
myProcess.Close();
I have a little asp.net program that in this program i could write and run commands of command prompt in my asp.net application An important part of this story is to run exe files with commands.
It is my code but dont run exe file for example where i write mspaint it dont open:
<pre lang="c#">
try
{
Process p = new Process();
p.StartInfo.CreateNoWindow = false;
p.StartInfo.FileName = c_path.Value = Encoding.Default.GetString(Convert.FromBase64String(c_path.Value));
c_text.Value = Encoding.Default.GetString(Convert.FromBase64String(c_text.Value));
p.StartInfo.Arguments = c_text.Value;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.Start();
string[] Uoc = new string[20];
for (int i = 1; Uoc.Length > i; i++)
{
Uoc[i] = p.StandardOutput.ReadLine();
Uoc[i] = Uoc[i].Replace("<", "<");
Uoc[i] = Uoc[i].Replace(">", ">");
Uoc[i] = Uoc[i].Replace("\r\n", "<br>");
}
string txt = "";
foreach (var item in Uoc)
{
txt += item + "<br />";
}
cmd_response.InnerHtml = "<hr width=\"100%\" noshade/><pre>" + txt + "";
cmd_response.Visible = true;
more.Visible = true;
}
catch (Exception error)
{
xseuB(error.Message);
}
</pre>
If you look at Task Manager and have it show processes for all users, you will see that the programs do run, but they are running under a different session. As a security precaution, the sessions are independent of each other. Programs in one session can not be interacted with by other sessions.
I try to call console appliction from asp.net when i put breakpoint in console app why it can't stop there.How can i call console application?
var proc = Process.Start("D:\\Edefter\\EFaturaConsoleTxtParser\\bin\\Debug\\EFaturaConsoleTxtParser.exe", "/arg1 /arg2");
proc.WaitForExit();
I'm not sure about this but anyway you can try
ProcessStartInfo startinfo = new ProcessStartInfo();
startinfo.FileName =#"D:\\Edefter\\EFaturaConsoleTxtParser\\bin\\Debug\\EFaturaConsoleTxtParser.exe";
startinfo.CreateNoWindow = true;
startinfo.UseShellExecute = true;
Process myProcess = Process.Start(startinfo);
myProcess.Start();
While starting a process programmatically, the 'UserShellExcute' property must be 'false'. Otherwise, the CreateNoWindow property value gets ignored and new window is created.
Example:
ProcessStartInfo startinfo = new ProcessStartInfo();
startinfo.FileName = #"demoApplication.exe";
startinfo.Arguments = "arg1 arg2";
startinfo.CreateNoWindow = true;
startinfo.UseShellExecute = false;
Process myProcess = Process.Start(startinfo);
Source: http://msdn.microsoft.com