0

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?

Aamir
  • 14,882
  • 6
  • 45
  • 69
purvang
  • 339
  • 4
  • 6
  • 15
  • 1
    some what similar to http://stackoverflow.com/questions/7610727/to-run-cmd-as-administrator-along-with-command – purvang Oct 01 '11 at 11:45

2 Answers2

1

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"; 
Chris Taylor
  • 52,623
  • 10
  • 78
  • 89
  • Hey thanks it was the problem than it worked now, i want to execute two commands is it Possible if it is then how to do?I tried below method but didnt work info.Arguments = "-n \"CN=My_Root_CA_1_admin_try ,O=Organization,OU=Org Unit,L=San Diego,S=CA,C=US\" -pe -ss my -sr LocalMachine -sky exchange -m 96 -a sha1 -len 2048 -r My_Root_CA_1_admin_try.cer" + "&& certutil.exe -f -addstore Root My_Root_CA_1_admin_try.cer"; I want to run this command to store the certificate in trusted root? – purvang Oct 01 '11 at 12:39
  • Great, glad that sorted you out. I think your next point is probably better suited as another question. But I would probably create a batch file which takes a few arguments and then execute the batch file from the C# code. – Chris Taylor Oct 01 '11 at 12:45
0

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

UserName = "Administrator", Password = ,

Chief
  • 914
  • 1
  • 9
  • 26
  • i did verify it there is no problem in administrator privilege as i did run cmd using the same code and it did run as admin properly but then i could not pass commands to it through my program – purvang Oct 01 '11 at 12:29