开发者

How to check Condition for executing Application through Shell propmt using C#

开发者 https://www.devze.com 2023-03-31 12:01 出处:网络
I have an application that can be run using GUI and Non-GUI environment. In order to execute with non-GUI envi开发者_运维问答ronment I need to check condition for \"Executing the Application using She

I have an application that can be run using GUI and Non-GUI environment. In order to execute with non-GUI envi开发者_运维问答ronment I need to check condition for "Executing the Application using Shellprompt"(so that GUI should not pop up). I need to check the condition for executing if the application is using shellprompt. How can I specify or check the above condition? Thanks in advance.

Regards,

Arasu.


Hi usually we pass some command line parameters to enable "batch mode" of the application when we run it from the console, also because the normal use case is to have it running via Windows Scheduled task.

Said so, inside the main method you can check the command line parameters and in case your keyword (aka "batch") was specified instead of loading the main form you run your UI less procedures.


so if I understand correctly you are currently able to specify the app should start up on command prompt from a setting in the UI, but you want to be able to specify it should start up on command prompt from the command prompt? you can use the args in the main method of your app for that, just as you would pass args to a comon command line app. like so (from Program.cs):

namespace WindowsFormsApplication1
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            if (args != null && args.Contains("-nogui"))
            {
                // start command shell app version
            }
            else
            {
                // start UI app version
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
        }
    }
}

I may have misread your question so if my answer is not of help to you.. maybe you'll find this answer helpful instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号