简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM