Launch .NET application from another folder - c#

Here: Launch C# .Net Application from C++ they say it's possible to launch a .NET application using CreateProcess.
I can't.
Even from the command prompt (Windows 10) I can run my C# application only if I cd to the exe folder.
I've added that folder to the PATH env var, so my C++ application can run it without know where it actually is. But as said it doesn't run.
Trying with the command prompt it just says "This application cannot be started".
Is there something more I have to do?

Related

Console Application, detect launched from an exe file or from terminal

I developed an console application, with the dotnet framework.
I want the application to run when called in a terminal session and when executing the .exe file.
Now I got a problem with the design of my application.
When launching the exe, I need to ask if the program should be terminated, so that the user can read the output of my application (otherwise the application and therefore the terminal would close before any human could read what hs been printed).
But exactly this process of asking before the application stops executing is annoying if the application has been launched from the terminal, let's say by running dotnet myapp.dll.
This is because when launching a terminal session the terminal doesn't close after an application has terminated.
So my question is if there exists any advice/ best practice/ or if there is a way of detecting if the application has been launched via an exe file or in the terminal.
Thanks for your advice.

Run a published console app from win form app

I have a win form application that accept exe file and folder path as argument.
Then a console app is launched. But in my case these console apps are
also published.
When I execute from Debug console app work but when I select
Setup.exe from published app the application installs and then
crash. With argument out of range error.
A related answer can be seen here. But it work with unpublished
exe which I am already doing.
Can I get name of the installed console app something like
"WINWORD.exe" or "Chrome.exe".

Attach to running program with powershell

I have a Raspberry Pi v2 running Windows 10 IoT and am trying to run a dotnet 2.0 console application on it.
I have a powershell script start it on startup, but then I do not get the console output from it. I was wondering if there was a way to attach to the running process with powershell on my computer, like you would to a docker container, to get the console output.
I do not want to run my program on my computer, and the Raspberry Pi is the only computer I want to leave on overnight to run the program.
If you can't or don't want to re-start your Application
You are rather limited in this case, since, as stated in another SE Answer by Harry Johnston:
Windows does not provide any mechanism to retroactively give another
process a standard output handle if it was created without one.
(Besides, in most cases an application will check the standard output
handle only during startup.)
If you need to read something that already has been written to the Console, you are probably out of luck.
You should however be able to get any future output by attaching to the process with debugging tools.
In case of the Visual Studio Remote Debugger, this would even allow you to debug the execution of your Console Application, provided you wrote it.
An accepted answer on Superuser.com suggests that StraceNT is also capable of read the output of a running Console Application. This will probably be your best bet if the running Application wasn't written by yourself.
If the Application can be stopped and restarted
Powershell Remoting is probably the best way.
You would need to enable Powershell Remoting on your Raspberry Pi, and then you can use enter-pssession [RaspberryPi-Hostname-or-IP] in your local Powershell console to connect to your Raspberry Pi.
At that point you can just start your console application as if you were running it on your local machine and get all the console output you want.
No need to attach to anything.
You can redirect the output of your console app to a txt file in the current directory. If you run the console app from powershell you can do it like this:
.\[YOURAPP].exe | tee test.txt
And you can access the test.txt from Windows file sharing.

Launch a WPF application from a batch file or console application

I've made a WPF application based on .NET framework 4.
This application will be copied to a pendrive, and the client will have to run it from there.
In order to check if the client has Framework 4 installed, I've made a batch file that read the output of "clrver.exe", and if the framework 4 is installed it runs the application using the command
START "application path"
The problem is that few seconds after the WPF application is running it crashes.
So I've tried to make a C# Console application, just to check, and using Process.Start() I've started the WPF application. The behaviour is exactly the same.
If I try to run the WPF application by clicking directly on the executable it runs perfectly.
If I try to run it from a console, it crashes after few seconds (5~6 seconds).
Does anyone know the reason or an idea on how to run it?
The problem was dued by the working directory that cause some problem when the application is launched by a console application or a batch file.
I've solved replacing all relative paths in my code with absolute paths retrieved at runtime with: System.AppDomain.CurrentDomain.BaseDirectory

Have activex serve and store executable to a known location

I have a web application that runs internally. I need to run an executable (command line application written in C#) from the browser by passing it 2 parameters.
Infrastructure:
Windows XP - 8
Internet Explorer 6+
C# (.Net 4.0)
The code the launches the executable:
var scanApp = new ActiveXObject("WScript.shell");
scanApp.run("C:\\Path\\To\\exe param1 param2", 1, true);
The above works on my local machine because I have the exe in a known location (on my desktop).
My question is, how best can I deploy this on a client machine through activex and then run the executable?
The workflow would be:
1. Go to webpage
2. Click link that attempts to launch exe
3. Activex 'installs/downloads' the exe to a known location if its not there already
4. Run the exe
TLDR
How to deploy an executable through ActiveX and then launch it whenever user clicks on a webpage button?
Is it necessary that the installation occur through ActiveX? If not and you can deploy a different way (Group Policy, ClickOnce, etc), you can register a protocol handler to accomplish your second goal (similar to how iTunes is registered as a handler for itunes:// links). Just make that part of the install script.
For more information on that topic, see here or here.

Categories

Resources