How to run command in the process which is execute

2019-08-28 01:33发布

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?

Here is my 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()

  }

Please Tell me where is the problem is it not executing as administrator? or the command to be executed is not passed properly?

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?

2条回答
SAY GOODBYE
2楼-- · 2019-08-28 02:23

I believe you need to supply credentials to invoke process in admin mode.

UserName = "Administrator", Password = ,

查看更多
劳资没心,怎么记你
3楼-- · 2019-08-28 02:24

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

You line

info.Arguments = "makecert testCert_admin_check.cer"; 

should be

info.Arguments = "testCert_admin_check.cer"; 
查看更多
登录 后发表回答