0

Would somebody be able to tell me if what I'm attempting is possible??

My Issue is on Windows 10 (on windows 7 the below works)

I'd like to programatically create a an instance of "CMD.exe" launched in Administration mode whereby I specify the details of the admin user when creating the CMD process.

My end result is always the same:

  1. I can create the CMD.exe process
  2. The owner of the process is the administrator account I created it under (i can see this via task manager)

but the CMD.exe doesn't launch in administration mode (and that's my problem)

Here's my code — any help is greatly appreciated (I've spent far too long looking at this"). Any other articles I've read indicate how to create the process as an administrator but not to run it in Admin mode on Windows 10)

ProcessStartInfo p = new ProcessStartInfo();

p.WorkingDirectory = @"C:\Windows\System32";
p.FileName = @"C:\Windows\System32\cmd.exe";

p.UserName = "myUser";
p.Domain = "myDomain";

char[] password = { 'm', 'y', 'p', 'a', 's', 's'};

SecureString adminpassword = new SecureString();
foreach (char c in password)
  {
      adminpassword.AppendChar(c);
  }

p.Password = adminpassword;
p.UseShellExecute = false;
p.Verb = "runas";
Process.Start(p);
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
P_Fitz
  • 819
  • 9
  • 16
  • You could try [my small little impersonator class](https://www.codeproject.com/Articles/10090/A-small-C-Class-for-impersonating-a-User). – Uwe Keim Dec 23 '16 at 15:54
  • You have to use `LOGON32_LOGON_BATCH` to create an elevated token. Doesn't look like .NET exposes this option, you might have to resort to P/Invoke. See http://stackoverflow.com/a/21718198/886887 for a C++ version. – Harry Johnston Dec 23 '16 at 23:35
  • Thanks for pointing me in the right direction Harry Johnson. I managed to get it working via Win32.LogonUser() and updating the calling users "Replace a process level token" privilege. This solution will suffice for now. – P_Fitz Jan 03 '17 at 14:34

1 Answers1

0

Have you tried to add application manifest with:

<requestedExecutionLevel level="requireAdministrator" />  

It seems to create a process as an administrator you need to be an administrator.

I'm sorry that I wrote here. I don't have enough reputation for comments.

WhiteSnake
  • 11
  • 1