I am going to install the my project silently using the following options from the C#.
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = true;
startInfo.FileName = tempPath + "myproject.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = "/s /v/qn";
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
exitcode = exeProcess.ExitCode;
}
It installs my projects sucessfully.but I need to Launch the installed application after the installation. How I can Do this? Is there any Additional arguments I need to pass to Launch the product after the installation?
Thanks in Advance,
Roshil
Related
I am trying to run an exe file in my console application which is located on a network drive.
So what needs to happen is the app needs to map the network drive with a drive letter by using this code:
private static void MapDrive()
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "net.exe";
startInfo.Arguments = #"use w: \\<server>\CompanyData\W10 /user:Administrator Password";
process.StartInfo = startInfo;
process.Start();
}
This works great and the drive letter is mapped.
Now the problem I am facing is to run the exe file with in this mapped drive.
I have tried the below but does not seem to work:
private static void RunSetup()
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = #"w:\setup.exe";
process.StartInfo = startInfo;
process.Start();;
}
Nothing seems to happen in regards to launching the exe file.
I need to know what I am doing wrong here?
Thanks
Either include the "/c" argument
startInfo.FileName = "cmd.exe";
startInfo.Arguments = #"/c w:\setup.exe";
or set FileName directly to the setup.exe
startInfo.FileName = "w:\setup.exe";
as mentioned in the comments
I am using graphicmagic exe to execute a command using command prompt. I have added the graphicmagic exe in my application root folder. I want to execute this exe and pass the arguments through c#. How to do this? I have tried the below code:
Method: 1
Process proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = AppDomain.CurrentDomain.BaseDirectory + "\\gm1.3.5\\gm",
Arguments = "convert -define dpx:colorspace=rgb -define tiff:bits-per-sample=16 'D:\\Image\\FFv1\\dpx1\\1.dpx' 'D:\\Image\\FFv1\\tiff1\\1.tiff'",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
}
Method: 2
Process proc = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = #"D:\Executable\Projects\MMF\gm1.3.5\gm";
startInfo.Arguments = "convert -define dpx:colorspace=rgb -define tiff:bits-per-sample=16 \"D:\\Image\\FFv1\\dpx1\\1.dpx\" \"D:\\Image\\FFv1\\tiff1\\1.tiff\"";
proc.StartInfo = startInfo;
proc.Start();
But both of its not working. Please suggest a way to execute exe file and pass commands.
It should be the privilege issue.
Try to adjust the identity in your app pool to LocalSystem.
This one is working fine:
using System.Diagnostics;
Process p = new Process();
p.StartInfo.FileName = #"D:\Executable\Projects\MMF\gm1.3.5\gm.exe";
p.StartInfo.Arguments = "convert -define dpx:colorspace=rgb -define tiff:bits-per-sample=16 \"C:\\Documents and Settings\\software\\Desktop\\DPX_Test\\3.dpx\" \"C:\\TEMP_21May2015103216\\3.tiff\"";
p.Start();
p.WaitForExit();
I'm trying to run some Git commands from a C# program using System.Diagnostics.Process and it's not working. Git is in my path and when I try to run the command at the command prompt it works fine. I've tried capturing the standard output using a nested using() statement and that's not helping. When it gets to the reader.ReadToEnd() it just shows the DOS window hung with nothing in it. Here's my code:
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.UseShellExecute = false;
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
startInfo.WorkingDirectory = "c:\\gitmover";
startInfo.FileName = "cmd.exe";
startInfo.Arguments = " git add \"*.*\"";
using (Process process = Process.Start(startInfo))
{
using (StreamReader reader = process3.StandardOutput)
{
string result = reader.ReadToEnd();
}
}
Any ideas what I could be doing wrong?
When I run the package in Visual Studio the files print. When I deploy it and run it as a SQL Server job the files do not print. Any ideas? The package RUN AS is a domain admin account.
Here is the code.
ProcessStartInfo info = new ProcessStartInfo();
info.Verb = "PrintTo";
info.Arguments = "\"printername\"";
info.FileName = path;
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
Process p = new Process();
p.StartInfo = info;
p.Start();
p.WaitForInputIdle();
System.Threading.Thread.Sleep(3000);
if (false == p.HasExited)
p.Kill();
I am trying to execute commands on Mingw from other process with this code:
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = #"PATH-TO-MINGW\mingwenv.cmd";
startInfo.UseShellExecute = false;
startInfo.RedirectStandardInput = true;
using (Process exeProcess = Process.Start(startInfo))
{
StreamWriter str = exeProcess.StandardInput;
str.WriteLine("ls");
exeProcess.WaitForExit();
}
but this code just lunches Mingw and does not input command.
Do I miss something or it is not possible to do?
Thanks
Update
Based on Jason Huntleys answer, solution for me looks like this (I am using OMNeT++ simulator so directories are based on it)
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = #"PATH_TO_SIMULATOR\omnetpp-4.3\msys\bin\sh.exe";
startInfo.UseShellExecute = false;
startInfo.RedirectStandardInput = true;
using (Process exeProcess = Process.Start(startInfo))
{
using (StreamWriter str = exeProcess.StandardInput)
{
str.WriteLine("cd PATH_TO_SIMULATOR/omnetpp-4.3");
str.Flush();
str.WriteLine("ls");
str.Flush();
}
exeProcess.WaitForExit();
}
I suspect c# is launching your mingw command in a CMD prompt. You need to spawn your process within a bash shell. Try wrapping your command with "bash -l -c 'ls'" or "bash -c 'ls'". Make sure bash is in your PATH, and be sure you quote command arguments, if any. I've had to use this method when I spawn bash commands from popen in python. I know diff language, but could be related.
I imagine the code will look similar to this. I haven't tested in C#:
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "bash.exe";
startInfo.Arguments = "-l -c 'ls -l /your/msys/path'";
# Or other examples with windows path:
# startInfo.Arguments = "-l -c 'ls -l /c/your/path'";
# startInfo.Arguments = "-l -c 'ls -l C:/your/path'";
# startInfo.Arguments = "-l -c 'ls -l C:\\your\\path'";
process.StartInfo = startInfo;
process.Start();
you should do
str.Flush();
so the command you've writen is passed to the process.
also you should use using statement when dealing with streams
using (Process exeProcess = Process.Start(startInfo))
{
using(StreamWriter str = exeProcess.StandardInput)
{
str.WriteLine("ls");
str.Flush();
exeProcess.WaitForExit();
}
}