5391

How to run command in the process which is executed with admin rights?

Question:

I want to create <strong>a self signed certificate</strong> and install it using through c# program. I use <strong>makecert</strong> to make certificate i run it as <strong>administrator</strong> and i pass command in the <strong>ProcessStartInfo.argument</strong> 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() }

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

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?

Answer1:

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";

Answer2:

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

<blockquote>

UserName = "Administrator", Password = ,

</blockquote>

Recommend

  • Start a service from a webapp with administrator privileges passing by a batch file
  • The requested operation requires elevation
  • How To Save Image in My WPF Application
  • Getting the relative path to the rdlc report in my winform app
  • How to ask for Administrator privileges in Windows 7?
  • opening a file in administrator mode from excel VBA in windows 07
  • c# run process on non-admin right
  • Strange file-permissions if apps run as administrator
  • How to Switch User programatically using C#
  • Batch file: run command in a cmd.exe launched as a different user using batch file
  • sweetalert2 inputoptions from file in select example
  • New Firebase failed: First argument must be a valid firebase URL and the path can't contain “.”
  • JSON encode and decode on PHP
  • Building Qt project for C++11 standard
  • List images(01.png) and descriptions(01.txt) from directory
  • Object and struct member access and address offset calculation
  • how to upload multiple files in c# windows application
  • How can I sort a a table with VBA with given text condition?
  • How to install a .deb file on a jailbroken iphone programmatically?
  • Handling un-mapped Rest path
  • How to rebase a series of branches?
  • Spring Data JPA custom method causing PropertyReferenceException
  • C# - Serializing and deserializing static member
  • Sending data from AppleScript to FileMaker records
  • Eraser for UIBezierPath
  • Cannot Parse HTML Data Using Android / JSOUP
  • How to include full .NET prerequisite for Wix Burn installer
  • Suggestions to manage Login/Logout transitions
  • JTable with a ScrollPane misbehaving
  • Understanding cpu registers
  • How do I configure my settings file to work with unit tests?
  • Exception on Android 4.0 `android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)`
  • Is it possible to post an object from jquery to bottle.py?
  • unknown Exception android
  • EntityFramework adding new object to nested object collection
  • Checking variable from a different class in C#
  • reshape alternating columns in less time and using less memory
  • failed to connect to specific WiFi in android programmatically
  • How can I use threading to 'tick' a timer to be accessed by other threads?
  • How do I use LINQ to get all the Items that have a particular SubItem?