如何使用C#将参数从一个exe传递给另一个exe [英] How to pass arguments form one exe to another exe using C#

查看:349
本文介绍了如何使用C#将参数从一个exe传递给另一个exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个不同的exe文件。

如果我从一个exe中单击一个按钮,文本框中的值(比如3个文本框)应该传递给另一个exe,这样我就可以在第二个exe文件。



我尝试了一些代码并获得了拒绝例外。



任何人都可以帮我摆脱这个问题。





例外:访问被拒绝



EXE 1

I am having two different exe files.
If I click a button from one exe the values in the textboxes(say 3 textboxes) should passes to another exe so that I may use it in the second exe file.

I have tried some codes and got Access is Denied Exception.

Can anyone help me to get rid of this problem.


Exception: ACCESS IS DENIED

EXE 1

 Application.EnableVisualStyles();
            
Application.SetCompatibleTextRenderingDefault(false);

Global.Passingvalues =  OrderXML + "," + Global.CurrentView+ "," + strOrderId;

System.Diagnostics.Process startApp = new Process();

System.Diagnostics.ProcessStartInfo psiview;

psiview = new System.Diagnostics.ProcessStartInfo(orderPath, Global.Passingvalues);
                        
startApp = System.Diagnostics.Process.Start(psiview);
                        
startApp.WaitForExit();





EXE 2

 static void Main(String[] arg)
{ 
 Application.EnableVisualStyles();
            
 Application.SetCompatibleTextRenderingDefault(false);

 frmSplashW frmSpl = new frmSplashW();                  

 Application.DoEvents();

 string[] passedString = new string[3];

 passedString = arg[0].Split(',');

 orderXML = passedString[0];//"";// arg[0];
                    
 currentView =passedString[1] ;//"";//arg[1];
                    
 orderID = passedString[2];//"";//arg[2];                

 frmSpl.LoadInitRMSBusiness(orderXML,currentView,orderID);
                    
 Application.Run();
}

推荐答案

传递参数的方式很奇怪。通常使用空格来分隔它们,并且每个空间都被放入arg数组的不同元素中。如果你提供的任何东西都有空格,你会得到一些非常奇怪的结果。



BTW双引用任何有空格的东西。



就访问被拒绝而言,不太可能与命令行有关。如果您没有权限执行某些操作,则会获得拒绝访问权限。第二个进程将是第一个进程的子进程,因此它将继承其安全性令牌。运行第一个帐户的帐户是否有权运行第二个?
The way you are passing your parameters is odd. Normally a space is used to separate them and each gets put into a different element of the arg array. If any of the things you are supplying has a space in it, you'll get some very weird results.

BTW double-quote anything with a space in it.

As far as the access denied is concerned, unlikely to be to do with the command line. Access is denied is what you get when you don't have permission to do something. The second process will be a child of the first, as such it will inherit its security token. Does the account the first thing running under have access to run the second?


这篇关于如何使用C#将参数从一个exe传递给另一个exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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