如何在以管理员权限执行的进程中运行命令? [英] How to run command in the process which is executed with admin rights?

查看:46
本文介绍了如何在以管理员权限执行的进程中运行命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建自签名证书并通过 c# 程序安装它.我使用 ma​​kecert 制作证书,我以 管理员 身份运行它,并在 ProcessStartInfo.argument 中传递命令,但该命令不执行代码中的问题?

I want to create a self signed certificate and install it using through c# program. I use makecert to make certificate i run it as administrator and i pass command in the ProcessStartInfo.argument but the command doesn't executes what is the problem in the code?

这是我的代码:

 public void Createasnewadmin()
 {

        ProcessStartInfo info = new ProcessStartInfo();

        Process p = new Process();          

        info.FileName = Application.StartupPath+@"\makecert.exe";

        info.UseShellExecute = true;

        info.Verb = "runas"; // Provides Run as Administrator

        info.Arguments = "makecert testCert_admin_check.cer";

        //i just create sample certificate but it doesn't get created
        //The problem is above line the command doesn't get execute 

        p.StartInfo=info;

        p.Start()

  }

请告诉我问题是不是以管理员身份执行?还是要执行的命令没有正确传递?

我认为它是以管理员身份执行的,因为我自己点击是按钮以管理员身份执行,这是由 Windows 提示的

I think it is executing as admin as i myself click on yes button to execute as admin that is prompted by windows

为什么命令没有执行?还有别的办法吗?

Why is command not executing? is there any other way?

推荐答案

查看您的代码,我怀疑您收到了错误,因为您的参数不正确.

Taking a look at your code, I suspect you are getting an error because your arguments are incorrect.

你行

info.Arguments = "makecert testCert_admin_check.cer"; 

应该

info.Arguments = "testCert_admin_check.cer"; 

这篇关于如何在以管理员权限执行的进程中运行命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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