Click here to Skip to main content
15,918,109 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

How to use command line object for run two exe in c# .net windows application?

I want to access one exe from another exe using c# .net windows application.
another exe should not be run manually, its should be run only application exe.

or

How to protect other exe or external exe through c# .net?
External exe should not be run manually though user.

How could be possible?

Please help me.

Thanks in Advance.

Ankit Agarwal
Software Engineer.
Posted
Updated 30-Jun-14 0:48am
v2
Comments
[no name] 30-Jun-14 6:52am    
You would do this in the exact same way that you have already been told.
[no name] 30-Jun-14 6:55am    
but i have not received correct answer for my question.

you can check command line parameter !!
by default it shows 1 parameter that is exe name what you have to do is pass dummy param. from command line and check the length of params. from command line if only 1 param that means from clik and more thn two is from command line so you can skip that time !
this is tricky way that i can suggest you


<pre lang="c#"><pre> 
   static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            var par = Environment.GetCommandLineArgs();
            if (par.Length > 1)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
        }
    }
 
Share this answer
 
Comments
[no name] 30-Jun-14 7:58am    
My application it's not running by this method.
[no name] 30-Jun-14 8:02am    
My application internal exe it's not running.
You cannot check the command line parameters of one .EXE from another one.

Your "parent" .EXE has to pass the parameters it needs to on the command line of the second .EXE when you launch it.
 
Share this answer
 
Comments
[no name] 30-Jun-14 8:24am    
How can we write code for this?
I'd guess you have a lack of understanding arround processes and execution therefore your not "so good" question. I'll try to summarize what I understand.

You wan't to start another process/executabel from within your C# application?

Solution:
Have a look at Process.Start http://msdn.microsoft.com/de-de/library/system.diagnostics.process.start(v=vs.110).aspx[^]
In essence you give this method the file path of the executable and (if you want) command line arguments.

You want't to hinder other users from starting that application.

Possible (Hack-)Solution.
As others suggested (IF you have access to "other" exe's code) you could implement a check for a specific commandline argument (or Count)you would send from your application but user wouldn't just by "clicking".

Other Solution.
Do it with default OS Features (rights/policies)
"pack" the executable within your application (embedded resource?) so that it doesn't "appear" on the users system outside the context of your application.
...

So maybe answer the open questions (Access to "other" exe) and try to use Process.Start

Kind regards Johannes

(Don't get me wrong, but your answer to "solution1" ("my exe is not running by this method") hints to a clear lack .NET knowledge - how should a argument line check and the "normal" boilerplate code you get with a new WindowsForms-project (you have seen that code, have you?) start an exe? So all good answers won't help you if can't put it to code, nobody can circumvent learning some basics...)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900