Get data from EXE [closed] - c#

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have requirement, where I need to call application or EXE, whatever output of that application will be, I need to get that data in my application/code.
Just say I have an application or EXE which gets detail of computer like PC name, IP address, MAC address etc etc. My code/application shoud automaticaly trigger this EXE and get all PC data in my applicaion/code.
But above all is it realy possile??

But above all is it realy possile??
Yes.

Yes. You can start the process, redirect its output and parse it.
var proc = new Process {
StartInfo = new ProcessStartInfo {
FileName = "program.exe",
Arguments = "command line arguments to your executable",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
proc.Start();
while (!proc.StandardOutput.EndOfStream) {
string line = proc.StandardOutput.ReadLine();
// parse the line
}

Try having a look at Process.Start and Process.StartInfo

Related

Playing Audio Files with spaces in filename [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
is there any possibility to play audio-files with spaces in their names?
For instance: Calvin Harris - Summer.mp3
I want to open that file in the Windows Media Player/VLC Media Player and then the error log in the VLC shows: "Bad File descriptor in C:\..Project\Release\Calvin"
Problem: The spaces!
CalvinHarris-Summer.mp3 can be opened without problems.
How could I solve that problem without renaming the audiofiles?
I'm starting the audiofile and the player with a Process.Start
If you pass the file name as an argument to the process with quotes around it, this should work for both VLC/WMP when there are blanks in the file name.
For example.
string fileIn = #"c:\Wherever\Calvin Harris - Summer.mp3";
ProcessStartInfo processStartInfo = new ProcessStartInfo()
{
Arguments = String.Format("\"{0}\"", fileIn),
FileName = VLC_EXE_PATH
};
Process.Start(processStartInfo);

Read text from console C# [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a question that i could not find on the internet.
For i friend of mine i am making a application that wil work after a command. Pretty easy but here comes the tricky part. That command is given in a other console. So what i am trying to do is read the lines from the other console and that should trigger an action in mine to write to the other console.
Like i said i've tried to find something on the internet that can help me but i could not find anything.
Is this possible and if it is possible how can i accomplish this?
Thanks in advance
EDIT
The other console is an gameserver that is started with an batch file
I could trigger the gameserver from my own application, but it will take over the program so how can i make it that it triggers in my program and then read the lines from the program
Since you want to control the input of the gameserver, you should start the gameserver from your application, so that you get control over the standard input of the gameserver.
Then you read all the lines from standard input, and check them before writing them to the gameserver's standard input. That way you can also write extra lines to the gameserver's standard input.
Code from http://social.msdn.microsoft.com/forums/vstudio/en-US/46c91711-755f-48fa-a4a8-92956082218f/howto-launch-process-and-write-to-its-stdin:
using System.Diagnostics;
...
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.UseShellExecute = false; //required to redirect standart input/output
// redirects on your choice
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.FileName = ...app path to execute...;
startInfo.Arguments = ...argumetns if required...;
Process process = new Process();
process.StartInfo = startInfo;
process.Start();
process.StandardInput.WriteLine(...write whatever you want...);

How do I keep a process open? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a web application in ASP.Net/C# (using MVS), and I want to be able to launch some programs on the client side (this should be safe since it's only for intranet use), and keep these programs open in order to give them some command inputs through the web app.
For example, I would like to open "cmd.exe" client-side, and then being able to send multiple commands one after another (synchronized with some buttons of my web form) to the process.
How can I do this? I've read a lot about using a block of Javascript with an ActiveX object, or in C# with System.Diagnostics.Process, but I'm quite stuck on how to proceed.
function RunEXE()
{
var oShell = new ActiveXObject("WScript.Shell");
var prog = "c:\\WINDOWS\\system32\\notepad.exe";
oShell.Run('"'+prog+'"',1);
}
You could also have a look at custom protocol handlers, that's what e.g. Steam uses. You'd simply have a link like myprotocol://dosomething/whatever and it will launch your client-side application with the given URL.
It's basically just about writing a registry key: http://msdn.microsoft.com/en-us/library/ie/aa767914(v=vs.85).aspx
For example, to register a protocol named alert, you can do this:
HKEY_CLASSES_ROOT
alert
(Default) = "URL:Alert Protocol"
URL Protocol = ""
DefaultIcon
(Default) = "alert.exe,1"
shell
open
command
(Default) = "C:\Program Files\Alert\alert.exe" "%1"
This will cause the application in command to be launched when you navigate to an url that starts with alert://.
Using c#
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "CMD.EXE";
startInfo.Arguments = "list of args";
Process.Start(startInfo);
Now after that you can keep checking weather the is open or not by
Process[] processes = Process.GetProcesses();
or
Process[] chromes = Process.GetProcessesByName("chrome");
Check if you process is open or not then pass args to it

Using System.Diagnostic.Process.Start and assigning parameters in outside .exe file [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I'm relatively new at C# development and I'm trying to figure out how I can use an outside application to accept parameters set in my VS (2008) project. The idea is to have the outside application accept coordinates to rotate the screen. So have it rotate to 90 degrees, 180 degrees, and 270 degrees. So I have two buttons. One to send the command to rotate and the other to reset the values. I was thinking it would be easier to just use a list box and have the three options and use a switch statement to execute each option. The only thing I'm unsure of is how to have System.Diagnostic.Process.Start execute the rotate.exe and pass the parameters I'm setting for each rotate option. Any ideas?... I couldn't find anything that covered this exactly, but if you find anything of reference that may be helpful, please let me know! Thanks!
Process.Start can start with arguments.
Sample
Process.Start("rotate.exe", "90");
http://msdn.microsoft.com/en-us/library/h6ak8zt5(v=vs.110).aspx
Or use ProcessStartInfo.
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "rotate.exe";
startInfo.Arguments = "90";
Process.Start(startInfo);
See: http://msdn.microsoft.com/en-us/library/vstudio/system.diagnostics.processstartinfo
You should take a look at what options Process class offers. Take a look at [a this] (http://www.dotnetperls.com/process).
static void OpenMicrosoftWord(string f)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "WINWORD.EXE";
startInfo.Arguments = f;
Process.Start(startInfo);
}

C# - Launch a process in a different directory of the executable [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I need to launch a process that is for example in this path:
c:\A\ApplicationToBeLaunched.exe
I want that this process runs in a different path of their executable. This other folder will have all the configuration files of the ApplicationToBeLaunched.exe application. For example, the path could be:
c:\B\
I am trying to do this with this c# code:
System.Diagnostics.Process prProcess = new System.Diagnostics.Process();
prProcess.StartInfo.FileName = "c:\\A\\ApplicationToBeLaunched.exe";
prProcess.StartInfo.UserName = "";
prProcess.StartInfo.UseShellExecute = false;
prProcess.StartInfo.WorkingDirectory = "c:\\B\\";
prProcess.Start();
But the process always is executed in the application directory (c:\A\). I also have tried to set the property UseShellExecute to true.
What am I doing wrong? Can any help me?
Editing:
After some tests, I have checked that the issue is in the application launched. The process with the working directory is working fine.
i did a little test, created a small program with this in the Main method:
System.Diagnostics.Process prProcess = new System.Diagnostics.Process();
prProcess.StartInfo.FileName = #"C:\src\Test\ObjectTest\ObjectTest\bin\Release\ObjectTest.exe";
prProcess.StartInfo.UserName = "";
prProcess.StartInfo.UseShellExecute = false;
prProcess.StartInfo.WorkingDirectory = #"c:\temp\";
prProcess.Start();
And in the ObjectTest.exe
Console.WriteLine(Directory.GetCurrentDirectory());
And the output result:
c:\temp\
So i think your having some other problem with your program and not problem with the WorkingDirectory.
I don't know why WorkingDirectory is not working but I have encounter this by myself in the past.
Try to change the current working directory before starting the new process:
Directory.SetCurrentDirectory("c:\\B\\");

Categories