在控制台应用程序中调用exe文件

编程入门 行业动态 更新时间:2024-10-16 18:39:46
本文介绍了在控制台应用程序中调用exe文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 我在控制台应用程序中调用Exe文件时遇到问题 这是我的代码部分

Hi all, I have a problem with calling an Exe file in my Console Application Here is my code part

try { System.Diagnostics.Process process1 = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; if (System.Environment.OSVersion.Version.Major >= 6) // Windows Vista or higher { startInfo.Verb = "runas"; } else { /*Do nothing*/ } startInfo.FileName = @"D:\glstats\glstats.exe"; startInfo.UseShellExecute = false; process1.StartInfo = startInfo; process1.Start(); process1.WaitForExit(); } catch (Win32Exception ex) { log.WriteLine("Exec Batch Mode Failed. "); log.WriteLine(ex.ToString()); log.WriteLine("Program Quit: " + DateTime.Now.ToString()); log.Close(); return; }

问题是,进程glstats.exe会立即出现并立即关闭。 有没有办法等到glstats.exe完成用户界面? 软件glstats.exe需要Windows 10中的管理权。 我已经被这两天困住了,今天我试着要求任何帮助,因为我已经完成了谷歌的所有指南但它没有用。 我想感谢你的意见 谢谢。 我尝试过: stackoverflow/questions/2532769/how-to-start-a-process-as-administrator -mode-in-c-sharp 这里是第一条准则,我读过, HT tps://stackoverflow/questions/13807429/running-cmd-commands-with-administrator-rights

推荐答案

对于提升的流程,您还需要UseShellExecute: For an elevated process, you need UseShellExecute as well: string appPath = @"..."; string appArgs = @"..."; Process proc = new Process(); ProcessStartInfo si = new ProcessStartInfo(appPath, appArgs); si.WindowStyle = ProcessWindowStyle.Normal; si.Verb = "runas"; // UAC elevation required. si.UseShellExecute = true; // Required for UAC elevation. proc.StartInfo = si; proc.Start(); proc.WaitForExit();

将出现UAC对话框,用户批准提升,应用程序运行。当它退出时,控制权返回到你的应用程序。

The UAC dialog will appear, the user approves the elevation, the app runs. When it exits, control returns to your app.

亲爱的, 非常感谢你支持我这个问题。 我已经解决了这个问题。 实际上,问题是参数输入。 我纠正了它,现在没关系。 解决方案是, 我必须有这个代码行 Dear all, Thank you so much for supporting me about this question. I resolved the problem already. Actually, the problem is "Argument" Input. I corrected it and now it's OK. the Solution is, I must have this code line string output = p.StandardOutput.ReadToEnd();

否则,glstats.exe将在第二次被杀死。

otherwise, the glstats.exe will be killed in second.

更多推荐

在控制台应用程序中调用exe文件

本文发布于:2023-11-17 08:47:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609511.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制台   应用程序   文件   exe

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!