How to enter text into CMD windows? [duplicate] - c#

This question already has answers here:
Run interactive command line exe using c#
(3 answers)
Closed 6 years ago.
I can't seem to find a possible solution for entering 1 line of "command" into a CMD window. I searched the MSDN and asked google and they only found me solutions to enter text into a textfile, but that's not the same I guess.
Thank you in advance!

You're going to have to start the Minecraft service process from your .NET application. Whatever you've got now in the batch file you're using, you can duplicate that in the Process start code in C#, or you can just have your C# code run the batch file.
If you want a config file providing startup parameters, you could put that stuff in app.config and have your application give them to the Minecraft server process on startup.
Once you've got the process started, your application can keep the Process object and send repeated commands to its standard input stream, as outlined in this answer.

System.Diagnostics.Process.Start("CMD.exe", [your command]);

Related

How do I run one program from another in c#? [duplicate]

This question already has answers here:
How do I start a process from C#?
(13 answers)
Closed 2 years ago.
So for example, I have a few apps that I want the user to be able to use within one central app, so that means I need to run the app and give it the data it needs, so that it can return things to the central app.
How could I go about running the seperate apps from one c# app, and how would I be able to run it as long as they are in the same folder, no matter where that folder is.
Thanks in advance
PS: I know i could just code in the functions of the apps into one app, but what if I needed to connect my c# app with a python or java app?
Reputation is not high enough to comment, so here are my 2 cents.
This code gives you your main-exe-location, from there append your other executables names and use process.start or the other solutions as suggested.
using System.IO;
using System.Reflection;
string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string path = Path.Combine(directory, "your.exe");

How to get a WPF app to open another app if it exists [duplicate]

This question already has answers here:
Check if an executable exists in the Windows path
(8 answers)
Closed 3 years ago.
I am working on a WPF app, and I would like to include a button that directs it to another app. I would like it to have the following functionality:
If the app is installed on the user's computer, it opens the app for them.
If the app is not yet installed, it sends them to a link where they can download the app.
I know I will need to use Process.Start to open the app, but I am stuck on how to check if the app exists. If anyone could point me in the right direction it would be appreciated!
Two things you can use:
File.Exists(string) - Checks if the file exists.
try-catch - Simply try to open it, and handle any exceptions.
I would probably opt for the first solution...

How I can play audio in C# console application? [duplicate]

This question already has answers here:
How to play a sound in C#, .NET
(7 answers)
Closed 3 years ago.
I would like to know if it possible just play some kind of audio file in C# Console Application.
I don't find any answer on this question.
Many Thanks
In command prompt you can play an audio file by typing it's name from location folder:
c:\my_Music>track1.mp3
This opens the file with the format's associated progam so there will be a pop-up of an external program. Set program by using right-click on a file and choose "Open With".
I've not tested this in a console app. But you should be able to type a String into the console app and then trigger an ENTER press event.
Option 2:
Use SoundPlayer class.
A good tutorial for beginners. Also can check this: Playing sounds on Console.

Replace exe file when application is running [duplicate]

This question already has answers here:
Auto-update library for .NET? [closed]
(12 answers)
Closed 9 years ago.
I have simple question - is it possible, to replace *.exe file (application file), when it's running? I mean i know that i cannot do that when app is running, but maybe it's possible to do something like:
do application.shutdown()
replace oldExe -> newExe
application.restart().
Create a helper application. You will run this "helper" application when you need it, and it can monitor/replace the main application when it has been closed. Once replaced, the helper application can launch your main application again.
You can also run command line arguments to your helper app, telling it what you need it to do.

Capturing user ran programs [duplicate]

This question already has an answer here:
How to detect a process start & end using c# in windows?
(1 answer)
Closed 8 years ago.
I am looking for a way to record when certain programs have been executed.
For instance, if Microsoft Word has been started I would like to write out a time and date stamp along with the program name.
The output I get. I may change it to an Excel spreadsheet. Just need a little guidance on where to look to capture user run programs.
It looks like you want to use the ManagementEventWatcher
example
msdn
As for creating an excel spreadsheet from data, you can easily find code for that.
like this

Categories