使用“runas”的C#execute cmd命令争论 [英] C# execute cmd command with "runas" argument

查看:95
本文介绍了使用“runas”的C#execute cmd命令争论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。如何通过代码执行runascmd命令。

事情是我的所有命令都运行正常,但是带有runas的命令会出错。我必须在远程PC上以域管理员身份执行命令。即使打开cmd提示输入密码也应该可以正常工作。感谢您的帮助

Hello. How can i execute a "runas" cmd command through code.
The thing is all my commands work fine, but the one with runas gives error. I have to execute the command as Domain Aministrator on a remote pc. It should work fine even to open cmd prompt for inserting the password. Thanks for the help

推荐答案

请在下面找到代码。



Please find code below.

ProcessStartInfo procStartInfo = new ProcessStartInfo()
   {
       RedirectStandardError = true,
       RedirectStandardOutput = true,
       UseShellExecute = false,
       CreateNoWindow = true,
       FileName = "ABC.exe",
       Arguments = "/user:Administrator \"cmd /K " + command + "\""
   };


试试这个



Try this

Process p = new Process();
           ProcessStartInfo startInfo = new ProcessStartInfo("CMD");
           startInfo.Verb = "runas";
           p.StartInfo = startInfo;
           p.Start();


这篇关于使用“runas”的C#execute cmd命令争论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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