ProcessStartInfo psi = new ProcessStartInfo("java.exe", " -jar \"C:\\craFVUsubsreg-lite_APY.jar\"");
psi.UseShellExecute = false;
Process p = new Process();
p.StartInfo = psi;
p.Start();
I want to invoke the utility tool, which is of java.jar file within the "c#" [mvc] application and it is work fine when i run the application through code. However after i published the application and then i try to invoke the same jar file it is not responding or i can say it is not working.
Above is the process code which i'm using to invoke the jar file. Even the user permission i have setted to full control mode.
Kindly guide me, where i am wrong, or is their any way to directly invoke the java.jar file without converting to java.exe.
Related
is it possible to run a C# project Already build using another project? there is any way to invoke the c# execution using a c# Code.
In here I need to execute the Already Compile Project inside a another project.
You can run an exe using Process.Start
ProcessStartInfo ps = new ProcessStartInfo("YourExecutable.exe", "any arguments");
ps.WindowStyle = ProcessWindowStyle.Hidden; // or exclude this line to show it
ps.CreateNoWindow = true; // and this line
ps.UseShellExecute = false;
Process process = new Process();
process.StartInfo = ps;
process.Start();
There are additional ways to get the output of your process for displaying or logging but that is easily searchable.
I have a program which wraps around some Windows SDK executables and opens them in a separate CMD window.
Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = "/C signtool.exe [args] & pause";
process.StartInfo.Verb = "runas";
process.Start();
Right now, I have the Windows SDK folder added to my system's Path environment variable. Is there a way to programmatically add the Windows SDK folder to the Path environment variable of the user OR run the process with the SDK folder added to the Path variable of that particular CMD window?
This is the folder I need added to each CMD window's Path variable:
C:\Program Files (x86)\Windows Kits\10\bin\10.0.16299.0\x86
This sub-process must run as administrator. It does not need to receive the output of the child process.
Use a ProcessStartInfo and its Environment property instance to set this up.
var startInfo = new ProcessStartInfo();
var defaultPath = startInfo.Environment["PATH"];
var newPath = "C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.16299.0\\x86" + ";" + defaultPath;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/c set > D:\\env.txt";
startInfo.Verb = "runas";
startInfo.Environment["PATH"] = newPath;
startInfo.UseShellExecute = false; // required to use Environment variables
Process.Start(startInfo);
There are a number of hurdles to overcome here.
As you've discovered, the Environment and EnvironmentVariables properties of ProcessStartInfo cannot be used when UseShellExecute is true (an exception is thrown). But Verb only works when UseShellExecute is false (the Verb is silently ignored). This comes down to the differences between CreateProcess (the core Win32 function) and ShellExecute/ShellExecuteEx (the shell function).
As another commenter suggested, you might try setting the environment in the parent process and then starting the child process. However, elevated processes don't inherit the environment from a non-elevated parent process.
I would be willing to bet that there is a way to do what you want using a correct series of Win32 calls to get an elevated token and then calling something like CreateProcessAsUser. I am also willing to bet it'll be a little error-prone and ugly in C# because of the necessary struct marshaling. So instead of trying to figure that out for you, I'll offer another suggestion:
Just programmatically write a batch script that sets the environment and invokes signtool.exe. You can then invoke that batch script using the runas verb as you're currently doing.
how I can open CMD using my IIS Application
var startInfo = new ProcessStartInfo();
startInfo.WorkingDirectory ="c:\\pdftohtml\\";
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "MyText";
Process proc = Process.Start(startInfo);
I believe this code is true but dose not work with IIS for some reason
Thanks in Advance
Opening a command prompt from an IIS application is not a good idea.
If you need to run a tool, maybe it's better to find the API used by the tool and reference it from a service called by the IIS app.
If you need to convert pdf to html, check this link
So here's my end goal. Steam allows you to add other installed games to your library but only if it's a .exe file it's pointed at to start running.
I just installed Arena and Daggerfall and they both run via DOSBox which is launched from a .bat file. So I decided to turn it into a .exe by writing my own. So far I've got the code written. When I just run the .bat file, it opens everything fine, however, when I try running it from my code, the .bat file executes but with errors. Here is my code below:
if (File.Exists("D:\\Bethesda Softworks\\Arena\\Arena (Full Screen).bat"))
{
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("cmd.exe", "/c" + "\"D:\\Bethesda Softworks\\Arena\\Arena (Full Screen).bat\"");
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;
System.Diagnostics.Process proc;
proc = System.Diagnostics.Process.Start(psi);
}
And the error I'm getting is this:
"The system cannot find the path specified. 'dosbox.exe' is not recognized as an internal or external command, operable program or batch file.
I'm not sure if this is an issue because of how dosbox is called from the Batch file or how the .exe ends up running the batch file. Either way, I'd rather fix this in the code rather than by making alterations to the .bat file itself.
Any help is greatly appreciated!!
Try setting ProcessStartInfo.WorkingDirectory
psi.WorkingDirectory = "D:\\Bethesda Softworks\\Arena";
I have create c# dll which is contained in web directory of the product. This dll contain a function which accept some parameters and call a exe (phantomjs.exe) with accepted parameters.I also have write some logging code for file writing in this function. Now I call this dll from asp classic code. Then I found that log maintain by this dll but work of phantomjs.exe does not occur. While when I call this dll from console application then phantomjs.exe works.
I use below code to call the exe
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = false;
p.StartInfo.FileName = pDirectory + "\\res\\bin\\phantomjs.exe";
p.StartInfo.Arguments = arguments;
p.Start();
p.WaitForExit();
Please tell me will there be a need to sign this phantomjs.exe to run in webdirectory or any thing else.