How to send the admin password to windows cmd

Asked

Viewed 233 times

-1

I have the code below in . Net written in Visual Studio 2019, which activates windows. The problem is that when running windows propmpt command running with an AD admin account it asks for the password, and this I am not able to send by program/code. Someone could help in this situation?

System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = “cmd.exe”;
proc.StartInfo.Arguments = “runas /user:dominio\usuario slmgr.vbs -ipk aqui serial”;

proc.StartInfo.UseShellExecute = true;
proc.Start();
  • only the "runas" would already run as admin... the user who will run this application does not have the privilege?

  • the user is Adm. but no need to enter password?

  • here gave of good... but what you can do is also instead of the arguments inform in StartInfo

  • What property of startinfo? could you give an example?

  • In mine here not enabled no. When I tested by the windows prompt straight asked password, so I think in the code is asking too. Couldn’t see that coming.

1 answer

2

If the user who is running the application has the privilege of admin just declare the verb "runas"... but you can pass the authentication credentials with the domain on ProcessStartInfo also.

And to run the process with the credentials it is necessary to configure the UseShellExecute as false

    var senhaSegura = new System.Security.SecureString();
    var senha = "senhaDoUsuario";

    foreach (char c in senha)
        senhaSegura.AppendChar(c);



    var process = new System.Diagnostics.Process();
    process.StartInfo = new ProcessStartInfo
    {
        FileName = "cmd.exe",
        UserName = "usuario",
        Domain = "dominio",
        Password = senhaSegura,
        Verb = "runas",
        Arguments = "slmgr.vbs - ipk aqui serial",
        UseShellExecute = false
    };
    process.Start();
  • That’s right. but if my password is encrypted in a text file for example in C: temp tempPassword.txt and the key in C: temp tempKey.txt has to pick it up and enter in the above code in Password?

  • @user2509556 var senha = System.IO.File.ReadAllText("C:\temp\tempKey.txt");

  • Going back to the previous question. I would like to encrypt the password in a text file and decrypt it by entering password.

  • Another question: if I have my password which puts in Password which is a Securestring is my encrypted password?

  • no, but it’s also another question :P

  • @user2509556 the answer solved your problem?

  • after making the suggested changes I received the following error in the console:Directory name is invalid!

  • @user2509556 which directory?

  • I found that there is a difference when running on the machine with another user in the administrator case and then followed what was said in https://answall.com/questions/239928/process-start-n%C3%A3o-load-as-Depend%C3%Aancias-do-execut%C3%A1vel Informing Workingdirectory of this I received another message where the error looks like the previous one. The message is as follows: Application startup failed due to configuration.

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.