How to make an installable .Net console app [duplicate] - c#

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.

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 detect a running MSI Installation [duplicate]

This question already has answers here:
How do I test if another installation is already in progress?
(3 answers)
Closed 7 years ago.
I'm looking for a way to detect if a Windows Installer installation is already in progress. What I've found out so far is:
Checking the Registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\InProgress
Using the Windows Installer API function MSIInstallProduct with a dummy file which then would return the specific error code.
Does anybody know a smarter solution?
Same as this:
check for windows installer mutex availability
and this:
http://blogs.msdn.com/b/heaths/archive/2006/01/23/516454.aspx
Question 1:
http://blogs.msdn.com/b/windows_installer_team/archive/2005/11/09/487559.aspx

How can I launch a Windows application ONLY from another application? [duplicate]

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.

C# launch power options [duplicate]

This question already has answers here:
How can run functions of powercfg by C# code?
(3 answers)
Closed 9 years ago.
From my C# program I want to open the power options from the control panel in Windows.
However I can't seem to find out how to do that, I tried making a shortcut and see where it goes but it is referring to the control panel.
Does anyone have an idea how to do that or where the exe is located to launch?
Try the following:
System.Diagnostics.Process.Start("powercfg.cpl");

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.

Categories