Feroz Khan

Feroz Khan

  • 1.4k
  • 300
  • 93.1k

Run CMD with Admin credential

Aug 6 2023 11:19 AM

Dear All,

I want run cmd with admin credential and admin credintial i want to specifiy in code and i want to run some command in windows but application will be hidden,

and where i am runing that is user standard account do not have admin access so i want to run some cmd code with admin access which i have credential of admin and want to perfom some command (like) Net user admin abc1233; password change or any other commands as per requirement. 

So below is my code and its not working because user do not have admin access to perfom this command.

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "net user admin abc@123456";
startInfo.Verb = "runas";
process.StartInfo = startInfo;
process.Start();


Answers (2)