如何使用命令行对象从c#.net windows应用程序中的另一个exe运行一个exe? [英] How to use command line object for run one exe from another exe in c# .net windows application?

查看:117
本文介绍了如何使用命令行对象从c#.net windows应用程序中的另一个exe运行一个exe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



如何在c#.net windows应用程序中使用命令行对象运行两个exe?



我想使用c#.net windows应用程序从另一个exe访问一个exe。

另一个exe不应该手动运行,它应该只运行应用程序exe。







如何通过c#.net保护其他exe或外部exe文件?

外部exe不应该通过用户手动运行。



怎么可能?



请帮助我。



在此先感谢。



Ankit Agarwal

软件工程师。

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.

推荐答案

你可以查看命令行参数!!

默认显示1个参数,即exe名称,你要做的就是传递虚拟参数。从命令行检查params的长度。从命令行开始,如果只有1个param意味着来自clik而且更多来自命令行,那么你可以跳过那个时间!

这是一个棘手的方式我可以建议你





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());
            }
        }
    }


您无法从另一个.EXE检查一个.EXE的命令行参数。 />


您的父.EXE必须在启动它时在第二个.EXE的命令行上传递所需的参数。
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.


我猜你不了解周围的流程和执行,因此你不是那么好的问题。我将尝试总结一下我理解的内容。



您不想在C#应用程序中启动另一个进程/ executabel吗?



解决方案:

看看Process.Start http://msdn.microsoft.com/de-de/library/system.diagnostics.process.start(v = vs.110)的.aspx [ ^ ]

从本质上讲,您可以为此方法提供可执行文件的路径和(如果需要)命令行参数。



你不想阻止其他用户启动该应用程序。



可能(黑客)解决方案。

正如其他人建议的那样(如果您有权访问其他exe代码),您可以检查您将从您的应用程序发送的特定命令行参数(或计数)但我们呃不会只是点击。



其他解决方案。

使用默认操作系统功能(权利/政策)

打包应用程序中的可执行文件(嵌入式资源?),以便它不会显示在应用程序上下文之外的用户系统上。

...



所以也许回答开放式问题(访问其他exe)并尝试使用Process.Start



亲切的问候约翰内斯



(不要误会我的意思,但你对solution1的回答(我的exe不是通过这种方法运行)提示显然缺乏.NET知识 - 如何使用新的WindowsForms项目进行参数行检查和正常样板代码(您已经看过代码,是吗?)启动exe?所以所有好的答案都无法帮助你,如果不能把它放到代码中,没有人可以规避学习一些基础......)
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...)


这篇关于如何使用命令行对象从c#.net windows应用程序中的另一个exe运行一个exe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆