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");
Related
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...
This question already has answers here:
C# set environment variable
(2 answers)
Ways to deploying console applications in C#
(5 answers)
Closed 4 years ago.
How can I make my console app installable so that when I open CMD I can run it from anywhere with a keyword. Like when I type in git in cmd for example. Thanks.
For this, you need to set up an environment variable called PATH. In Windows, it is in the registry. But for Mac or Linux you may want to update the .bash_profile file.
You can use the following function
SetEnvironmentVariable(String, String)
Here is the link for the MSDN .net core API
Then again I haven't tried this before. But hope this helps you out.
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]);
This question already has answers here:
C# : Making an exe to not run directly
(4 answers)
Closed 7 years ago.
I want to have a WPF C# program launch a second WPF C# program, and prevent this second program from being launched any other way. Any ideas?
You could pass the 1st application's Process Id as a parameter, and have the 2nd application look up and validate the calling process.
Compile the second program as a dll, make the entry point internal, and have both applicatios share namespaces. Depending on your level of security, you might want to implement some handshake protocol between both applications.
This question already has answers here:
Notification when a file changes?
(3 answers)
Closed 8 years ago.
I have inherited application that, among many other things, has to watch if user writes/deletes text file into specific folder.
Currently, the application uses timer and polls after 5 seconds. I find this ineffective, and wish to improve this part of code.
My question is about existence of the .NET function that monitors changes in directory. Is there such function I can use to detect when a file is written/deleted in a specified folder?
Thank you.
Yes, you have the FileSystemWatcher class. It does exactly what you're looking for
Yes there is. I would suggest you take a look at the FileSystemWatcher class:
http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher%28v=vs.110%29.aspx
It's quite easy to set up, and it monitors for Win32 events, so is relatively inexpensive to use.